Sunday, March 20, 2011

VirtualBox - Cloning a VM

NOTE - This was done using VirtualBox 4.0.4 r70112 with a Windows 7 host.

It needs to be fleshed out but this is just to capture the initial process.

I've been using VirtualBox to host some VMs (mainly Linux).

It's a bit of a pain to create a brand new VM each time and I like to have a relatively clean base image to start from when starting a new project. So, I want to be able to clone an image relatively easily.

Here's the steps I took to get a 'template' VM and working copies of it. It may not be the most efficient but it worked for me and may work for you.

  1. Create an initial template VM as for any guest machine. Install the chosen OS and perform any base/initial configuration you want to be captured in the template itself.
  2. Ensure the guest machine is powered off.
  3. Clone the virtual disk for the VM. You can't simply copy the virtual disk file (not if the guest will be used on the same machine) as VirtualBox will see that both images have the same UUID. So, we need to use the clonehd function to copy the image and replace the UUID.
    C:\Program Files\Oracle\VirtualBox\VBoxManage clonehd
    This clones the virtual disk and gives it a new UUID
  4. Create a new guest from within VirtualBox choosing the appropriate hardware settings.
  5. When choosing disks, select to use an existing disk and select the copied image.
  6. Boot the machine and it should start up with the exact same OS behaviour as the original image that was cloned. Voila!

NOTE - Cloning the image also registers it with VirtualBox. If you subsequently want to move/rename it then use the 'Virtual Media Manager' from the File menu within VirtualBox.

NOTE - I'm not aware of an ability to clone the machine description itself (but I haven't actually tried). This may well be possible rather than creating a new machine and setting the hardware settings manually. The machine configuration appears to be held in XML files so it may be as simple as copying/editing these. Whether that is supported is another matter...

That's all for now. I may clean up and add some screenshots at some point... Based on past experience, don't hold your breath! ;-)

Time flies

Well, it never really took off quite as quickly as I expected/hoped. Life got in the way and blogging very much took a back seat.

Anyway, hopefully there will be a few more posts on here soon. Basically I've decided to use this as a staging post for any tidbits of info that I find as I'm conquering various (sometimes trivial) technical challenges.

So, we'll see how we get on...