Fast, Efficient Message Archiving for BizTalk with the BizTalk Message Archiving Pipeline Component. Download a Free 14-Day Trial!

How-To: Clone or Copy a VirtualBox Virtual Disk

As a virtual machine environment user, I regularly create ‘base’ images of machines that I can reuse – a base Windows Server 2003 environment, or SQL Server 2005 environment for example. That way, when I need a new machine, I can simply create a copy of the virtual disk and add any additional software I need, saving myself valuable time creating new virtual environments.

With VMWare’s various offerings, copying a virtual disk is easy: copy the disk in Windows Explorer and add it to a newly created VM; VMWare will detect that the disk was a copy and create a new unique identifier (UUID) for the disk before adding it to the VM. Easy and painless. Not so with VirtualBox.

With VirtualBox, copying a virtual disk is a bit of a pain. If you copy the disk in Windows Explorer and try and use it in a new VM, VirtualBox will have a hissy fit and display the error shown below. A bit of a ‘wordy’ way to say that it already knows about this disk, don’t you think?

VirtualBox - Add Copied Virtual Disk - Duplicate UUID Error

The publicised way around this is to use the command-line VBoxManage CloneHd tool, however there is another – secret and undocumented – way to clone a disk: the setvdiuuid tool. Lets look at these two methods in detail.

Cloning a Virtual Disk – The ‘Supported’ Method

Cloning a disk is (IMHO) a clunky and Unix-y type way of creating a duplicate disk. We need to invoke the CloneHd command of the VBoxManage tool, supplying the disk to clone and the name of the new ‘cloned’ disk. In its simplest form, you would do something like this at the command-line:

VBoxManage clonehd "DiskToClone.vdi" "ClonedDisk.vdi"

The VBoxManage tool will chug away and clone the disk for you, creating a new UUID in the process:

virtualbox-clonehd-2

The cloned disk can now be used on a new VM without incurring the ‘I already know about this disk’ error.

Copying a Disk – The ‘Unsupported’ Method

The alternative to the CloneHd tool is an undocumented option available in VBoxManage – the setvdiuuid command. As the command help states: ‘This is a development tool and shall only be used to analyse problems. It is completely unsupported and will change in incompatible ways without warning’. Because of this, let me add a little disclaimer: I don’t accept any responsibility if you completely destroy your VM using this procedure. Having said that, it appears to work without issue, so I’m more than happy to use it myself – just make sure that you take a backup of you virtual disk before using it if necessary.

To use the tool, simply create a copy of the virtual disk’s VDI file in Windows Explorer; open the Windows command-line and issue the setvdiuuid command for the newly copied disk:

VBoxManage internalcommands setvdiuuid "CopiedDisk.vdi"

The tool will create a new UUID and assign it to the disk:

virtualbox-setvdiuuid

The new copied disk can now be used on a new VM without incurring the ‘I already know about this disk’ error.

