How to clone / duplicate a VirtualBox VM on Mac OS X
The 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.
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.
alex June 1, 2010 at 11:07 am
you saved my ass with this tutorial. thanks
Sprogz August 18, 2010 at 8:19 am
Great tutorial, thanks.
It does make you wonder why on Earth VirtualBox doesn’t have a nifty “Clone VM” menu option in the GUI that does all this for you?
I wonder what the reason is that’s preventing them from implementing this, because it’s clearly not technically difficult for them to do?
Joe Krahn August 30, 2010 at 4:06 pm
My guess is that VirtualBox does not implement a “clone VM” tool because they want to avoid implications of supporting unlicensed duplication of OS software.
bruzed August 30, 2010 at 7:50 am
thanks for the tutorial, you rock!
martin December 7, 2010 at 11:29 am
thanks helps a lot 🙂
but if you dont want so edit the xml files after you generates the copies
it is easier so add in vb a new maschiene and use the vdi file as harddisk 🙂
all thinks will be done auto
David J. December 14, 2010 at 7:46 am
Hi,
Thanks for this tuto. I have been using it sometime. But now I use the native export/import tools from VBoxManage command line.
Can you advise me if this technique is also a good one?
Thanks in advance
Ian Hoar December 14, 2010 at 11:18 am
Hi David,
I have only used the technique above.
yosh May 31, 2011 at 4:02 am
Thanks a lot!!!
I REALY didn’t want to install windows again, just for a browser version…
Kristian Hansen June 6, 2011 at 1:42 pm
Thanks so much for the tutorial!
Gus September 6, 2011 at 1:21 pm
Nice tutorial, but on latest version you have “Clone…” option on VirtualBox menu… pretty easy, isn’t it? 🙂
Ian Hoar September 6, 2011 at 1:24 pm
Hi Gus, this tutorial was written before Virtual box had a clone feature.
Philip March 25, 2013 at 4:05 pm
Hi,
just great DIY for someone like me who just can follow this and who has no skills in programming or anything. Tried several hints for days but this was the one that worked. THANKS!
Just for the record:
Some folders are different now in 2013 and I release and remove the disk which I found in an other blog “clone-virtual-machine-sun-virtualbox-simple-steps”
Great that you took the time and energy to help with this!