Inspired by this tutorial, I decided to try a similar thing, to speed up the TimeMachine backups of my VirtualBox virtual machines.

The results are quite nice, rather than backing up 20GB every time I boot the VM, it does only about 500MB. While this not spectacular – changing almost no data in the VM generates some traffic, at least is fast enough to let TM backup it up.

Same way as the tutorial, you create a sparse bundle image, mount it and you move inside it all your VM data. You can either tell VirtualBox that the new machines are located in a new location (the place where your image mounts), or create a symbolic link between your previous VM location and the mounted disk location. Notice that I said symbolic links and not an Alias from Finder. The VBox is not able to navigate through Aliases. To create a symbolic link you fire up a Terminal and type:

cd ~/Library
ln -s /Volumes/VirtualBox/VirtualMachines .

In the previous example my virtual machines were located under ~/Library/VirtualMachines and the name VirtualBox.

There are however a few annoying things about this whole setup. The disk has to be mounted before you start VirtualBox and it does not get unmounted automatically. I am sure that there is magical scripting solution for this, but I am yet to find it.

The advantage of Sparse bundle images over the regular dmg images is that they can expand dynamically up to the maximum size allocated (they can resized however if you decide you want more space). They are also allocated in 8MB stripes, thus allowing you to perform incremental backups.

Unfortunately they do not shrink automatically after you deleted some data. This can be achieved with the following terminal command:

hdiutil compact Your_sparse_image.sparsebundle

A similar bloating phenomenon happens with your VBox disk files if you made the expand.

The first step is to zero out the free space. If your VM is Windows boot it, download sdelete and run it from a command prompt:

sdelete.exe -c

After that is done shutdown the VM and run:

BoxManage modifyvdi your_VM_disk_file.vdi compact

It is rather annoying having to deal with 2 layers of self adjusting container images.