Mounted Disk Image is significantly smaller than .dmg

Joined
Apr 27, 2008
Messages
92
Reaction score
5
Points
8
Your Mac's Specs
MBP 2.5 Intel Core 2 Duo, 2GB 667 MHz DDR2, 17" Hi-Res Display ; iPhone 3G 2.1
I am working on an applescript which includes creating a disk image and copying a folder to it. My script calculates the size the disk image needs to be to fit all the files on it, and then sends a shell command to create and mount the disk image. The problem is that the once the disk image is mounted the capacity is significantly less than the corresponding .dmg file.

(example: mydiskimage.dmg = 10.04 GB, but when mounted it only has a capacity of 9.72 GB, where is the missing 328 MB?)

So my question is where is the missing disk space, and is there a way to calculate how much that is going to be so I can include it when I'm creating the .dmg file?

Here is the applescript command I'm using to create the disk image:

do shell script "hdiutil create -size 10278.1640625m -fs HFS+ -volname \"Converted Clips\" converted_clips.dmg"
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
You can pass the -srcfolder option, which will create an image that contains the folder and calculates the required size for you. This will help you to avoid having to calculate a size. So, for instance, the following should create an image for you with you not having to worry about passing a size:
Code:
hdiutil create -srcfolder <folder> -volname "Converted Clips" converted_clips.dmg
(Replace <folder> with the name of the folder). You also don't need to pass the -fs parameter as it is redundant (the image will take the fs of the folder).

From the hdituil man page for the -srcfolder parameter: "Derive the image size from the the filesystem entity source and copy the contents of source to the resulting image. The filesystem type of the image volume will match that of the source as closely as possible unless overridden with -fs. Other size specifiers, such as -size, will override the default (size of the source directory plus some padding for filesystem overhead), allowing for more or less free space in the resulting filesystem. -srcfolder copies file by file, creating a fresh (theoretically defragmented) filesystem on the destination image." (important parts bolded).
 
OP
J
Joined
Apr 27, 2008
Messages
92
Reaction score
5
Points
8
Your Mac's Specs
MBP 2.5 Intel Core 2 Duo, 2GB 667 MHz DDR2, 17" Hi-Res Display ; iPhone 3G 2.1
Thanks for the reply, however, when working with large files it can take a long time to create the image and copy the files, and there is no status displayed.

With the previous method, i can create a log file to periodically check the size of the image while its being created, then mount the image, and copy the files, again periodically logging the available space left on the image. (all while displaying the log on my desktop with geektool)

With the method you provided, i can still log the creation of the image, but not the copying of the files, because I don't think there is a way to get the available space of an image without mounting it.

-- update --

I do think i have it working just by adding about 5% to the size of the image, however it is kind of a waste of disk space.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top