Cloning VirtualBox

After reading that cloning VirtualBox VMs is difficult I thought I had better work out how to do it. Because if I’m going to use VM technology I need to be able to move them around the home network and back them up. The basic concepts are:

We can copy a VDI as it is basically just a Windows file on the host machine. VDIs are VirtualBox Disk Images are image files that can hold a Virtual Machine.

VirtualBox has a bunch of settings that explain how to launch the VM within a VDI. We need to recreate these and point it at the VDI to get a working VirtualBox.

But…. You can’t start two machines with the same UUID. So there is a command to fix that.

My method:

c:
cd "c:\program files\sun\xVM VirtualBox"
copy "\VDI\Windows XP Server.vdi" "\VDI\Clone.vdi"
VBoxManage internalcommands setvdiuuid \VDI\Clone.vdi

So I basically copy the VDI (with the VirtualMachine turned off) and give it a new UUID. This works except I still have to fire-up the VirtualBox gui, create a new VM with the same settings as the master VM but rather than create a new VDI, I choose the new clone.vdi.

What I want to do next is be able to pause the master VM, script the Copy, UUID, creation of the new VM. Luckily VirtualBox has the same command set available on Windows that the less gui-friendly OSes use. Hooray.

I also need to script automatically starting and stopping VMs. In effect I can run an XP host which on startup can launch a bunch of VMs. Ideally it should all be able to gracefully shutdown.

I know ESX does this better but I have some non-ESX firendly hardware in my stack and I would like to just build them as XP hosts and get all the benefits that virtualisation gives but on the cheap. So far it is looking good.

I am also currently just running on a local disk. Running with a VDI over the LAN seems like inviting trouble but creating cloned backups on a remote disk does seem like a really easy way to do a fool-proof backup.

I also need to get my head around allowing VMs access to the real LAN as I will want to run web servers for example on these VMs and default network settings disallow this due to the funky NAT that is in use. I guess I’m going to have to work through the command line Port forwarding…