Cloning and Copying VirtualBox virtual machines

Change History
2013-12-08: Updates.
2011-09-22: Updates.
2008-11-03: Updates.
2008-11-01: First draft.

This article explains how to clone and copy VirtualBox VMs (virtual machines).

Update December 2013: An easier way to merge snapshots

Verified this technique with VirtualBox 4.3.4.

VirtualBox has come along since I fist posted this article back in 2008 (Version 2.0.4) — the latest version of VirtualBox (4.1.2) adds a Clone command which largely renders the techniques described below redundant and hugely simplifies matters (although they will still be useful if you are interested in fine-grain snapshot management).

Here’s the procedure to merge and compact all the snapshots to a new VM containing a single VDI file:

  1. Optionally rename the VM so you can reuse its current name for cloned VM (you can change the VM name from the Basic tab of the General settings).
  2. Right-click on the VM and run the Clone… command:
    • If you opted for step 1, set the name to the VM’s original name.
    • Accept the remaining defaults i.e. do not Reinitialize the MAC address; Clone type: Full clone; Snapshots: Current machine state.
  3. Take a snapshot of the cloned VM (a roll-back checkpoint and to minimize incremental backups)).
  4. Start the new (cloned) VM and run precautionary disk checks (chkdsk or fsck).
  5. Optionally delete the old VM (right-click on the VM and run the Remove… command). If you select the Remove Only option the old VM will be left on disk and you can restore it later using the the Machine→Add… command.

Note

After cloning Windows 8 I noticed a couple of (seemly benign oddities):
  1. The first time the clone was started Windows 8 displayed the introduction to Windows 8 that you get when you first login.
  2. Opening a Microsoft Office 2010 or 2013 for the first time on the clone triggered the Microsoft Office software activation wizard.

Problems with 64-bit Windows 7 Guests with .vdmk disks

This note is off-topic but it may be of help to anyone experiencing this problem (sorry, I don’t have a solution, apart from don’t put 64-bit Windows VMs into .ova files).

After importing a .ova (Virtual Applicance) that had been previously exported from VirtualBox I experienced Windows chkdsk errors after creating a snapshot. The chkdsk problems seemed to change with each chkdsk, the problems seemed to snowball. Here are the circumstances under which I was able replicate this problem (I didn’t try any other scenarios):

  • Window 7 64-bit Intel i5 host and Windows 7 64-bit (Intel i7) host.
  • Only Windows 7 64-bit guests (XP, Vista and Win7 32-bit guests are all fine).
  • After the first snapshot has been added.
  • VirtualBox 4.0.8 and 4.1.2.

The techniques described in this article were tested on a Windows XP Pro SP2 host operating system using VirtualBox version 2.0.4. The details may vary if you use a Linux or some other host OS.


Introduction

Cloning and copying VirtualBox VMs is not as straight forward or obvious as it is with VMWare Desktop and this subject has created a lot of confusion in the support forums. This is because:

  • There is no single VirtualBox command for VM cloning.
  • The documentation is vague.
  • A couple of the VirtualBox commands are poorly named.

The good news is that the underlying technology is just great and with a little understanding copying and cloning VMs is quite easy.

This article explains how to copy an existing VM containing an installed and configured guest OS. Before starting it helps to have a basic understanding of VirtualBox virtual machines.


Virtual Machines

A VirtualBox VM consists of three parts:

  1. One or more virtual hard disk image files (VDI files).
  2. Zero or more Snapshots (also VDI files).
  3. XML configuration files defining the VM (virtual hardware parameters).

Snapshots

  • A snapshot bookmarks the state of the VM (specifically the VM file system) at the point in time the snapshot is made.
  • You return to a previous snapshot by deleting the current state and all newer snapshots.
  • When you create a snapshot, changes to the file system accumulate in the current snapshot file, older snapshot files and disk image files are effectively read-only.
  • If there are no snapshots the VM’s disk image file accumulates file system changes just like normal disks — the VM’s Current State is merged into the disk image automatically when you close the VM.

With respect to copying the important thing to understand about snapshots is that there is no easy way to copy them, so if your source VM has any snapshot information that you want to copy you first need to merge the snapshot(s) into the source VM’s disk images.


Copying a Virtual Machine

Here’s an outline of the copy process:

  1. If the source VM has any snapshot information that you want to copy you first need to merge the snapshot(s) into the source VM’s disk image files.
  2. Make a clone the source VM’s disk image file(s).
  3. Create a new VM and attach the cloned disk image file(s).

Here are the details:

Merge source snapshots

Here’s how to merge the source snapshots to the source disk image VDI file (skip this step if you source VM doesn’t have any snapshots).

  1. If the source VM is running close it.
  2. From the VirtualBox window select the source VM then click the Snapshots tab.
  3. If you want to include the current state of the disk in the merge save it as a snapshot by selecting the Current State then executing the Take Snapshot (Ctrl+Shift+S) command.
  4. Select the most recent snapshot you want to include in the target VM and execute the Discard Snapshot (Ctrl+Shift+D) command. This merges the snapshot file into it’s parent VDI file (snapshot or base disk).
  5. Repeat the previous step, working your way down the snapshot list until the oldest snapshot has been merged into the base VDI.

The VirtualBox snapshot commands are poorly named, in particular the inconsistent and confusing use of the word Discard:

Command Should be named Applied to Description
Discard Snapshot (Ctrl+Shift+D)
Merge with Parent
Snapshot
Merges the snapshot file into the parent snapshot or disk image file and then deletes the now redundant snapshot file.
Revert to Current Snapshot (Ctrl+Shift+R)
Current State
Deletes the current state returning the VM state to the most recent snapshot.
Discard Current Snapshot and State (Ctrl+Shift+B)
Delete Current Snapshot and State
Current State
Deletes the current state and the most recent snapshot returning the VM state to that of the penultimate snapshot. Use this command to delete snapshots.

Clone or copy the source disk image

At this point the entire state of the source VM that we want to copy is contained in the disk image VDI file.

To avoid confusion I use the term copying to refer to copying a VM to different host machine and the term cloning to refer to creating a copy on the same host.

Copying to another host machine
If you want to create a copy on another host machine you simply copy the disk image to the new host.

  1. If the source VM is running close it.
  2. Copy the source disk image to the VirtualBox VDI directory on the target host machine. You’ll normally find the source disk image in the VirtualBox VDI directory (the standard VDI location on Windows hosts is C:\Documents and Settings\<username>\.VirtualBox\VDI).

Once you’ve copied the disk image you need to register it with VirtualBox on the target host machine:

  1. From the VirtualBox window select File→Virtual Disk Manager (Ctrl+D) menu command.
  2. Press the Add button and select the copied disk image file.

Creating a clone on the same host machine
Use the VBoxManage command-line utility the clonevdi command option to clone and register the disk image (you can’t just copy the disk image to the same host machine because the disk UUID will conflict with the source disk image):

  1. Open a Command Prompt window on the host machine.
  2. Change to the VirtualBox VDI directory (normally C:\Documents and Settings\<username>\.VirtualBox\VDI).
  3. Now run the VBoxManage command with the clonevdi command option. The following example transcript shows the creation of a copy of Ubuntu 8.04.vdi named Ubuntu 8.04 clone.vdi and registers the new disk:
    C:\Documents and Settings\srackham\.VirtualBox\VDI> "C:\Program
    Files\Sun\xVM VirtualBox\VBoxManage.exe" clonevdi "Ubuntu 8.04.vdi"
    "Ubuntu 8.04 clone.vdi" VirtualBox Command Line Management Interface
    Version 2.0.4 (C) 2005-2008 Sun Microsystems, Inc.  All rights
    reserved.
    
    0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
    
    C:\Documents and Settings\srackham\.VirtualBox\VDI>

