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.

39 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

  20. 20 bujy

    I am using VBox 3.1.2 r56127 and tried to clone the disk like follows (but it didn’t work)

    D:\work\VDI>set PATH=%PATH%;c:\Program Files\Sun\VirtualBox
    D:\work\VDI>vboxmanage clonehd “trunk.vdi” “work.vdi”
    VirtualBox Command Line Management Interface Version 3.1.2
    (C) 2005-2009 Sun Microsystems, Inc.
    All rights reserved.

    ERROR: Cannot register the hard disk ‘D:\work\VDI\trunk.vdi’ with UUID {179d52d8-b463-40c7-a635-784f
    787c2648} because a hard disk ‘D:\work\VDI\trunk.vdi’ with UUID {179d52d8-b463-40c7-a635-784f787c264
    8} already exists in the media registry (‘C:\Users\bujy\.VirtualBox\VirtualBox.xml’)
    Details: code E_INVALIDARG (0×80070057), component VirtualBox, interface IVirtualBox, callee IUnknown
    Context: “OpenHardDisk(Bstr(szFilenameAbs), AccessMode_ReadWrite, false, Bstr(“”), false, Bstr(“”),
    srcDisk.asOutParam())” at line 628 of file VBoxManageDisk.cpp

    IT WORKED ONLY WHEN I USED A COMMAND LIKE THIS:

    D:\work\VDI>vboxmanage clonehd f950273f-7a42-46f4-90e4-93441f6cad45 ids_work.vdi –format VDI
    VirtualBox Command Line Management Interface Version 3.1.2
    (C) 2005-2009 Sun Microsystems, Inc.
    All rights reserved.

    0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
    Clone hard disk created in format ‘VDI’. UUID: 4b3300bd-4013-4913-a205-feb5fbf16f5c

    Basically instead of specifying the name of the DiskToClone.vdi I had to specify its UUID
    The new vdi was created on c:\work\VDI even if the clone command was executed on d:\work\VDI

  21. 21 bela

    After upgrading to 4.0 (Linux host) I found that “VBoxManage internalcommands setvdiuui” is not working.

  22. 22 Oliver Stephan

    With version 4 of VirtualBox the internal command is “sethduuid” and works the same way.
    vboxmanage internalcommands sethduuid copied.vdi

  23. 23 Hank

    Can you explain why (on a Windows host) it is necessary to change the UUID using the command line?

    My coworker on a Mac host uses only the pulldown menus to Export a VM and then import several copies of it, and says there is no need to do anything with the command line at all and it should work the same way on a Windows host.

    I’ve been given a Windows host to do this same task.
    I am following his instructions — doing it his way so far.

    There have been some unexplained errors.

    Could someone spell out exactly what sorts of errors would be explained by omitting changing the UUID, with a Windows host?

  24. 24 Hank

    Also, has anyone confirmed this easy command line method works under VirtualBox 4.0.0?

  25. 25 Bob

    Sorry a little help needed by a novice user of Virtual Box 4.0.0

    I’m at the following prompt C:\Program Files\Oracle\VirtualBox>

    and I add the following to the command prompt (above) – it doesnt work so I must be doing something wrong!

    VBoxManage internalcommands setvdiuuid “C:\Users\Office\VirtualBox VMs\Windows XP Virtual Disk\Windows XP Virtual Disk.vdi

    Im a first time user of Virtual Box and I need to make copies of my ‘base’ vdi so I can install different software on each copy.

    Thanks in advance.

  26. 26 CalcProgrammer1

    The command is changed in VirtualBox 4, it is now

    VBoxManage.exe internalcommands sethduuid

  27. 27 Pat Tormey

    The command has changed to sethduuid…
    recommend building a simple batch file

    “C:\Program Files\Oracle\VirtualBox\VBoxManage” internalcommands sethduuid “D:

    \VirtualBox Machines\NewClone.vdi”

  28. 28 Mubbasher Khanzada

    Hi Nick,
    Great post… many thanks for explaining it in very simnple and elegant manner.
    I noticed that for cloning the Virtual Drive, the original setvdiuuid specified in your post did not work on my Virtualbox, however replacing it with sethduuid did the job, thought would let others know if original command does not seem to be working.

    Thanks again.
    Mubbasher.

  29. 29 Sean

    Hi

    My suggestion is to do what Pat said.
    Create a txt file
    paste the following:
    “C:\Program Files\Oracle\VirtualBox\VBoxManage” internalcommands sethduuid %1
    @pause

    Save as .bat

    Now u can drag your vdi on to this file and it will reset the uuid :)

  30. 30 isavel

    thanks, your save me a lot of time!!!

  31. 31 Shah Murad

    This cloneHD command worked perfect!!! Thanks to Nick for the tips and also taking the time to add command line screen shots
    Much appreciated!!!
    Shah Murad

  32. 32 Amir

    Thank you so much. This helped me a lot. cloneHd wasn’t working for whatever reason. But sethduuid worked out. Much quicker!

  33. 33 kham

    I’am new to VirtualBox … this is a great post.

    Thanks

  34. 34 kham

    To clone an entire VBox do we have to to the same for all created files ?

  35. 35 Devarishi

    The command has changed to “sethduuid” (I am using VirtualBox 4.1.8 version):

    C:\Program Files\Oracle\VirtualBox>VBoxManage internalcommands sethduuid “C:\CentOSDup.vdi”
    UUID changed to: ac3f7a4d-da4f-4077-be7b-4fcac9fd9f88

  36. 36 Frank

    @echo off
    cls
    c:
    cd \
    cd “C:\Program Files\Oracle\VirtualBox>”
    VBoxManage internalcommands sethduuid %1
    @pause

  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
  3. 3 More VirtualBox fun–Cloining a hard disk. | CCG TechBlog

Leave a Reply





Get Adobe Flash playerPlugin by wpburn.com wordpress themes