I have recently starting using VirtualBox as my medium of virtualisation on my laptop and it works pretty well – I’ve even got Mac OSX working. But one thing I struggled with at first is the cloning of the VirtualBox Disk Images – the hard disk files that the Virtual Machines use. Once I had found out how to do this without encountering any errors I figured I would make a note of it so that I always have a referral point – and now so do you.
Copy/Paste Anyone?
No. That won’t work. Trust me I’ve tried…What you will end up with is two .vdi files with conflicting UUID’s. This means that you won’t be able to run them side by side, or indeed have them on the same physical machine.
Using the Command Line tool VBoxManage
You’re getting warmer now. This is the tool to use to clone your existing .vdi files. But you can’t simply bash out your script and expect it to work straight away. There’s a little bit of prep to do. So take note of the following steps and, if you follow them, you’ll have as many copies of your .vdi files as you want.
Assumptions:
- VirtualBox is installed
- You already have a base VM set up, complete with Virtual Hard Disk (vdi) – i.e. you have installed an OS
- Open VirtualBox
- Click on the Virtual Machine you want to clone
- Now click File>Virtual Media Manager
- When the Virtual Machine Manager appears, click on the .vdi file that you want to clone and then click Release – this will release the .vdi from the VM. THIS IS IMPORTANT. If you miss this step you will encounter UUID conflicts.
- Fire up command prompt (Start>Run>cmd [enter])
- Enter the following command:
< File path of VBoxManage> clonehd “<file path of the source .vdi file>” “<file path of the target (cloned) .vdi file>”
For me this command was:
“C:Program FilesOracleVirtualBoxVBoxManage” clonehd “D:Virtual MachinesVirtualBox VMsWindows7Windows7.vdi” “D:Virtual MachinesVirtualBox VMsWindows7SQLServer2005Windows7SQLServer2005.vdi”
If you see the following, your .vdi base file is being copied correctly. Check your target directory for the cloned .vdi file.
Once the clone is complete you should see the following:
The key thing to note in this screen is that a New UUID has been assigned to the cloned .vdi file. Remember, if you hadn’t released the base .vdi file from its VM, then you’ll get an error when executing the clonehd command – See step 5.
- Go Back to Virtual Box
- Click the New icon, to create a new VM
- Enter a Name for your new VM and select the Operating System that you’ll be using.
- Adjust the amount of memory that you need for the VM
- Now, on the Virtual Hard Disk screen select Use Existing Hard Disk.
- Click on the folder icon and navigate to the .vdi file that you have just cloned and then click Next.
- Review the summary, then click the Finish button and you’re done. The new VM should now be available in your list of VMs
That’s it!
