Monday, December 17, 2012

Virtualbox: Multi-attach disk

Just a short intro to VirtualBox multi-attach disks, for reference in other posts.

Virtualbox is my favorite free desktop virtualization product, and one of my favorite things about it, is the possibillity to use "master" disks, where one disk file becomes the system disk for several virtual machines. This is similar to template VMs and linked clones in VMware Workstation, except that you're not cloning a VM, you're just using a master disk. In my humble opinion, the Virtualbox solution is superior to VMware's, and at least, you will find it much easier to use.

Using master disks, I can create and log in to a new virtual machine in less than a minute, literally. I don't have to reinstall the OS for every new VM, I just give it a ready installed OS from a master disk.

What happens when you assign a master disk to a VM, is that the VM creates a differencing disk, where all writes go. The master disk will be used for reading, for whatever is not overwritten on the differencing disk. Over time, the differencing disk, that is local to every VM, will grow, and a large number of the original files will be overwritten by updates. This is not essential, the concept is not about saving disk space.

One note about differencing disks. Do not expect to be able to extract any data from a differencing disk without having access to the master disk. If your master disk is gone, your differencing disk is worthless, due to the fact that it writes modified blocks, not files. Adjust your backup routines accordingly.

Creating the master disk

I will not go into details about how to prepare an OS for a master disk, this is a common thing to every systems administrator, although most often for the purpose of using disk imaging tools for deployment of new servers or desktop computers. However, I do encourage you to use sysprep for your Windows master disks.

After installing your OS and preparing it for a master disk, you shut down your VM. Open the Virtual Media Manager from the VirtualBox File menu, and locate your disk. If it is still attached to your VM, release it by clicking the Release icon. Then click the Modify icon and select "Multi-attach".

That's it, your disk is now a read only master disk, and every time you attach it to a VM, that VM will create a differencing disk for write access.

When you create a new VM, it is very easy to use the master disk, just choose to "Use an existing virtual hard drive file", and select your disk. Notice the blue icon next to the disk name, that tells you this is a multi-attach disk.

Warning! If you create a new master disk, release it and modify it as described, you should remember to either create a new VM with that disk, or just reattach it to the VM you used to create it, before you close VirtualBox. The reason for this is that if you don't, it will go missing...