Compacting sparse bundles
QI’m using an encrypted ‘sparse bundle’ in APFS for private documents. How do I get it to reduce in size, as that isn’t available in Disk Utility?
ASparse bundles are a type of disk image which stores the contents of a virtual disk in ‘bands’ of fixed size within a bundle folder. These are sparse because, unlike regular disk images, they can grow in size as they need. Whilst they grow larger without any intervention, at least until they approach the max size you set when you create them, if you later remove files and folders from sparse bundles, they don’t automatically shrink down again.
Disk Utility doesn’t currently offer any command to compact sparse bundles. The easiest way is using
C-Command’s DropDMG from the App Store, which is more comprehensive in its support for all types of disk image. Otherwise, you’ll need to open Terminal and use the command:
hdiutil compact myDocuments. sparsebundle
This will compact the sparse bundle named myDocuments.
Storage inside a sparse bundle works like any other disk volume, and sometimes it won’t compact much because its contents are fragmented through the storage bands. You can try defragmenting the sparse bundle when it has been mounted, then compacting it using DropDMG, or copying its contents to a new sparse bundle.