Tuesday, February 23, 2010

Working with VHD and differencing disk in VirtualBox

I recently switch to VirtualBox (from VirtualPC), but i was not ready to dump all my VHD files. So i decided to keep working with VHD. The other thing I use a lot is “differencing disk”, VirtualBox also support these, but, as with VHD the documentation is not always very clear on how to use them.

First you have to understand a difference between Virtual PC and Virtual Box about “differencing disk” :

In VirtualPC In VirtualBox
You create a normal VHD that will become the parent, then you create a child VHD pointing to the parent You create a normal VHD and flag it as “immutable”, then you create new VMs using this “immutable” VHD. VirtualBox will automatically create the child VHD that will appear like a snapshot ({GUID}.VHD)

Here’s how I do it :

Step 1 : Create a 20Go dynamic disk VHD

vboxmanage createhd --filename "F:\.VirtualBox\HardDisks\WinXP_Parent.vhd" --size 20480 --format VHD --variant standard --remember

Step 2 : Change the new VHD into an immutable disk

vboxmanage "F:\.VirtualBox\HardDisks\WinXP_Parent.vhd" --type immutable

I Also like to force it to read-only as an additionnal precaution :

attrib +R "F:\.VirtualBox\HardDisks\WinXP_Parent.vhd"

Step 3 : Create a new VM using the WinXP_parent.vhd

VboxNewVHD

Yon now have a new virtual machine with a differencing disk in the VHD format.