21 Responses to “How-To: Clone or Copy a VirtualBox Virtual Disk”


  1. 1 swordfish147

    Amazingly simple. I’ve been trying the official method for ages and kept getting it all wrong. This is by far the easiest method I’ve come across and I guess would be very easy to make a GUI of. I’ve successfully copied and now running a second XP VW using a Win 7 host. Thanks for publishing

  2. 2 cope

    I try to do method 2 and get error:

    ERROR: failed to create the VirtualBox object!
    ERROR: Could not lock the settings file ‘C:\Users\COPE7\.VirtualBox\VirtualBox.x
    ml’ (VERR_SHARING_VIOLATION)
    Details: code E_FAIL (0×80004005), component VirtualBox, interface IVirtualBox,
    callee

  3. 3 Nick Heppleston

    Are you currently running the VM you are trying to clone in VirtualBox, or otherwise have a handle open to the VDI file?

  4. 4 cope

    O Yes, the problem was because VM is turned on, now is everything OK, thank’s a lot

  5. 5 david palme

    Worked like a charm. I copied the .vdi, renamed to my liking, copied the command into the cmd prompt, opened the folder containing the new .vdi, clicked on it and dragged to the cmd window (I needed to do this to make sure the syntax was correct – seems to need exact capitalization), completed the quotes and ran: Voila!

  6. 6 DogSpit

    Thanks! This is great. I’ve cloned a number of images now using both Linux and XP. Saves me a lot of setup time. Since I need to test programs, this allows me to create a base in a very short time and I now always have an exact starting point.
    Thanks!

  7. 7 Travma

    I use VirtualBox 3.0.4 r50677 in windows and I try several methods undocumented and documented but the 2nd clone machine does not complete the boot and freze in a black screen in about when it load mup.sys driver in safe mode in xpsp3. After 2 days with experiments I notice that I have checked 2 CPU cores in “master” pc but only ONE CPU to the 2nd clone. So beware the first time to try to start the clone machine the settings in system tab and/or anyware else to be the same in clone machines as in the master machine. Afterwards, I was able to change CPU cores for the 2nd clone machine and it just work (but not for the first time eg. the first boot must complete to be able to change CPU cores). Both the commands “VBoxManage clonehd scr.dvi dest.vdi” and “VBoxManage internalcommands sethduuid SimpleCopyFromMasterImage.vdi” are working fine. Also it doesn’t matter if I unload images or not before using these commands.

  8. 8 Jason

    Slightly off-topic, but I’m looking for some VirtualBox help and you seem to be the most knowledgeable person that knows how to present material and be understood. I have a WinXP host running VirtualBox 3.1.2 r56127. I have two VIMs, each running WinXP. Host computer has an instance of SQL Server 2005 Express installed. One of my two VIMs also has an instance of SQL Server 2005 Express installed. I can’t get my second VIM to connect to either database server. The only help I’ve gotten so far is to use “Bridged Adapters” for my network settings. Um, well, did that and it still ain’t working. There must be more to it. Can you help?

  9. 9 Nick Heppleston

    Hi Jason,

    I had exactly the same problem with 3.1.2 r56127 running two Windows Server 2008 VM’s on a Windows 7 host. I found that if I started the VirtualBox Admin Console as an administrator (i.e. ‘Run as administrator’) and then started the VM’s the networking works! I think it must be a bug in this version – I suppose we just have to wait until the next release :-(

    Let me know if this solves your problem….

    Nick.

    ps. VirtualBox Bug Tickets http://www.virtualbox.de/ticket/5949 and http://www.virtualbox.de/ticket/5924 have been raised that address this issue.

  10. 10 Benjy

    Hi Nick,
    Very useful post. I have a slightly tangential question. What do you do about differencing disks? In VPC I could have a base workdisk (say with VS installed) and then a diff disk (with BTS and SQL) and still use the base to create a number of other diff disks (and in fact use the diff disk itself as a base). I can go to 3 levels with this. Virtual Box doesnt have this kind of functionality. I can take a snapshot, but I cant just export that particular snapshot (or a base + a number of snapshots) into a single package and use that. I have to keep cloning the machine and installing particular software on the clone to mimic what we have in VPC.

    benjy

  11. 11 Jerry

    Benjy,

    You want to use the -remember switch on clonehd.

  12. 12 Super VirtualBox

    Brilliant! Thanks for putting in the time and effort for this wonderful how to. Very Good!

  13. 13 Chris

    How do you specify the uuid explicitly, i.e. this method assigns the uuid, but I want to be able to specify the new uuid.

  14. 14 Nick Heppleston

    Chris, I don’t believe that you can specify the new UUID yourself – the vboxmanage tool creates a new one automatically for you ‘on the fly’. Nick.

  15. 15 Harley Pebley

    Super. I’ve never been able to get the clonehd method to work. It takes forever and says it finished successfully, but there’s never a new vdi created. Weird. But this method worked both faster and correctly. Thanks for sharing!

  16. 16 JoeJackson

    Just wanted to say thanks for the article…

    Works fine with version 3.1.6 r59338

  17. 17 Kevin Woo

    Hi Nick,

    I update to VirtualBox v3.2.4r62431, tested the “VBoxManage internalcommands setvdiuui” invocation and am happy to report that it still works.

    Kev

  18. 18 Akaash

    Hey Nick,
    Gr8 work bro…it’s working on VBox 3.2. I’ve been searching for a solution for cloning a hd for about a week coz the method explained in Help menu of VBox is a bit confusing for me…

    Akaash

  19. 19 Kebabbert

    This is wrong:
    VBoxManage clonehd “DiskToClone.vdi” “ClonedDisk.vdi”

    You must specify the full path, otherwise it will not work! This is correct:
    VBoxManage clonehd C:\FullPath\DiskToClone.vdi C:\FullPath\ClonedDisk.vdi

  1. 1 The right way to backup a virtualbox .vdi file « Vinh Pham's Blog
  2. 2 Clone a VirtualBox Machine : Steve Smith's Blog

Leave a Reply





Get Adobe Flash playerPlugin by wpburn.com wordpress themes

Nick Heppleston’s BizTalk Blog is Digg proof thanks to caching by WP Super Cache