Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let's say that I have three files with the following sizes:

FileA: 15468bytes

FileB: 3874235bytes

FileC: 10452326bytes

and I want to create a UDIF, GPTSPUD, HFS+ DMG with hdiutil which will exactly the size needed to hold these files. I can, of course, tell hdiutil to create a dmg of the size 14342029 bytes, but the dmg will have < 14342029 bytes in free space available due to the number of bytes needed to support the file system.

Is there a known way to calculate how large to make the DMG so it will hold the files?

p.s. In the 'real' case, there are thousands of files of various sizes.

p.s.s. I am aware of various issues that files actual use X number of blocks on a disk and that a block is a fixed size.

share|improve this question
Why do you want to create a disk image with the exact size for the files? Is creating a sparse image (which will be only take up the space required for its contents, rather than its entire capacity, including free space) somehow unsuitable? – Scott Aug 29 '11 at 13:01
Because I am curious about how to determine the exact size (or reasonably close). It is simply a question that I am seeking the answer to. – ericgorr Aug 29 '11 at 13:40
Well this is a hard one - you need to take into account the metadata for the .dmg itself. Why not simply use hdiutil create with the -srcfolder option, which will make a formfitting DMG? – w00t Sep 2 '11 at 17:34
Again, there are many solutions to the general problem is creating a DMG to hold a set of files. I am simple seeking a specific answer to this one. – ericgorr Sep 2 '11 at 18:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.