user870130
user870130

Reputation: 575

Creating DMG without extra space

I currently use hdiutil to create my DMGs.

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

Is there a better method that either shrinks the DMG to size or creates it size?

Upvotes: 8

Views: 5160

Answers (2)

user149341
user149341

Reputation:

Yes:

hdiutil create myImage.dmg -srcfolder SourceDir

This will automatically size the image to fit.

Upvotes: 6

CNeo
CNeo

Reputation: 746

You can create a larger dmg, add the files, then resize it:

hdiutil resize -size xxxg myImage.dmg

or create a sparseimage, and then convert it

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

I've never tried the latter, not sure if it'll pick the right size for the dmg.

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

Note that sparseimages need to be compacted if files are deleted from them, as they don't release the space from deleted files automatically:

hdiutil compact Source.sparceimage

Upvotes: 4

Related Questions