Home > OS X, Tech > VirtualBox Differencing Disks in OS X

VirtualBox Differencing Disks in OS X

Create an immutable VirtualBox disk with changes to that disk written to a differencing disk in OS X.  This is useful in the context of TimeMachine backups.

After my recent switch to OS X, I fell in love with TimeMachine and the transparent backups it provides.  I even have it backing up to my Windows 7 file server wirelessly so I literally do nothing when I am at home to get seamless unattended backups (not even plugging in an external HDD).

The one issue I have found in this setup is that my VirtualBox disks (Ubuntu Linux and Windows 7) get copied completely after each backup.  This is less than ideal.  3.5GB per backup adds up very quickly!  Here I describe how I created a ‘base’ (immutable) virtual box disk and let VirtualBox create an additional differencing disk on top of the base disk.  After this, TimeMachine is only copying very small chunks of data rather than the whole 3.5GB disk!

I found quite a few posts online related to this topic, including this forum post, this forum post/tutorial about VirtualBox VDIs, this forum post, and this StackOverflow topic.  Each of these contain good information.  However, this forum post was pretty much exactly what I was looking for.

To summarize the process, we first must create the base VDI disk and mark it as immutable.  This forces VirtualBox to create a second differencing image of changes beyond the immutable base disk image.  The second step is to change the mode of the differencing disk, toggling autoreset from ON to OFF.  By default the differencing disk only applies for one run of the VM.  In otherwords, any changes across restarts will be lost.  Turning autoreset off fixes this.

Here are the steps I’ve extracted from that discussion, including commands that need to be run:

  1. Create an immutable .VDI disk.
    1. Detach the base VDI from the virtual machine in the VM settings.
    2. Make the VDI immutable by running the following command:
    3. VBoxManage openmedium disk -type immutable DISK_FILE_NAME.vdi
    4. Reattach the now immutable VDI to the VM.
  2. Tell VirtualBox to use a differencing disk explicitly. Click the check-box that says ‘Differencing Disk’ in the VBox settings for the VDI that is immutable.  Note the GUID of the differencing disk that gets created.
  3. Disable autoreset for the differencing disk:
    1. By default VBox will reset the state of the machine between restarts.
    2. Disable this behavior by toggling the autoreset setting:
    3. VBoxManage modifyhd --autoreset off DIFFERENCING_DISK_GUID

After running through these steps you should be able to start your VM, make some changes, and restart.  The changes on disk that you made should be persistent.  It would be nice if VBox would make this particular use case all GUI-based, but at least it’s possible.  Regardless, now TimeMachine only copies the differencing disk which is significantly smaller than the base disk image.  Please let me know if this works for you in the comments!

Update (2010-5-10 21:47): If you make significant changes beyond the base disk image, it is possible for the differencing disk to grow beyond the size of the base image itself.  In this case, it may be worth it to collapse or merge the changes into the base disk image and start the differencing disk fresh.  To do this, you make a clone of the differencing disk image, use the clone as the new base, and use the process above to start fresh with a new differencing disk.  I used this forum post as a basis for this process.  The clone command is:

VBoxManage clonehd DIFFERENCING_DISK_GUID NewBaseDisk.vdi
  1. August 7th, 2010 at 11:38 | #1

    Can’t you do the exact same thing with snapshots? Or does VB continue to write to the same disk file?

    • August 9th, 2010 at 08:50 | #2

      From what I understand, VB will write to the virtual disk you have assigned to the VM unless you make it immutable. I need to read more about snapshots in VB, but this was the first solution I found that was TimeMachine friendly. : )

  1. No trackbacks yet.