Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

Is there a possibility to "defragmentize" a sparse bundle image and reclaim (most) of the free space?

Here is the background: I am using sparse bundles and every now and then I want to reclaim space from them so I run:

hdiutil compact image.sparsebundle

However, as explained in the man page, it only reclaims completely unused band files, so in my case it says:

Reclaimed 0 bytes out of 90.4 GB possible.

Of course there is the possibility to copy the contents of this image to a new sparse bundle that is then used in lieu, but that is both cumbersome and requires enough free space for this operation.

Meanwhile, I found out that the output of the compact command is somewhat misleading (I am currently running OS X 10.5.7) as it sometimes lists a size as possible that is larger than the size currently taken up by the image bundle on the hard drive. I did not look closer but the output seems to be either the maximum size or "maximum size" - "used size".

share|improve this question
up vote 18 down vote accepted


From what I've heard, the sparse bundle divides the data into 8Mb bands. Changing the band size might just help, if you're lucky. I mean, you'll never get 100% reclaimed space, but maybe better than what you get now. (Depending on the data on the image etc.)

I did a dirty simple test with two 500Mb sparse bundles, one with 8Mb (default) band size, and one with 1Mb (smallest allowed size from what I can tell). I copied over 400mb of mp3 files and then removed every other file and then run hdiutil compact on their asses.

Size after compact
8Mb bands: 271Mb
1Mb bands: 215Mb

The command to convert your sparse bundle is

hdiutil convert src.sparsebundle -format UDSB -tgtimagekey sparse-band-size=2048 -o dst.sparsebundle

Band size is in the unit 512byte. So the above example sets the band size to 512 * 2048 = 1Mb. Just be careful if you're dealing with TimeMachine images or user home folder images etc. You're deviating from the Apple path :) Keep a fail safe backup!

As for defragmentation: I have a funny feeling it's just as fast (or faster!) to just use hdiutil to convert the sparsefile to a new sparse file with the same format. I think it tries to be smart about it. But I don't know.

(Note that defragmenting a sparse bundle just defragments the disk data, not the sparse bundle bands, unless it's a sparse bundle aware defragmentor. hdiutil convert does a band 'defragmentation' I believe.)

share|improve this answer
Your command line arguments are in the wrong order: -o should be directly before dst.sparsebundle, not src.sparsebundle (-o denotes 'output'). – Nick Forge Nov 1 '10 at 12:05
Also, note that this method doesn't preserve encryption. There's probably a flag to enable it, but at this point I found it easier just to make myself a new sparsebundle in Disk Utility and copy my files into it. – Justin Searls Dec 24 '10 at 19:28
For encryption, just add the -encryption switch to the command. – fideli Sep 20 '11 at 3:37
Thanks a lot. Decreasing sparse-band-size is very useful for Dropbox hosted sparse-bundles – Max Ried Sep 17 '12 at 8:04
Ok this doesn't make sense... when I convert to defragment the image, the resulting sparse bundle is 16% bigger than the original. – Michael Jun 6 at 4:15

I think the 90.4 GB possible are plain wrong. When I ran

hdiutil compact *.sparsbundle

it freed up 16 GB of space which is roughly what I actually expected. Funny enough it said roughly "800 GB possible" which is way more than the capacity of my HD. So I assume the second figure is just some (flawed) theoretical number.

share|improve this answer

I don't know of a free way to do it, but I believe Prosoft Drive Genius will do what you're needing here:

You mount the sparsebundle, defrag it using Drive Genius, and then the

hdiutil compact

command should work.

share|improve this answer

Reclaimed 0 bytes out of 90.4 GB possible.

I bet the drive that holds the sparse bundle has about 90 GB free space? As sparse bundles often can grow until the disk is full, this space is simply reported as being available free space... You will see the same figures in Disk Utility. Very misleading indeed.

The following might give you some insight:

hdiutil imageinfo image.sparsebundle
share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.