Ian Hoar – Passion for Technology – Geeking Out - Technology, Web, Toys, Games, Design, Entertainment, Gadgets, & Geeking Out

How to clone / duplicate a VirtualBox VM on Mac OS X

VirtualBoxThe sad truth is that it’s becoming more and more important to cross test your markup on multiple browsers including Internet Explorer. Yes I’ve heard the announcement about IE6 being dead, but chances are you probably need multiple browsers, and graceful degradation / progressive enhancement should still be the ultimate goal for any web designer.

VirtualBox to the rescue

VirtualBox is a fantastic virtualization tool for Mac OS X, Windows, Linux and Solaris. I actually like it more than Parallels, and unlike Parallels, it’s free.  Setting up a virtual machine is pretty easy, but it’s a bit time consuming. Once you have a VM set up there doesn’t appear to be any quick way to duplicate the already working image. This tutorial will guide you through the steps needed to duplicate a VirtualBox image on Mac OS X.

This tutorial assumes you have VirtualBox installed and a working VM already. If you are setting up a VM to test in Internet Explorer, then I recommend setting up the first image with IE6 and then duplicating and upgrading to IE7 and then duplicating again and upgrading to IE8 and no doubt soon to be, IE9.

Lets get started

First open your Finder and navigate to:

YourUserName/Library/VirtualBox/HardDisks/

Here you should see at least one or more vdi files. Take note of the one you want to copy. This tutorial will assume we are cloning Windows_XPIE7.vdi to Windows_XPIE8.vdi, remember these names will be replaced with your own vdi file name. Now you need to open the OS X Terminal. If you don’t know where this is, it’s called Terminal in your Applications/Utilities directory. Now change directories to VirtualBox. I usually type cd and then drag the file path from my Finder into the Terminal window, alternatively you can type it out:

cd /Users/YourUserName/Library/VirtualBox/HardDisks

VirtualBox comes with a command-line utility called VBoxManage. In the terminal windows type:

VBoxManage clonehd Windows_XPIE7.vdi Windows_XPIE8.vdi

This will take a minute or so. Once it is done you will have a clone of your vdi file and you will see a UUID: with a long string of string of letters and numbers. Copy this string, I recommend pasting it into a text editor for the moment or leaving the Terminal window open.

Now navigate back to the Finder:

YourUserName/Library/VirtualBox/Machines/

Right click the Windows_XPIE7 directory and select Duplicate. Rename it to Windows_XPIE8. For consistency, inside this directory rename Windows_XPIE7.xml to Windows_XPIE8.xml. With a text editor open the renamed file.

In this file search for uuid. The first instance should be under Machine. Something like this:

<Machine uuid="{91ddb597-afe8-476a-b077-ef4575dca102}" name="Windows XPIE7" OSType="WindowsXP" lastStateChange="2010-05-04T02:15:21Z">

Paste the uuid that you saved from your clone here. (This does not need to be the exact same uuid, but it makes things easier.) Change the name to Windows XPIE8. This is the name that will show up in VirtualBox.

<Machine uuid="{81ddb597-afe8-476a-b077-ef4575dca102}" name="Windows XPIE8" OSType="WindowsXP" lastStateChange="2010-05-04T02:15:21Z">

Now scroll down and look for a second uuid in the AttachedDevice element node, you will likely find more than one, but the one you are interested in has a type of “HardDisk“.

<AttachedDevice type="HardDisk" port="0" device="0">
    <Image uuid="{5af3e1b9-e7c9-4a57-9251-a47d4adaca7c}"/>
</AttachedDevice>

Here you want to paste the uuid you saved earlier over the old one. Save and close the file.

In the Finder navigate to:

YourUserName/Library/VirtualBox/

Open VirtualBox.xml in your text editor. Under the element MachineRegistry you will see MachineEntry elements. Copy one of these and update the uuid with the one you saved earlier.

<MachineRegistry>
    <MachineEntry uuid="{31ddb597-afe8-476a-b077-ef4575dca102}" src="Machines/Windows XP/Windows XP.xml"/>
    <MachineEntry uuid="{91ddb597-afe8-476a-b077-ef4575dca102}" src="Machines/Windows XPIE7/Windows XPIE7.xml"/>
    <MachineEntry uuid="{0158e13d-ef69-44cf-bb11-01755763f1ff}" src="Machines/Windows XPIE8/Windows XPIE8.xml"/>
</MachineRegistry>

Now you need to change the HardDisks element. Add a new Hardisk element and change the uuid to the uuid you saved in your text editor.

<HardDisks>
    <HardDisk uuid="{be0d8b4a-ee99-410b-9d9e-a65d581479cf}" location="HardDisks/Windows XP.vdi" format="VDI" type="Normal"/>
    <HardDisk uuid="{5af3e1b9-e7c9-4a57-9251-a47d4adaca7c}" location="HardDisks/Windows XPIE7.vdi" format="VDI" type="Normal"/>
    <HardDisk uuid="{0158e13d-ef69-44cf-bb11-01755763f1ff}" location="HardDisks/Windows XPIE8.vdi" format="VDI" type="Normal"/>
</HardDisks>

It seems like a lot of steps, but it’s actually a lot faster than re-installing the OS. Now you should be able to fire up VirtualBox and see your new VM listed. Now all you have to do is update your browser.

VirtualBox screen

This Tutorial was inspired by Josh Prowse’s YouTube tutorial. Mine is slightly updated for a new VirtualBox directory structure and I use the same uuid throughout.

Related posts:

  1. Adobe Bridge underappreciated?

12 Comments to “How to clone / duplicate a VirtualBox VM on Mac OS X”

Responses:

  1. Ngoprek pake VirtualBox | life to share
Your comments are important, join the conversation