My experience is that merging snapshots into a single base VDI saves a lot of space (a Windows XP guest with 5 snapshots shrank from 8.6GB to 3.7GB) but defragging the drive and then running the VBoxManage modifyvdi compact command didn’t appear to regain any disk space in either Windows XP or Vista.

Create a new virtual machine

There is no command to copy a VM so we create a new VM and attach our copied disk to it:

  1. From the VirtualBox window select Machine→New… (Ctrl+N) menu command.
  2. Work your way through the Create New Virtual Machine wizard till you get to the Virtual Hard Disk page then press the Existing… (not the New…) button and select the disk image VDI file that you previously cloned or copied.

That’s it, you should now be able to start and run your new VM.

Warning

Try not to be tempted to edit the VirtualBox XML configuration files manually — the files are interrelated and making changes manually is not as easy as it looks (I’m talking from experience here) — best to use the VirtualBox commands instead.

Final Thoughts

Although I have not tried, it should be relatively easy to automate the copying and cloning procedures by scripting the powerful VirtualBox VBoxManage command.

162 Responses to “Cloning and Copying VirtualBox virtual machines”

  1. Sham Says:

    Stuart,
    Excellent article. Wish I had read this article earlier.
    After I have cloned the vdi; I have realized that the snapshots are not considered. I deleted the snapshots altogether now so will have to start from scratch.
    Many thanks for this note.
    Cheers, Sham

  2. Jason Says:

    Excellent, thanks for posting this, it worked like a charm!

  3. Jason Says:

    one thing to note here also is that you can create lots of clones at once but it takes forever, I ran the script to create 5 machines and it took almost 4 hours for machines with only 20gig vdi files, ouch! Otherwise it takes about 30-40 minutes to do one at a time.

    • O C Says:

      Experiment with a timeout buffer, this actually speeds things up. I believe it is to do with exhausting the burst capability on the SSD. You will notice the initial clone creates, quickly then a downturn. either way, clone1…timeout…clone2 allows the system to recover and deliver the second clone more quickly.

  4. Ed Gomez Says:

    I tried to clone one of my drives – host is Vista Home Premium guest is XP Pro. While it was very easy to create the original, I wanted to make a clone of it so I can run tests without having to reenstall XP each time. In VMWare, I merely create a copy renamed it and VMWare reasigned the identifier. The technique named above did indeed allow the copy to be made (clonevdi Virtualbox version 2.1) – – but it would not run. My script was:

    “C:\Program Files\Sun\xVM VirtualBox\VBoxManage.exe” clonevdi “XP_Pro_Org.vdi” “XP_Protest2.vdi”

    The message on a black screen was:

    “Windows could not run because of an error in the software. Please report this problem as: load needed DLLs for kernal. Please contact your support person to report this problem.”

    What went wrong?

    • Devarishi Says:

      Thanks Ed!

      I first tried clonevdi command but I got an error because I had copied the vdi file on a different partition but the HDUUID was already registered so it didn’t work. Then I read your comment and the problem was resolved!

      So, this command is very useful and works fine…

      VBoxManage.exe” internalcommands sethduuid “virtualHDName.vdi”
      Okay, right now I am checking out the cloned / duplicate Guest OS. Thanks to you again!

  5. Ed Gomez Says:

    I have read the internet literature and have found a workaround that works!

    In windows copy to the drive and rename it to what you need. Then get a command screen to the directory that houses the drive(s). Use:

    “C:\Program Files\Sun\xVM VirtualBox\VBoxManage.exe” internalcommands sethduuid “xp_protest.vdi”

    This will change the uuid of the drive. “XP_protest.vdi” is the copy of the disk file, as I named it on my system. Now I am free to start using VirtualBox without fear of losing data. You must go through the creation of the drive with “add” and “existing” in the proper places…

    You can copy a file from another computer or a backup of your own making by manually doing what VMWare does automatically – recreate the uuid! But pricing on VirtualBox is much lower! It does all I need in a much easier way than VMWare. The only hangup was the backup/transfer from/to another compute, with which I had a problem. Now that that is over – I am a happy man!

    • Chris Rosin Says:

      Thanks, Ed! This worked perfectly for me (Vb version 3.2.8 r64453)

      1. Copy your VDI, rename if necessary
      2. Run the command line below (note change in path for my version)
      “C:\Program Files\Oracle\VirtualBox\VBoxManage.exe” internalcommands sethduuid “whatever your VID is called.vdi”
      3. In VBOX – File, Virtual Media Manager, New, point to your new VDI copy.
      4. In VBOX – Machine, New, Use Existing HD, Select the new file/media you added above in step 3. BINGO! Happy Cloning…

      The Rosinbag

  6. Mark Says:

    Thanks for the awesome write-up. I’d read several other pages on this topic but was still confused until I read yours.

  7. Harley Pebley Says:

    Thanks for this; it helped a lot.

    One thing I ran into was a cryptic error trying to clone:
    [!] FAILED calling virtualBox->OpenHardDisk2(src, srcDisk.asOutParam()) at line 372!
    [!] Primary RC = VBOX_E_IPRT_ERROR (0x80BB0005) – Runtime subsystem error
    [!] Full error info present: true , basic error info present: true
    [!] Result Code = VBOX_E_IPRT_ERROR (0x80BB0005) – Runtime subsystem error
    [!] Text = Could not get the storage format of the hard disk (VERR_FILE_NOT_FOUND)
    [!] Component = HardDisk2, Interface: IHardDisk2, {ed6e2525-c2fd-42a4-917a-7a9045ac9e15}
    [!] Callee = IVirtualBox, {339abca2-f47a-4302-87f5-7bc324e6bbde}

    Apparently the directory where the VDI files changed from 1.x to 2.x and by default VBoxManage only looks in the new location. When I gave the full path for the source, it was able to find and clone it properly.

    Hope it helps someone.

    Cheers,
    Harley Pebley

  8. Larry Magnuson Says:

    Thanks a lot. You got this exactly right. Both the nomenclature and the steps of the process are non-intuitive. VB 2.1 VBoxManage also has an internal command to change the UUID of a copied vdi file: “VBoxManage internalcommands sethduuid copiedfile.vdi”
    This worked successfully for me.

    Thanks again for the clarity.

  9. David Says:

    I’m getting an error message trying to use the clonevdi command:

    C:\Documents and Settings\user\.VirtualBox\VDI>”c:\Program Files\Sun\xVM Virt
    ualBox\VBoxManage.exe” clonevdi “Windows XP Pro.vdi” “Windows Vista.vdi”
    VirtualBox Command Line Management Interface Version 2.1.2
    (C) 2005-2009 Sun Microsystems, Inc.
    All rights reserved.

    [!] FAILED calling a->virtualBox->OpenHardDisk2(src, srcDisk.asOutParam()) at line 369!
    [!] Primary RC = VBOX_E_IPRT_ERROR (0x80BB0005) – Runtime subsystem error
    [!] Full error info present: true , basic error info present: true
    [!] Result Code = VBOX_E_IPRT_ERROR (0x80BB0005) – Runtime subsystem error
    [!] Text = Could not get the storage format of the hard disk ‘C:\Documents and Settings\user\.VirtualBox\HardDisks\Windows XP Pro.vdi’ (VERR_FILE_NOT_
    FOUND)
    [!] Component = HardDisk2, Interface: IHardDisk2, {ed6e2525-c2fd-42a4-917a-7a9
    045ac9e15}
    [!] Callee = IVirtualBox, {339abca2-f47a-4302-87f5-7bc324e6bbde}

    C:\Documents and Settings\user\.VirtualBox\VDI>

  10. Dragonseer Says:

    Thanks for the tips. I agree with your point that the naming conventions for handling snapshots should be changed. Why ‘merge’ is labeled as ‘delete’ I really don’t know.

  11. AlThePal Says:

    Hi,

    Thanks for an excellent write up – this cleared up a lot of confusion for me. One thing I found was that when creating a clone on the same host machine, I had to run the VBoxManage command from one directory further up the tree i.e. from the .VirtualBox directory. If I tried to run it from the VDI directory I got a VBOX_E_IPRT_ERROR (Could not get the storage format of the hard disk). I’d imagine this is due to a path problem. Obviously then you need to add “VDI\” before the name of the original and cloned files.

    Al

  12. Jason Chen Says:

    Very helpful instruction. I just follow your steps and make it work without problem. If only they can just create a simple “clone” button next to each of the snapshot, then we will be all set.

    Thanks for this blog.

  13. Mazen Harake Says:

    Thank you! This helped ALOT! I don’t understadn why they just didn’t have a “clone” button in the UI ??

    Anyway, thank you, you saved me a lot of time :)

    Regards

  14. kemiisto Says:

    Thanks! Very usefull instructions set, even for me, Mac OS X user. =)

  15. Angry VBX User Says:

    Thank you, thank you and Thank you. This page must be bookmarked by all VirtualBox users.

    It turns out that the scariest option “Discard” does exactly the opposite (meaning it save instead of throwing away)

    I have lost 2 days of work because of the confusing wording of the snapshot GUI in VirtualBox 2.14. Definitely there is a translation issue on the wording of the snapshot options. Must use clear words like “Merge”, “Commit”, “Rollback” rather than “Discard”. Also the VBoxManage clonehd must allow an option to clone from the LATEST snapshot.

  16. Andreas Says:

    GREAT!!!! This saved my day!!!! I also got tricked by the misleading use of ‘discard’ in Virtualbox!!

  17. Florian Says:

    Great post, this is what is missing it the manuals for VirtualBox…

    Your “final thoughts” are well thougth and this has already be done:

    http://www.die-rooter.de/ITworks/archives/4-VirtualBox-CloneVDI.html

  18. Peter Valdemar Mørch Says:

    What a damn shame one can’t clone an entire virtual machine including snapshot hierarchy to another machine. Thanks for this howto. And Yes, the VirtualBox snapshot commands really are poorly named.

    Love AsciiDoc! (Thats how I found this article) – perhaps I’ll try blogpost.py one day…

  19. Eric Says:

    Am I reading this correctly – the only way to back up a guest VM with snapshots in its “most recent” state is to merge them all (and therefore losing all the “old snapshots”?)

  20. R.Cvancar Says:

    Very helpful article !
    I copied a VM on the same host machine (Host: Linux 10.3, VirtualBox 2.0.6).
    Log in as root, change to ‘/usr/bin’, and ‘VBoxManage’ will do the job as described above :-)

  21. tom Says:

    Thanks for posting this. I needed my snapshots to come along for the ride.

  22. mpo Says:

    Thx for this howto, very useful. Since you hitted well in the google-rank, the following addendum might be useful to others comming along:

    Apparently the syntax of the VBoxManage clonevdi command has slightly changed.

    I could run it from any ‘current working directory’ but I had to specify the *vdi files (both source and target) with their relative paths under the $HOME/.VirtualBox directory

    So for my setup with HD files at $HOME/.VirtualBox/VDI, I had to use
    VBoxManage clonevdi ./VDI/source.vdi ./VDI/target.vdi
    to make the disk-clone

  23. Richard Says:

    Thank you for the detailed description and instructions. However I feel some detail must be missing. After trying your instructions for the 3rd time, I am always left with the base-installation of my guest os (Fedora-10) just prior to making my first snapshot.

    The snapshots are deleted and the xml references to them are removed. I restored from backups, modifying the xml to get it functioning and ran the vm to verify the restore worked.

    I have become good at modifying the xml, and figure I can just write my own utility to migrate
    an image to another host. However it would be good to not have to include the snapshots with my distribution (amongst local dev’s in our department). Here are some details I came across that the instructions above seem to have glossed over:

    1) The last entry in the ‘Snapshots’ tab is always a “Current State” item, further this may be showing as “(changed)” or not.

    2) If “changed”, then the instructions advise creating a new snapshot first. Doing so creates a new snapshot with the last entry as “Current State” without the “(changed)” flag.

    3) At this point the instructions say to select the latest snapshot we want, and select “Discard Snapshot”, and this will be merged into the parent. However the latest is always the “Current State”. There is no “Discard Snapshot” option for the Current State entry, just “Revert to Current”, “Discard Snapshot and State” and “Take Snapshot”. If I select the actual snapshot, I can “Discard Snapshot”. So I do this.

    4) Select “Discard Snapshot” from the snapshot parent of “Current State”. This takes a very long time, and I’m left with the previous snapshot and a “Current State (changed)” entry.

    5) Now, do I create a new snapshot, since I have a changed “Current State”? It seems I could go in circles here, so I continue and select the now last snapshot (since I just discarded, or “merged” one). I select “Discard Snapshot”.

    6) Will this include the “Current State (changed)” entry data? Not sure, but it takes a long time again to complete (my images and snapshots are between 6GB – 11GB in size, so I’m not surprised it takes a while – this is encouraging)

    7) Now I am left with just a “Current State (changed)” entry, and no snapshots. But when I fire this up, it is just the base install, with no snapshot changes included. All my configurations are gone. Looking at the file-system, I notice that the “Snapshots” folder is now empty, and the “HardDisks” folder just has a single file dated from the time 3 weeks ago when I created the first disk, before taking my first snapshot.

    What happened to my snapshots? It seems VBox took a long time to delete them and provide nothing else. There doesn’t seem to be much evidence of any merging of data/files taking place.

    Conclusion:
    Unless there is something I missed (I tried the above 3 times), it doesn’t seem that VBox can merge snapshots into the main HardDisk file. The only way I was able to migrate an image was to copy all snapshots and xml files to the new system and install them intact (with minor tweaks to the xml).

    Please feel free to rip apart what I’ve done and expose any errors in my understanding. I just cannot believe that Sun would make such an excellent product (it runs great) without the ability to migrate the images with a degree of ease.

    Well, then again it’s free software, and not as mature as VMWare – but for the price VBox is pretty amazing.

    – Richard

    3)

  24. Richard Says:

    Well, what do you know?

    While writing the above I was also in the midst of a final attempt. This time it appears to have worked and my HardDisk now is much larger and contains the sum of all snapshots.

    I feel like an idiot, but hey that’s operational development for you.

    I would only then add a single additional step if the instructions above fail:
    1. Write a post explaining with excruciating detail everything you’ve done, make a fool of yourself, and post it before completing your final attempt. It will surely work this time.

    Thanks guys,
    – Richard

  25. Ben Says:

    Cool, the same basic procedures work great on Mac OS X 10.5.6 with VirtualBox 2.1.4 for Mac.

    Main difference is the files are located in:
    \Library\VirtualBox\HardDisks\
    and
    \Library\VirtualBox\Machines\

    Command line syntax is just the same except for the pathing. On the Mac you can just cd down into the HardDisks directory and run:

    vboxmanage clonevdi “Ubuntu 8.04.vdi” “Ubuntu 8.04 clone.vdi”

    And off you go. :)

  26. Michael Tansella Says:

    Thank you very much!!!
    First time that I understand it

  27. Stefan Says:

    Thanks for this. Stefan.

  28. Slavi Says:

    Thanks for the nice article.
    What is strange is that I have the same Ubuntu image 8.04 :)

  29. Slavi Says:

    On MAC one may see this error: “Could not get the storage format of the hard disk”

    Solution: It needs an absolute path. Relative goes to default disk image location

    Credits: http://forums.virtualbox.org/viewtopic.php?f=8&t=15021

  30. Ragnorok Says:

    – Nice, Stuart. Thanks!!

  31. AlThePal Says:

    Another minor correction. In your ‘Merge source snapshots’ section, you state in step 3 that the current state of the disk can be included in the merge by taking a snapshot. Step 4 then instructs the user to use Discard Snapshot on the most recent snapshot you want included in the target VM. However, if you do this on the snapshot created in step 3, it deletes the snapshot, but changes are not saved in the previous snapshot. Rather they are put back into the current state of the disk.

    In this case, what you have to do is create a snapshot as per step 3, then delete the prior snapshot(s) to the one you have just created. The snapshot you are left with will then contain the current state of the disk.

  32. Gil Says:

    What a great post and instruction guide this is. Really well-done and composed. Explained everything clearly. Perfect. Thanks!

  33. Gil Says:

    Just one other word to the wise: Be sure you have enough disk space before you discard a snapshot, especially if it’s a 20Gb-type large snapshot file because you are going to need basically 2x the actual disk space of the update .vdi file. I found this out. My disk ran out of space during a snapshot discard operation. I was able to get around it by moving the snapshots and the .vdi file to an external USB harddrive and then creating soft links in their original locations and fortunately was able to restart the discard snapshot operation. It’s much slower over the USB but at least it will probably finish ok this time.

  34. Niko Says:

    Thanks for your information!, but as i tried to clone a vdi, it didn’t work, so i googled and found out on that website: http://www.virtualbox.org/ticket/3888 that i need to include the complete path of the vdi files in order to get it cloned – so now it works!
    Here is the full example:

    ——————————————————————————–

    C:\Documents and Settings\srackham\.VirtualBox\VDI> “C:\Program
    Files\Sun\xVM VirtualBox\VBoxManage.exe” clonevdi “C:\Documents and Settings\srackham\.VirtualBox\VDI\Ubuntu 8.04.vdi” “C:\Documents and Settings\srackham\.VirtualBox\VDI\Ubuntu 8.04 clone.vdi” VirtualBox Command Line Management Interface
    Version 2.0.4 (C) 2005-2008 Sun Microsystems, Inc. All rights
    reserved.

    0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%

    C:\Documents and Settings\srackham\.VirtualBox\VDI>

    ——————————————————————————–

    And for those who don’t know how to get into the path with the cmd:
    Just type
    cd C:\Users\Your Username\.VirtualBox\VDI
    And then the your command, e.g.:
    “C:\Program Files\Sun\xVM VirtualBox\VBoxManage.exe” clonevdi “C:\Documents and Settings\srackham\.VirtualBox\VDI\Ubuntu 8.04.vdi” “C:\Documents and Settings\srackham\.VirtualBox\VDI\Ubuntu 8.04 clone.vdi”

    Good luck!

  35. Niko Says:

    without the extra wide spaces in between, of course.
    sorry

  36. Federico Cáceres Says:

    Thank you, I just did a barbaric copy paste of the virtual disc image file, but when I saw I could not import the old virtual machine configuration file i was lost. Thanks for poiting out that there is no easy way to use the old file and that we have to recreate a VM poiting to the same disc image file. Not very friendly, but quite effective.

  37. Steve Holden Says:

    A valuable article for the explanation of merging snapshots. You are right about VirtualBox terminology being confusing, and the documentation is no help at all. I’d almost certainly have lost information if I’d gone ahead without having read this article. Thanks.

  38. xiao Says:

    very handy, thanks

  39. Von Says:

    Very nice write up.

  40. mv288 Says:

    You will run into a network related issue in cloned images on booting
    them.

    eth0 in the cloned instances will not start due to this error.

    SIOCSIFADDR No such device eth0 error while getting interface flags

    (I got to that error by running $sudo ifup -a )

    This forum here has a good description of the problem and a solution
    http://ubuntuforums.org/showthread.php?t=255018

    If the steps in that forum do not work, simply remove eth0 mappings and change eth1 to eth0. Restart the server to see the changes take effect.

  41. Otheus Says:

    Right, so cloning a VM is cloning the hard drive. What if you want to clone the VM settings itself (except disks, uuid, and name)? Here:

    alias vbm=VBoxManage
    vbm createvm --register "$newvm" || die "Could not create vm $newvm"
    # read all parameters into variable list Some hacks are needed:
    #    (0) upper-case arguments areg state-dependent.
    #    (1) replace first = with blank
    #    (2) in version 2.2.2, biosbootmenu is the parameter, but machinereadableoutput is bootmenu
    #    (3) exclude machine-specific parameters (disk, mac address)
    #
    modifyargs="$(                                                                                                                                                  vbm showvminfo --machinereadable $template |
      sed -e '1,/^$/d;/^[A-Z]/d;s/=/ /;' \
          -e 's/^bootmenu/biosbootmenu/;' \
          -e '/^sata\|macaddress[0-9] \|hd[a-d] \|name /d' \
          -e 's/^/--/'
    )"
    eval vbm modifyvm $newvm
    
  42. Otheus Says:

    Right, so cloning a VM is cloning the hard drive. What if you want to clone the VM settings itself (except disks, uuid, and name)? Here:

    # Clone a VM by creating a new VM and cloning the settings from the existing vm ($1) named $2
    template="$1"
    newvm="$2"
    
    alias vbm=VBoxManage
    vbm createvm --register "$newvm" || die "Could not create vm $newvm"
    # read all parameters into variable list Some hacks are needed:
    #    (0) upper-case arguments areg state-dependent.
    #    (1) replace first = with blank
    #    (2) in version 2.2.2, biosbootmenu is the parameter, but machinereadableoutput is bootmenu
    #    (3) exclude machine-specific parameters (disk, mac address)
    #
    modifyargs="$(
      vbm showvminfo --machinereadable $template |
      sed -e '1,/^$/d;/^[A-Z]/d;s/=/ /;' \
          -e 's/^bootmenu/biosbootmenu/;' \
          -e '/^sata\|macaddress[0-9] \|hd[a-d] \|name /d' \
          -e 's/^/--/'
    )"
    eval vbm modifyvm $newvm $modifyargs
    
  43. vcg408 Says:

    Thank you very much for this blog post. I was able to clone my virtual machine within minutes of reading this well-written post.

  44. ray Says:

    Thanks very simple and useful explanation, works fine!

  45. Kiswono Says:

    It’s working for linux too..
    VBoxManage clonevdi XP1.vdi XP2.vdi
    thank you ^^

  46. Eder Says:

    Great!!

    :)

  47. Glenn Boswell Says:

    Wow great stuff and easy to follow. I have noticed if I have a VM that is less than 4GB and will fit on dvd or fat32 drive it goes very well but if > 4GB and therefore NTFS used the process becomes a lot more envolved. Does VirtualBox use Win’s sids. Thanks.

  48. Chetan Crasta Says:

    Thanks for this post. It cleared up a lot of things.

  49. Josh Says:

    I’ve created a video walking through this process (on a Mac, but the same process would work on a PC, just using different file locations) here:

    http://joshprowse.com/virtualbox-how-to-clone-copyduplicate-a-virtu

    Hope this helps somebody!

  50. Saker Says:

    Thanks , it was ussefull for me. Thanks again.

  51. Mark Says:

    Many thanks. Indeed this is one of the most important operations that a user would want to do – it is easy to break VM so it is best to have copies available.

    Your explanation is excellent.

    Here’s an interesting error I was getting… I kept getting an error with the clone command.

    “Cannot register the hard disk ….. because a hard disk …. ….. already exists in the media registry ….”

    Mac OS X Host, XP Guest.

    The reason the command was failing – yet giving me an “already exists” error – was that I had not used the correct uppercase/lowercase spelling of the master I was copying! I had spelt the filename all in lowercase in the command.

    Go figure as to why you get an error saying file already exists instead of file not found!

    Cheers

    –mark

  52. Will Says:

    I realise this is an old post… but the command (at least for v3) is now:
    VBoxManage clonehd [options]

    ..which does the same as clonevdi, according to the doco.

    Worth noting too that the output file will be placed in the default vbox HD folder.

  53. Amnon Harel Says:

    Many thanks for this amazing guide to the muddled land of snapshots.

    I don’t understand why this is explained as “When you create a snapshot, changes to the file system accumulate in the current snapshot file, older snapshot files and disk image files are effectively read-only.” Wouldn’t it be simpler to say that the snap shot file is the OLD .dvi? Making a snap shot creates a new .dvi which is the current state (or some differential information needed to make the current state). Or am I missing something?

  54. JB Says:

    This was very helpful. Thank you!!!

  55. Vimal Says:

    Great tips. You’re right, there is a lot of confusion on how to copy an image with latest snapshot to another PC. These steps by far is the easiest way I’ve seen. Thanks for the info.

  56. Frank Diedrich Says:

    Extremly helpful. Your documentation pulled my away from thin ice.

    (The directory from where the VBoxManage command has to be invoked changed from VDI to HardDisks in Version 3.0.2).

    Cheers

  57. Aurélio Says:

    Hello Stuart,

    Thanks for all the information!

    I’ve found an easier way. Here in my VirtualBox3 I have the following menus:

    File > Export Appliance
    File > Import Appliance

    Which apparently did the same job, with no need to merge the snapshots first neither creating a new virtual machine by hand. It was all automatically done by exporting and then importing again.

    The only (minor) issue I’ve had was having to readd the shared folders.

    Oh, and the snapshots are lost on the clone. They’re untouched on the original.

  58. sridharsarnobat Says:

    Thank you for sharing this information with us. I was able to clone my Windows XP image successfully following these instructions.

  59. Justin Says:

    Thanks for this. It’s very clear and helpful.

  60. Ryan Says:

    Thanks for writing this guide! It’s not that tough once you get the process down, and you’ve helped me in doing that very much with this post. Thank you!

    Ryan

  61. jalexandre Says:

    The Version 3.0.4 of VirtualBox has a ‘ clonehd ‘ command.
    Thanks for the tip. It saved me a lot of time. :D

    [ ] ‘ s

  62. Pierre Marceau Says:

    Adding onto what I learned from this article. I would like to add my experience. I use VirtualBox on Centos 5.3 and manage my virtual machines mith VBoxManage.

    Here is how I can use snapshots.

    Machine name q3

    q3 has a one harddisk at:
    /root/.VirtualBox/HardDisks/q3.vdi

    q3 has a snapshot directory at:
    /root/.VirtualBox/Machines/Snapshots/

    Initialy /root/.VirtualBox/HardDisks/q3.vdi is my live drive and is updated constantly while q3 is running. The snapshot directory is empty.
    You might think of /root/.VirtualBox/HardDisks/q3.vdi as the ‘state’ of your drive.

    Now I make a snapshot:
    # VBoxManage snapshot take mysnapshot

    Now /root/.VirtualBox/HardDisks/q3.vdi is effectively frozen and you will see that the time stamp will never change.

    I now have a file in:
    /root/.VirtualBox/Machines/Snapshots/{0982.3123.894.72.32}.vdi
    the name is random (I think) generated by the system, but VBoxManage knows that this snapshot is named mysnapshot.

    At this point I think it worth thinking about this…
    /root/.VirtualBox/Machines/Snapshots/{0982.3123.894.72.32}.vdi
    is not your snapshot it is your live ‘state’ file, open and being updated by the running machine and…
    /root/.VirtualBox/HardDisks/q3.vdi
    is your readonly snapshot!

    Try:
    # VBoxManage showvminfo q3
    and you will see that it reports that you have a snapshot and that it’s name is mysnapshot.

    Now make another snapshot:
    # VBoxManage snapshot take mysnapshot

    and again…
    # VBoxManage snapshot take mysnapshot

    Now there will be three files in the snapshot directory, two frozen in time and the latest ‘state’ file.

    Now what I know from my few and limited tests is that you can merge your last snapshot into your second last snapshot and not lose any data.

    You would do this if you thought you had too many snapshot files and wanted to clean up…

    # VBoxManage snapshot q3 discard mysnapshot

    now you have only two files in snapshots and one of them is the live state file

    # VBoxManage snapshot q3 discard mysnapshot

    now you have only one file in snapshots and it is the live state file.

    # VBoxManage snapshot q3 discard mysnapshot

    now you no files in snapshots and
    /root/.VirtualBox/HardDisks/q3.vdi
    is once again live, with all the snapshots merged back into it and nothing lost.

    Summary:
    # VBoxManage snapshot take mysnapshot
    # VBoxManage showvminfo q3
    # VBoxManage snapshot q3 discard mysnapshot

  63. Josef Wainz Says:

    Thanks alot. I’ve used this posting twice with success. It is very helpful and clearly written.

  64. Charlie Says:

    Awesome, thanks! Took a lot of hunting to find this, but it worked perfectly.

  65. Tyson Navarre Says:

    Thanks for the tips! I needed to know how to clone my VMs and this helped a ton!

  66. Roger Says:

    If this doesn’t work, be sure to put the new vdi in a different folder, and use absolute paths for both source and target vdi.

  67. Anders Olesen Says:

    Thanks for this. It seems a little strange that there is no UI support for cloning images, since I would think that is a common operation. But thanks to you guide, I managed to get through it just fine anyway :)

  68. Bart Welvaert Says:

    Hi Stuart,

    Excellent overview – I was looking for something exactly like this. Has helped me a lot. Thanks.

    BR//Bart

  69. Phillip Hagedorn Says:

    Clean Clone of VirtualBox VM:
    VBoxManage export vmname -o vmname.ovf
    VBoxManage import vmname.ovf

    Greetings,
    Phillip Hagedorn

  70. ben Says:

    Nice notes! Have you updated this?

  71. Antonio Says:

    Thanks, the article helped me a lot

  72. Jonathan Morton Says:

    These are terrific instructions, thank you.

  73. David Ramirez Says:

    Current (as of Nov 2009) VirtualBox manual recommends using clonehd instead of clonevdi.
    clonevdi is however maintained for backward compatibility.

    VBoxManage clonehd |
    [–format VDI|VMDK|VHD|RAW|]
    [–variant Standard,Fixed,Split2G,Stream,ESX]
    [–type normal|writethrough|immutable]
    [–remember] [–existing]

  74. Tony Chung Says:

    Thanks for posting this! I’ve been playing with VirtualBox for the past month and couldn’t figure out how to keep a pristine master of my development workstation. Now I know!

    • Tony Chung Says:

      BTW: Cloning a Windows 7 VM requires a second license because the machine id changes. I guess we’ll have to resort to the original plan of copying the VDI manually and running only one instance at a time.

  75. Cristi Măgherușan Says:

    Now there’s a much easier way to copy a machine, based on the OVF support.

    Just export the virtual machine as OVF using the “File/Export Appliance” menu item, then import back the generated OVF file using “File/Import Appliance” and you can make as much copies as you want.

    You may erase the OVF file after you end up having all the clones you need..

    The drawback is that it takes a bit more disk space than the instructions found above, but it’s much smoother from the user’s perspective.

    Cristi

  76. A developper Says:

    Thank you very much for this article. It helps me a lot. (and I agree virtualbox snapshot commands should be completely renamed)

  77. Nivethan Says:

    I want to do this using command line – bo GUI, since I amm running vbox in Ubuntu Server just like a Virtual Server. Now I want another similar virtual machine within the same server, could you please let me know the steps?

    Thanks

  78. Eoin Says:

    Thanks!

    To make it explicit, the command under Linux to clone is:

    VBoxManage clonevdi source.vdi destination.vdi

  79. John McAllister Says:

    It becomes even more problemmatic if you have dropped additional hard disks in intermediate snapshots. :-((

  80. John McAllister Says:

    The scenario is that I had dropped a disk in an intermediate snapshot which it then wouldn’t discard. However discarding the snapshots above AND below the one which it won’t drop INCLUDING the original .vdi , has the effect of merging the snapshot it won’t drop back into the original .vdi. Surprisingly it even still seems to work.

  81. Watt Says:

    My friend it doesn’t work to clone when i follow the step under “Creating a clone on the same host machine” above

    i got follow message:

    H:\VirtualBox\5 linux>VBoxManage clonevdi “Feodora11.vdi” “Fedora11 clone.vdi”

    VirtualBox Command Line Management Interface Version 3.0.12
    (C) 2005-2009 Sun Microsystems, Inc.
    All rights reserved.

    ERROR: Cannot register the hard disk ‘H:\VirtualBox\5 linux\Feodora11.vdi’ with UUID {43a0b87f-d00d-410b-b798-19e90f02cb60} because a hard disk ‘H:\VirtualBox\5 linux\Feo
    dora11.vdi’ with UUID {43a0b87f-d00d-410b-b798-19e90f02cb60} already exists in the media registry (‘C:\Users\Admin\.VirtualBox\VirtualBox.xml’)
    Details: code E_INVALIDARG (0x80070057), component VirtualBox, interface IVirtualBox, callee IUnknown
    Context: “OpenHardDisk(Bstr(szFilenameAbs), AccessMode_ReadWrite, false, Bstr(“”), false, Bstr(“”), srcDisk.asOutParam())” at line 624 of file VBoxManageDisk.cpp

    H:\VirtualBox\5 linux>

    what could got wrong?

  82. Watt Says:

    ah forget it… i solve it

  83. Watt Says:

    For other that has the same problem
    always remember:

    Write:
    H:\VirtualBox\5 linux>VBoxManage clonevdi “H:\VirtualBox\5 linux\Feodora11.vdi” “H:\VirtualBox\5 linux\Fedora11 clone.vdi”

    that will have the syntax:

    VBoxManage clonevdi “path\file.vdi” “path2\file2.vdi”

    it was the path that was missing before!

    cheers

  84. Jeremy Says:

    Is it possible to also copy the BIOS DMI info when cloning a machine?

    The problem I come to is that when I clone a windows installation, it requires re-activation even though it’s on the same host.

  85. Eric Says:

    Thank you!

  86. morde Says:

    You are a genius :-)
    Thank you so much for this post, it helped me to work with VirtualBox.
    bye

  87. Ali Says:

    Thank you, that was a clear and useful article.

  88. Don Loritz Says:

    Many, many, many thanks!

  89. Henrik Says:

    Thanks, very good written and useful (even for a Mac user). Mac note: Open the terminal and run VBoxManage clonevdi “old name.vdi” “copy name.vdi”. You don’t need to change directory if you use the default location for your virtual harddisks.

  90. Christian Palm Says:

    Thanks for info… I keep going back to this post every time I need to clone a VirtualBox image

  91. Jonathan Lister Says:

    Thanks, that was really helpful! By the way, for Mac OS X, the path the VDI files is /Users//Library/VirtualBox/HardDisks/

  92. Michael Gebis Says:

    Thanks for the tutorial! It was a big help.

    I had one minor issue, and I’ll note it here just in case it helps someone else. For some weird reason when I typed this command…

    C:\Documents and Settings\srackham\.VirtualBox\VDI> “C:\Program
    Files\Sun\xVM VirtualBox\VBoxManage.exe” clonevdi “XXXX.vdi”
    “XXXX clone.vdi”

    …I got an error: “Cannot register the hard disk XXXX with UUID YYYY because a hard disk XXXX with UUID YYYY already exists in the media registry blah blah blah…”

    However, based on some internet sleuthing, it seems that virtualbox may now require the full path to the .vdi files. When I used full paths, the error went away.

    • bakaneko Says:

      yes, I agree with you :)
      thank you for your comment here since i also have the same problem with you to clone the vdi.

  93. Jillian Says:

    Thank you! This is a great post. I just linked to it off my post on how I did it the hard way (it’s at http://bit.ly/7OZMT7). I spent a good two hours editing everything and figuring it all out. The Amazing thing is that it works! I agree that it would be better to just use the tools it comes with.

  94. Pierre-Antoine Champin Says:

    An alternative, since VirtualBox 2.2, is to export the VM to the OVF format, and reimport it. It takes some time and disk space, but at least you don’t have to lose your snapshots on the original VM.

  95. chris j Says:

    This was helpful, but I had one small problem at the end.

    I was cloning the hard drive of a windows box, so I wouldn’t have to spend countless hours patching. When I said to use the existing, the new drive wasn’t there. I had to use the Add button to add the drive.

    Version I’m using is 3.1.2 on Debian linux (non-ose).

  96. Mafat Laal Says:

    Hi Stuart,

    Thank you very much for providing such a detailed and comprehensible overview. This is extremely helpful. Much appreciated.

    Best regards,
    Mafat

  97. Robin Says:

    Thanks for the note .Very well written and very help full .As you have rightly pointed out the sun docs leave a lot to be desired but the product never the less is very good .

  98. Chris F Says:

    Thanks for this, I was also confused by the oddly used term ‘discard’.

  99. vinny Says:

    Hi,

    This is really to the point explaination and perfect.

    regards,
    Vinny

  100. big foot Says:

    Actually, the editing of the XML files is trivial. To create exact copy of a virtual machine, first create new VM using the GUI. Then find the newly created virtual machine, open the XML file, delete everything except the UUID (ie everything except the first 3 or so lines), then copy in the info from the XML file for the virtual machine you want to clone.

    Of course, clone the VDI image as described in the article, detach the original one in the new VM, and attach the cloned one….

  101. andy Says:

    Rad! Very handy, I especially like your descriptions of their use of “discard” I would not have anticipated them behaving that way. And hell I didn’t even realized the clonevdi command existed. Thanks.

  102. Negasuki Says:

    This page is exactly what I was looking for. Thank you for sharing the information. I believe things may have been changed a bit since this had been posted.
    After adding a path in the command prompt, when in the folder location “C:\Users\\.VirtualBox\HardDisk\” the comand that was needed to clone the hard drive on my system was:
    VBoxManage clonehd “.vdi” “.vdi”

  103. Ian Says:

    Top notch work! VirtualBox 3.1.6 on Ubuntu 9.10 now shows “discard” as “delete”, but it appears to do exactly the same as you describe.

    You are right, it really should say “Merge into previous snapshot” or something similar, as you are not deleting or discarding any data, just the ability to revert to the snapshot before the one you are about to “Delete”

  104. AnotherGuy Says:

    Negasuki has simplified it. Thanks.

    For Windows XP I simply created Clone.bat as follows. “C:\Program Files\Sun\VirtualBox\VBoxManage.exe” clonehd “OldPath\OldName.vdi” “NewPath\NewName.vdi” It works like a charm.

    Just add the new drive with File/Virtual Media Manager/Add and apply it to a new or existing machine.

    And the command “C:\Program Files\Sun\VirtualBox\VBoxManage.exe” internalcommands sethduuid “Path\CopiedFile.vdi” works on a copied and renamed HD files

  105. Brendan J. Says:

    Cheers mate, worked like a charm!

  106. sofazen Says:

    Thanks, definitely very useful and only found in this blog after navigate for hours !!

  107. Dreykk Says:

    Thanks Stuart, wish all other tuts had this accurate explanation.

  108. Graza Says:

    You do not actually need to do all the merges to clone the latest (or any) snapshot, as “VBoxManage clonehd” allows you to provide a snapshot identifier as an alternative to a VDI filename, and this merges all the changes up to the chosen snapshot into the output file.

    You need to get the snapshot id for the drive first, but this is not difficult.
    The following works from the VBox GUI, but there would also be a commandline way to do it:

    1. Select the VM, and click on “snapshots”

    2. Note the name/description of the snapshot you want to clone (if you want to clone “current state” you will need to snapshot this state first, and give it a name)

    3. Go to the “VirtualMediaManager” and expand the entire tree of the drive you want to clone

    4. Find the diff file relating to the snapshot you want to clone –> As you select each “child” or diff-file, the bottom of the window will display the full filepath/location, and also “Attached to: ()

    5. Once found, you are able to select and copy the location. It will be something like “.VirtualBox/Machines/MyVM/Snapshots/{297a42c0-236c-474b-af3c-6393b31518ef}.vdi”

    6. Paste the location into a text editor and remove everything except the ID of the diff file, eg “297a42c0-236c-474b-af3c-6393b31518ef” (note, no braces or “.vdi” – just the ID)

    7. You can then use this ID to clone the snapshot, using CLONEHD (not clonevdi), eg “VBoxManage clonehd 297a42c0-236c-474b-af3c-6393b31518ef /home/myClonedVHD.vdi”

    And that’s it – no need to merge all the snapshots – clonehd will do that for you for the new vdi, but leave the original chain/tree of snapshots untouched!

  109. Todman Says:

    Worked great, thanks a ton!

  110. yac Says:

    It seems that if the hard disks are in vbox default directory (like ~/.Virtualbox/HardDisk/ or someting) one can do just
    $ VBoxManage clonevdi src.vdi dst.vdi
    but if it is somewhere else, one needs to do
    $ VBoxManager clonevdi UUID dst.vdi
    otherwise it will result in message like:

    Details: code NS_ERROR_INVALID_ARG (0x80070057), component VirtualBox, interface IVirtualBox, callee nsISupports
    Context: “OpenHardDisk(Bstr(szFilenameAbs), AccessMode_ReadWrite, false, Bstr(“”), false, Bstr(“”), srcDisk.asOutParam())” at line 624 of file VBoxManageDisk.cpp

  111. Amos Says:

    Hello all,

    The post itself didn’t help me since I already found the way to clone in some docs, but user’s comments did – after getting the same “Cannot register the hard disk” error, i tried entering with full path and it worked! Thanks for that!

    But, now I see that this actually wasn’t what I was looking for – I needed a way to copy existing small VDI file to BIGGER VDI file.
    Thing was I first made a 4Gig disk, which became small very soon and I wanted to move the complete system that to larger virtual disk without reinstalling it from the beginning.

    Any ideas on that one?

  112. Paul Says:

    @Amos – as I see it, you have two options.

    The first would be to simply add a new disk to the VM, and not actually increase the disk size – like adding a “D Drive”, or you could also mount the new drive under a mountpoint so it appeared to be the same drive in terms of your folder structure.

    The second would be to create the new bigger VDI, and mount both the old and new VDIs with an Ubuntu LiveCD (or similar) and use

    cp -r /media/oldvm_mount_point/* /media/newvm_mount_point

    to copy the entire contents of the older drive to the new one. This is a little invoved – Windows may well fail to boot from the new drive, and if so, there are a few steps you need to take to get it working. I have a lengthy email with instructions on fixing the boot issues – I’ll quote a relevant section here, but if this isn’t enough to get you going, I’ll post it up on my blog:

    Quote:
    25) Shutdown the Win VM, and Reattach the drive to Ubuntu VM (note that if you took a snapshot, you may need to select the “differencing” disk, rather than the main VDI). Mount and edit boot.ini – do this with “sudo gedit /media//boot.ini” rather than VIM, as gedit respects the CRLF. Probably best to do a backup first as well. Also backup your changes to ubuntu desktop, in case you lose them due to “differencing” disks, and need to redo it. Shut down Ubuntu VM.

  113. Ganesh Says:

    Thanks Stuart

    I’m feeling lucky that I met with your article.
    Yesterday I switched from vmware to VirtualBox due to some issues with 64 bit ubuntu 10.04(Lucid). I was wondering how to clone my new installations, else it would have been a havoc for me to create a new network for every machines. And I thank God, I reached your article.

    Thanks dear again. Keep up with your spirits. :)

  114. Liz Says:

    This is a useful post, but my experience was rather different: perhaps I’m just being slow, though.

    Your instructions seem to indicate that one needs to delete snapshots starting with the newest and working `backwards’ in time. I found that this just had the effect of removing these snapshots as if I had never taken them. Instead I needed to merge forwards in time, until I reached the snapshot I wanted to clone as my base. I could then use clonehd to make a copy of this base .vdi file, which contained my chosen snapshot.

    Is this anyone else’s experience? What am I missing in the above instructions?!

    • Graza Says:

      Liz,

      See my reply dated May 8. You *do not need to merge any snapshots* to clone them if you use clonehd and the correct identifier for the snapshot that you want.

      It would be good if Stuart could put the info from my post into his main article to avoid all confusion. I too found his explanation to be invaluable, however I also found bits and pieces on other sites, and bringing them all together, worked out how to clone without merging, which I think for most people would be less confusing – not to mention the fact that some people may not want to merge (as you lose your snapshots).

      My point is, that it *is possible* to clone from any given snapshot without merging, and that it it not difficult. Stuart’s article gives the impression that this is not possible, and it would be great if he could rectify this, as obviously there are a lot of people who want/need this info. Yes, this is a complaint ;-) …. but I’ll reiterate that I still found this article invaluable, and must thank Stuart for it!

  115. guvnr Says:

    Most folks will just want:-

    VBoxManage clonehd ORIGINAL.vdi CLONE.vdi

  116. Rashid Iqbal Says:

    hi

    me take the snapshots at two different time/configuration intervals. now I want to revert back to 1st snapshot. but cannot revert.

    the revert back option dimms.

    Kindly help me to sort out this problem.

    Rashid

  117. bansi Says:

    After cloning the hard disk, I had to attach it using “Virtual media manager” to get the disk listed. I am Using OracleVM Version 3.2.8.r64453 on fedora 13

  118. Eric Y Says:

    Thanks you save me HOURS of time!!!!

  119. Alexandre Says:

    Hi!
    I’m starting a blog about technology in portuguese and I wanted to use/translate this content. I’ll put a link directing and refering to your site. Can I use it?
    Thanks in advance.
    Alexandre

  120. Shade Says:

    Well i found a different thing if you changed the serial of the real vdi then you can never delete it totally it is giving error.(If you prepare some snapshots)
    So it is better to open a new folder and copy the vdi there and change the copy vdi so u can not crash the real one and your vpc.

  121. franz Says:

    thank you very much Stuart.

    This article help me a lot and I’ve save a lot of my time.

    thanks again

  122. Shade Says:

    Well i wrote an app. for everyone to use it.I shared it for people to save time but it is not posted here writing “Your comment is awaiting moderation”.What is wrong it is not a spam or a virus or a keylogger or others.It is only opening cmd and get a copy of that file nothing more.
    Anyhow ty for the blog i used how to change it but people need some fresh
    and easy solutions never forget it byes.

  123. Macchu Says:

    Thanks, this walkthrough saved a lot of time!

  124. DaveB Says:

    Thanks for writing this guide. I couldn’t figure out why I could just copy a VDI! You just saved me another few hours of messing around with it!

  125. Darren Says:

    Thanks for the great article, I was able to clone my Machine.

  126. Mike Says:

    You sir, are a good man.
    This tutorial was SUCH a relief from the long-winded, angry forum threads that characterize much of the VirtualBox documation.

    Thank you.

  127. FranzKranz Says:

    Thanks, works perfectly

  128. andy Says:

    Awesome article, worked perfectly on Debian. Also, just FYI for anyone listening, the VDI directory in Debian is hidden by default at ~/.VirtualBox/VDI

  129. Hank Roberts Says:

    Any help on doing this with VirtualBox v4 welcome. I’m trying to follow their Help instructions.

  130. alex pilon Says:

    It is indeed simple. Thanks

  131. Blaise Kal Says:

    On a Mac, execute this command in Terminal (adjust paths to match your environment)

    /Applications/VirtualBox.app/Contents/MacOS/VBoxManage clonevdi /path/to/your/original.vdi /path/to/your/copied.vdi

  132. Dan Says:

    My PC came pre-loaded w/Vista. Since I was never given the install discs, how may I define Vista as the guest OS to Virtual Box without these discs?

    Thanks,
    Dan

  133. Anthony Ciliberto Says:

    This worked fine, no issues

  134. Jesse Says:

    Thanks.

  135. Rupy Says:

    Hi,

    I found this article very helpful! Thanks for posting.

  136. Headlight Converters Says:

    good article Stuart! Thanks to you I have been able to avoid wasting my times, the tuto works really fine!

  137. dan Says:

    Since Virtual Box requires an OS and my PC came with VISTA already preinstalled (so I do not own the MS original VISTA install disk) how do I tell Virtual Box that I am using Vista?

  138. just-saying Says:

    how hard is it to add a button for cloning :S

  139. Manoj Says:

    Hi,
    Great article.
    I have query that If I cloned the vdi file its again asking for Windows activation. I think because of changing UUID. Suppose If I copying the vdi file do I need to activate the Windows license?

  140. Paul Says:

    A good writeup on using the newer clonehd command is here:
    http://forums.virtualbox.org/viewtopic.php?f=1&t=791#p106206

    As others above said, this will allow you to clone a snapshotted HD image without first flattening it. The result will be flattened, but the original image is un-changed.

    Ex:
    +-Installed WinXP (snap1)
    +-Did some updates (snap2)
    +-Current State

    With VBoxManage clonehd you can clone snap2 or even “current state” and get NewImage.vdi, without having to merge and lose your snapshots in the original VM!

  141. Adam Says:

    Thanks alot for this guide, really helped me alot!

  142. Wim Says:

    Hi,

    with version 4.1.0 there is a CLONE button!!!
    I had to move the vdi’s from C: to D: because of the space I needed.
    – In File – Preferences I changed the Default Machine Folder to a folder on D:
    – within the GUI I selected a machine and pushed the clone button
    – after cloning all the machines I deleted the original ones.

    Very simple!

  143. antechno Says:

    nice blog..
    can you add my site to your blogroll….
    :)

  144. Stat Says:

    Hi, I tried using a cloned image but this came up
    E_INVALIDARG (0x80070057)
    and something with the UUID, what can I do to solve this problem
    Thanks.

  145. Aladdin Says:

    Excellent article Stuart. It’s very useful especially with the inline notes.

    Thanks

  146. Sk8nFool Says:

    Excellent write up.
    I’m using VB 4.1.2 and cloned a VM. I selected the Full option. The result was a new VDI without any dependency on any other VDI. Now I haven’t started this clone up yet bit this would imply that all the VDI’s got collapsed into a single disk including the base Multi-attach VDI.

    Other than the name changes doesn’t this reduce your procedure to a single step?

  147. Bosco Says:

    Thanks buddy.. good instructions.. tested and worked fine.

  148. Rico Chet Says:

    Thank you Stuart! Just found out that simply copying a VM — which works with VMware WS flawlessly — doesn’t work with VBox and even broke my development VM :(. Spent hours today repairing it, now it seems to work again. The UUID stuff is really restrictive :(.

  149. Can I just copy and rename a VirtualBox vm? Says:

    […] found a tutorial here describing the process. Answered by […]

  150. Lucas Potter Skyywalker Says:

    If you just want to MOVE your VMs to a different location, I found this topic very useful:

    https://forums.virtualbox.org/viewtopic.php?f=1&t=48258#p219285

    Just followed it and it’s working fine. All snapshots are preserved.

  151. Jessica Says:

    thanks this helped so much! be sure however, that you are already in the folder where your original .vdi is in the command prompt before you run the code.

  152. Bob Terwilliger Says:

    Cloning now seems to be natively built-in; for more info see http://www.techrepublic.com/blog/itdojo/clone-and-move-virtual-machines-in-virtualbox/3305

  153. byggegrunde sønderborg Says:

    Howdy! This post couldn’t be written any better! Reading this post reminds me of my previous room mate! He always kept chatting about this. I will forward this post to him. Fairly certain he will have a good read. Many thanks for sharing!

  154. whydoubt Says:

    Couldn’t find my Q thru search, but: Why do so many continue to ignore the reality regarding failures, in trying to create VMs using .vhd of Windows OS installed on a different physical machine? The majority use OEM installations that are locked to the original computer, and Msoft made it impossible to simply migrate to other units, as that subverts their licensing structure. You can generally only put a new install onto a VM, or create a VM onto its same original machine, either under the same, or another new OS; i.e. a Win 7/10 VM under Ubuntu, where the .vhd was taken from the Win7/10 running, saved/backed up elsewhere, then a clean Ubuntu was installed on that machine; finally, a new VM was built up from the image of the original drive, which should work fine as it is still seeing/seen as on the correct original hardware. This fundamental issue is so pervasive, it should be emblazoned in ALL CAPS at the top of every troubleshooting page devoted to fixing Virtual machine issues. And since XP there simply is no way to trick or bypass the integral anti-piracy code that rules over these failed VMs.

Leave a reply to Tony Chung Cancel reply