Monday, 22 March 2010

Cloning VMs with Multiple Snapshots in VirtualBox

I'll keep this short and sweet. I needed a way to backup a VirtualBox machine with multiple snapshots to a single detached VDI.

'VBoxManage' is the command line tool with all the useful VirtualBox tools, and I had used its 'clonehd' to good effect before now to clone existing VDI files. However as you may already know, when you snapshot a VirtualBox you end up with multiple VDI files; so how can we consolidate these into one VDI without having to mess around merging existing snapshots on a live service?

Quite simply use the UUID of the state you wish to clone, this will create a new VDI of the associated snapshot, merged with ALL previous states... cool huh? You can get this out of the virtual disk management tool in the gui, or from the XML definition file for the machine, it'll look a bit like:
c6804c54-a8ca-4829-9eaf-132f8b1dd38a

So to make a spanking new single VDI for this saved state, run:
$ VBoxManage clonehd c6804c54-a8ca-4829-9eaf-132f8b1dd38a MyNew.vdi

Simples!