2

I want to resize (shrink) the capacity of the backup.sparsebundle to approx. the size actually taken up the files.

What I did thus far

I already compacted the image:

 # hdiutil compact backup.sparsebundle
 Starting to compact…
 Reclaiming free space…
.............................................................................
Finishing compaction…
Reclaimed 0 bytes out of 265.2 GB possible.

The stats

My system:

# system_profiler SPSoftwareDataType

  System Version: OS X 10.11.5 (15F34)
  Kernel Version: Darwin 15.5.0
  Boot Mode: Normal
  Secure Virtual Memory: Enabled
  System Integrity Protection: Enabled

Disk image size:

# du -sh backup.sparsebundle
213G    backup.sparsebundle

Volume size:

# diskutil info /Volumes/backup | grep -E 'Free Space|Total Size'
   Total Size:               501.8 GB (501806010368 Bytes) (exactly 980089864 512-Byte-Units)
   Volume Free Space:        284.8 GB (284753629184 Bytes) (exactly 556159432 512-Byte-Units)

The problem

The problem is that hdiutil doesn't allow to shrink the image, because the target size is below the content-min-length allowed:

# hdiutil resize -size 224GB MBA11-backup.sparsebundle
hdiutil: resize request 469762048 is below minimum size 800587800 allowed.
hdiutil: resize: failed. Invalid argument (22)

Here are the limits:

# hdiutil resize -limits MBA11-backup.sparsebundle
min         cur         max
800587800   980089864   34359738368 

The values are in 512 sized sectors, so the minimal size is (800587800 * 512) = 409900953600 bytes or 409.90 GB.

What I want to achieve

I would like to get rid of the free space and shrink the image Total Size of 501.8 GB to approx. the space actually in use of 217 GB (Total Size minus Free Space).

  • Why is the minimal size allowed so much greater than the actual space in use?
  • How can I reduce the minimal size set in order to shrink the image to the approx. actual space in use?
  • @klanomath It's 213GB, the disk size image (see Stats section). That's what you mean by on-disk size, right? – DBK Jun 14 '16 at 22:15
  • That's what I needed. Somehow I missed it, sorry – klanomath Jun 15 '16 at 4:17
  • Did you figure this out? I'm trying to do the same thing. – shawkinaw Jan 22 at 18:25
  • @shawkinaw It was a long time ago... But I could not figure it out, I think. Post an answer if you find a solution! – DBK Jan 22 at 18:48
1

there seem to be a lot of questions around disk images, esp. sparse bundles and none of the answers I found here provide easy solutions. You seem to have a few problems, I can help you with the first one (I ran into the same problem myself):

Reclaimed 0 bytes out of 265.2 GB possible

  1. Mount the image
  2. Note the path to the mounted Volume, i.e. /Volumes/VolumeName
  3. in Terminal type:

    diskutil secureErase freespace 0 /Volumes/VolumeName

For this step to succeed, there must be enough space left on the main Volume where the sparse image lives (I found roughly the space reclaimable plus a few GB to be a reliable rule of thumb.)

Then you can unmount the image and compaction should succeed.

freespace 0 fills the empty space with zeroes, all other options of diskutil secureErase freespace write random garbage to disk so other files are not recoverable.

The rest of the commands should work fine now, at least for me they did...

I realise this question is old and you most likely have moved on, but maybe it's a help to someone...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .