Saturday, January 23, 2010

Using differencing disks with VirtualBox

When evaluating new software, you often need to setup an isolated environment using virtual machines. This can be a lot of work when you have to install the machines from scratch. To avoid this you can setup a base configuration (for instance a machine which already has SQL server and Visual Studio installed) and copy the hard disk when creating a new instance. The downside of this method is that you waste a lot of disk space. To avoid this most virtualization products such as VmWare, VirtualBox and Virtual PC use differencing disks. These are disks that store only the different sectors in regard to their base or parent disk.

Following procedure shows how to use differencing disks with VirtualBox:

  1. Build the base system.
    After installing the operating system, apply all necessary update and install the VirtualBox additions.
  2. Release the base disk
    Since the base disk will become ‘read-only’, it must be detached form all virtual machines.

    ReleaseDisc
  3. Make the base disk immutable
    Use the following command:
    VBoxManage modifyhd <disk file>  --type immutable


  4. Create a new system from the base disk
    When creating the new system attach the immutable base disk. A new differencing disk will be created.

    NewSystem

    NewDisc

  5. Turn off the autoreset feature of the differencing disk
    This is necessary since the content of a differencing disk will be destroyed when the virtual machine is started.
    Use the following command:
    VBoxManage modifyhd <differencing disk file> --autoreset false



If you want to start a new hierarchy from a differencing disk, you can use the ‘VBoxManage clonehd’ command to build the new base disk. Following figure shows an example:

 

diskgen