Create DMG without extra space

I am currently using hdiutil to create my DMG.

The command I'm using is hdiutil create -size xxxg myImage.dmg -fs HFS+. . I always leave fidgeting around with size until I get it close enough.

Is there a better method that compresses the DMG to size or creates its size?

+7
source share
2 answers

Yes:

 hdiutil create myImage.dmg -srcfolder SourceDir 

This will automatically resize the image.

+4
source

You can create a large dmg, add files, and then resize it:

 hdiutil resize -size xxxg myImage.dmg 

or create sparseimage and then convert it

 hdiutil convert -format UDZO Source.sparseimage -o myImage.dmg 

I have never tried the latter, not sure if he will choose the right size for dmg.

Source: http://nickcharlton.net/post/converting-a-sparseimage-to-a-dmg

Note that sparseimages must be compressed if files are deleted from them, as they do not automatically free up space from deleted files:

 hdiutil compact Source.sparceimage 
+2
source

All Articles