How To: Properly Backup a VirtualBox Machine (.VDI)

2007 November 18

First of all, these are the instructions for a VirtualBox installation on a Linux host.  It may or may not be the same directory structure/commands for Windows or Mac OS X hosts.

Most people don’t realize that making a backup of a VirtualBox Machine (.vdi) is more complex than just copy/paste. If you do that, you’ll soon realize (when it’s too late) that it doesn’t work! This is the proper way to backup your VirtualBox Machine:

VBoxManage clonevdi source destination

Example:
VBoxManage clonevdi ~/.VirtualBox/VDI/WindowsXP.vdi ~/WindowsXP_Backup.vdi

NOTE:  Although I’m not specifically sure, sometime after Version 2 of this software, the clonedvi command has been replaced with clonehd (see page 108 of the VirtualBox Manual), however, clonedvi will still work as they kept the backwards compatibility.

Then, wait for it to complete. It may take a while depending on the size of your .vdi file (or how much space you allocated towards your virtual machine).
What this actually does is create a new UUID (Universal Unique Identifier) for the cloned VM.  This way, you won’t end up with a message similar to this:

A hard disk with UUID {4d749826-6a3f-43ff-90af-42618783bd3a} or with the
same properties (’/home/martin/.VirtualBox/VDI/test.vdi’) is already
registered.

Feel free to buy me a soda if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that I hope you'll be interested in:


Here are some similar posts that you may be interested in:


52 Responses leave one →
  1. 2007 December 18
    maumac permalink

    It seems that the actual command is “VBoxManage” (without the final R).

  2. 2007 December 21

    Excellent, can you clone whilst a disk is in use?

  3. 2007 December 21
    sendderek permalink

    @Gareth:
    Good question. It’s too bad I don’t have a good answer for you. I could make something up, but that probably wouldn’t help out all that much.

    Give it a try and see what happens.

  4. 2008 January 1
    Neil permalink

    Thanks for posting this – it was very helpful.

  5. 2008 January 24
    Anthony A. permalink

    I just tried to clone a .vdi while it was in use, VBoxManage gives this error:

    [!] FAILED calling virtualBox->OpenVirtualDiskImage(Bstr(argv[0]), vdi.asOutParam()) at line 2415!
    [!] Primary RC = 0×80004005
    [!] Full error info present: true , basic error info present: true
    [!] Result Code = 0×80004005
    [!] Text = Could not access hard disk image ‘/home/anthony/.VirtualBox/VDI/Windows_XP_20GB.vdi’ (VERR_FILE_LOCK_VIOLATION)
    [!] Component = HardDisk, Interface: IHardDisk, {fd443ec1-000f-4f5b-9282-d72760a66916}
    [!] Callee = IVirtualBox, {76b25f3c-15d4-4785-a9d3-adc6a462beec}

    It worked just fine as soon as I powered down the virtual machine.

  6. 2008 February 14

    Hi there,

    I simply want to duplicate a VBox machine. Searching the net I’ve found out about the standard solution

    VBoxManage clonevdi Master.vdi Clone.vdi

    and the (undocumented) function

    cp Master.vdi Clone.vdi
    VBoxManage internalcommands setvdiuuid Clone.vdi

    which actually staffs the clone with a new SID in one step.

    My problem is much less complex: how the hell do I get to the command line of VBox in Windows XP? Is it the Windows command line or do I have to run VBox in a special mode first?!

    Thx for advice!

  7. 2008 February 19
    sendderek permalink

    I guess I’m not really sure what your question is…

    Do you have an XP host or guest?

  8. 2008 February 19

    Hi derek,

    it’s a WXP host and a WXP guest. And I want to clone the guest-VM.

    Thx in advance…

  9. 2008 February 22

    In WinXP, you just need to open a command prompt, cd to the c:\program files\innotek directory and launch the VBoxManage command from there. You could also add the innotek prog files directory to your path if you wanted to run the VBoxManage from any directory.

  10. 2008 February 22
    sendderek permalink

    Thanks Chief. I had no idea…

  11. 2008 February 27
    Avi permalink

    Thanks alot for the heads up!
    makes the process of sysprepping a VM with this wonderfull application a breeze!

  12. 2008 April 11

    “Most people don’t realize that making a backup of a VirtualBox Machine (.vdi) is more complex than just copy/paste. If you do that, you’ll soon realize (when it’s too late) that it doesn’t work!”

    Actually it does. Or at least it does for me (I didn’t know any better until I read here). On xp I just had to create a new machine using the same settings (probably the OS type is critical, not sure about the rest), and attach the copied vdi for its hdd. On linux it’s a little more complicated — you have to chmod the copied vdi.

    Still haven’t figured out how to ‘flatten’ the snapshots so you get the latest version of your vdi though (and vboxmanage doesn’t do that either, AFAICT). I tried clonevdi with the uuid of the most recent snapshot, but vbm rejected that approach.

  13. 2008 June 28
    Hans Linkels permalink

    I am experimenting too with backup of a live VBox VM. I know about the SID. But as David S pointed out, if you first delete the existing VM and create a new one pointing to the copied VDI, it will work. That is not the problem.

    However, when I did a test, I advertently wrote to the disk of the VM while I was copying. That DID trash my copy, and this time it was not possible to start the copied VM.

    It is logical that errors occur while copying a VDI that is written to, yet there seems to be quite some uncertainty about whether or not you can you cp to copy a VDI file.
    I tried the clonevdi command as well, but this does requier the stopping of the VM, and that for many minutes while cloning a multi-GB file. That is not acceptable on a server.

    Are there other experiences with copying a live machine?
    I was using W2k guest on a Linux Debian Lenny host.

  14. 2008 July 8
    j. rose permalink

    test: clone vdi

  15. 2008 October 3
    david permalink

    I have the following problem: I’d like to backup an “intermediate” VirtualBox snapshot (i.e. there are other snapshots before and after the snapshot tree). The various information I was able to get my hands on was very confusing.
    First of all: is it possible to back up a _snapshot_ at all? How would I go about to solve my problem? Any ideas?
    Thanks!

  16. 2008 October 10
    Akshat permalink

    Cheers! thanks!

  17. 2008 October 23

    It works fine. But…

    If you have .vdi file in a different directory you have to specified the complete path. And…

    If this directory has spaces in name you have to use double cote (“).

    E.G.

    vboxmanage clonevdi “C:\Virtual Machines\ubuntu.vdi” “C:\Virtual Machines\ubuntu_clone.vdi”

  18. 2008 October 27
    Dan permalink

    try a bat file in the folder where your vdi file is called someting like “clone.bat” with the contents being Start Quote:

    ECHO off

    SET original_name=”win2k.base.vdi”
    SET copy_name=”w2k.1st.vdi”

    SET vboxPath=”C:\Program Files\Sun\xVM VirtualBox\VBoxManage.exe”
    SET options=”clonevdi”

    ECHO on

    %vboxPath% %options% %original_name% %copy_name%

    (PAUSE)

    :End quote. Good luck

  19. 2008 December 15

    I have yet to discover a way to move/copy VM snapshot files from their original host directory to a destination host directory.

    I’m in the situation where my host drive (C:) is nearly full because the VB snapshot files are so big!

    I’d like to move the VB snapshot files off of the host drive (C:) and copy them to an external host drive (E: – 500GB), but VB provides the user/developer with no way to complete the task! Crazy!

  20. 2008 December 18
    Jason permalink

    I have Vista host and XP guest. I cloned a VDI file and only base OS copied to new VDI. All SPs of XP and applications installed on source VDI does not exist in the new VDI. The command used is: xboxmanage clonevdi old.vdi new.vdi. Anything I missed?

    Thanks for your help.

  21. 2009 January 13
    mashcaster permalink

    This does not work, when restored the VDI, it is unable to connected to the internet. So to call this guide “How To: Properly Backup a VirtualBox Machine” is miss leading, as the “Proper” would would not need to be modified once restored.

    • 2009 January 13

      Well, this article is a bit outdated. It seems that the “clonedvi” command has been replaced with the “clonehd”. Refer to the manual for what this actually does and why it’s the ‘proper’ way of doing it:
      http://dlc-cdn-rd.sun.com/c1/virtualbox/2.1.0/UserManual.pdf

      Using the command “clonedvi” still works, but it actually calls on the “clonehd” command.

  22. 2009 January 16

    Sun seems to have moved the vbox 2.1 UserManual.pdf to here:
    http://dlc.sun.com/virtualbox/2.1.0/UserManual.pdf

  23. 2009 February 14
    Vjeko permalink

    Plain copy/paste works just fine for me. Can you explain what are the drawbacks of this method?

    • 2009 February 15

      Using this method, you get a new UUID. The last time I attempted a copy/paste (at the original posting date) it ended badly. Also, it was with a Win XP VM which has some extra baggage to it (licensing, etc). Here’s a person who had the exact same experience as me:

      I have tried a simple file copy and then importing the vdi file into
      VirtualBox using the Virtual Disk Manager. This gives the following
      error:

      A hard disk with UUID {4d749826-6a3f-43ff-90af-42618783bd3a} or with the
      same properties (‘/home/martin/.VirtualBox/VDI/test.vdi’) is already
      registered.

      I assume that the clonevdi command in VBoxManage copies the file and
      gives it a new UUID.

      http://vbox.innotek.de/pipermail/vbox-users/2007-August/001914.html

  24. 2009 February 15
    Chaz permalink

    I have VirtualBox 2.1.2 installed.
    This blog must be severely outdated.
    There are no VDI files and no Innotek folder

    • 2009 February 15

      Well, it is outdated a bit, but not severely outdated. I know that the command has been updated to “clonehd” instead of “clonevdi”, but clonevdi will still work because they kept it backwards compatible. The directory structure may depend on what OS your host machine is running. This guide was written for a Linux host, it may be different for Windows and Mac OS.

  25. 2009 April 7
    Keith permalink

    This simply doesn’t work

    You either get
    [!] FAILED calling virtualBox->OpenVirtualDiskImage(Bstr(argv[0]), vdi.asOutParam()) at line 2415!
    [!] Primary RC = 0×80004005
    [!] Full error info present: true , basic error info present: true
    [!] Result Code = 0×80004005
    [!] Text = Could not access hard disk image ‘/home/anthony/.VirtualBox/VDI/Windows_XP_20GB.vdi’ (VERR_FILE_LOCK_VIOLATION)
    [!] Component = HardDisk, Interface: IHardDisk, {fd443ec1-000f-4f5b-9282-d72760a66916}
    [!] Callee = IVirtualBox, {76b25f3c-15d4-4785-a9d3-adc6a462beec}

    or

    Usage:
    VBoxManage clonevdi |
    Syntax error: Incorrect number of parameters

    Obviously missing something here. I have searched all over the net and they give the exact same syntax each time.

    VBoxManage clonevdi sounce dest
    At this point it will be faster to reinstall a VM.

    • 2009 April 11

      Well, this line looks like the most informative:

      [!] Text = Could not access hard disk image ‘/home/anthony/.VirtualBox/VDI/Windows_XP_20GB.vdi’ (VERR_FILE_LOCK_VIOLATION)

      Seems like the file has some whacked out permissions? Maybe this command needs to be ran as “su”. Try that, and if that doesn’t work, go all out “chmod 777″ on it. If that doesn’t work, I wonder if the machine was shutdown improperly or something else within VirtualBox is locking it. Here’s a description that is a tiny bit better: VirtualBox Source Archive

  26. 2009 April 24

    Hey, I have found a guide for VirtualBox 2 and I think it might be interesting for someone. :)

    How to copy and transfer a Virtualbox Virtual Machine .vdi

    • 2009 April 25

      And this guide isn’t interesting? ;-) j/k

      Thanks for the extra link.

  27. 2009 April 25

    Of course it’s interesting. I didn’t mean it this way. No offence. :)

    • 2009 April 26

      Haha! No worries. I was just kidding around. I really do appreciate any insight or extra information.

  28. 2009 April 26

    OK, waitasec here. I have had zero problems cloning my WinXP guest images between Linux hosts.

    All I do is grab /home/username/.VirtualBox – drag and drop, works every time. I’ve migrated images built under Ubuntu to Fedora, I’ve passed them beween 32bit and 64bit hosts, zero problems, continuously since the VirtualBox 1.4x series right through to 2.2.

    Now again, that’s NOT trying to migrate from a Linux host to, say, MacOS or a Windows host. That’s almost certainly different.

    What’s the problem?

  29. 2009 May 3
    koshari permalink

    jim March said

    “I have had zero problems cloning my WinXP guest images between Linux hosts.
    All I do is grab /home/username/.VirtualBox – drag and drop, works every time. I’ve migrated images built under Ubuntu to Fedora, I’ve passed them beween 32bit and 64bit hosts, zero problems, continuously since the VirtualBox 1.4x series right through to 2.2.
    What’s the problem?”

    are you moving the images onto new partitions with uuids?

  30. 2009 May 20
    Joakim K permalink

    In order to clone a snapshot you need to specify the UUID of the snapshot as the first parameter for clonehd and then the target vdi file as second.

    VBoxManage clonehd 18d20cbe-aba7-4038-9876-f1255ab47e27 x:\VirtualBox\HardDisks\XPHomeSP3-IE6.vdi

    The UUID of the snapshot can be found if you open the Virtual Media Manager and expand the tree under the disk with the snapshot. Find the correct snapshot by looking for the disk with the correct name next to “attached to”. The UUID of the snapshot is the one between the { }.

  31. 2009 July 7

    Hi there,

    I get this problem “a hard disk ‘…’ with UUID {93….a2} already exists in the media registry

    $ VBoxManage –version
    3.0.0r49315

    $ VBoxManage clonevdi .VirtualBox/HardDisks/input.vdi /tmp/output.vdi
    VirtualBox Command Line Management Interface Version 3.0.0
    (C) 2005-2009 Sun Microsystems, Inc.
    All rights reserved.

    ERROR: Cannot register the hard disk ‘/tmp/output.vdi’ with UUID {9341458c-d50a-4f84-81b8-6d1ee44823a2} because a hard disk ‘.VirtualBox/HardDisks/input.vdi’ with UUID {9341458c-d50a-4f84-81b8-6d1ee44823a2} already exists in the media registry (‘.VirtualBox/VirtualBox.xml’)
    Details: code NS_ERROR_INVALID_ARG (0×80070057), 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

    I really don’t understand why this has turned out so unreliable.

    Maybe I’ll use rsync instead.

    Stephan

  32. 2009 July 7

    I see the explanations at

    http://www.my-guides.net/en/content/view/155/26/

    now — they say to “release” the hard drive before cloning.

    Looks like some strange design to me. Surely a physical hardware can be popped in and out without UUID registration problems?

    Stephan

  33. 2009 July 27
    Harish permalink

    Hi Stephan,

    You can fix this error by using the following command on your terminal.

    VBoxManage internalcommands setvdiuuid /path/to/virtualdisk.vdi

    On your terminal, it would look something like this.
    ————————————————————
    harish@harish-laptop:~$ VBoxManage internalcommands setvdiuuid /path/to/virtualdisk.vdi
    VirtualBox Command Line Management Interface Version 2.2.2
    (C) 2005-2009 Sun Microsystems, Inc.
    All rights reserved.

    UUID changed to: 9e89fe14-d010-469e-a737-cd65218c4acb
    ————————————————————

    Hope this helps.

    Cheers,
    Harish

  34. 2009 July 27
    Harish permalink

    P.S: Make sure you release the vdi image this time before you use the command that I mentioned above.

    Cheers,
    Harish

  35. 2009 August 5
    stupid setup permalink

    why aren’t the xml and other settings stored where you choose to save your .vdi image! .. ended up backing up the .vdi images.. not knowing some retard decided that storing extra file details etc in a completely different location would then still be required to get the .vdi image working properly again within virtualbox..

    who designs stuff like that!.. oh and to export out as a backup.. into a different format.. great so just waste some hdd space when I could easily just use the existing .vdi images..

    anyway screw it just changed the uid numbers of a new vm setup and my old vdi images worked.

  36. 2009 October 10

    Seems to me you’ve got bigger problems than UUID collisions (a fixable problem) if you are doing things this way: any potential incrementalism in your backup system is probably lost because a .VDI is one big file… right?

  37. 2009 November 9
    PCNetSpec permalink

    Is it posible to automate the restore of a .vdi, overwriting the current one thus putting the VM back to the state it was in previously?

    To clarify…once a week I want a linux system to automatically restore an XP .vdi…overwriting the existing one, without user intervention.

    Possible?

    Many thanks in advance.

    • 2009 November 9

      It is possible. I don’t know exactly off the top of my head.

      You’ll want to take a look into setting up a script to run the proper VDI backup command and then throw a cron job together to run that script for you. You can choose if you want to do this everyday, once a week, or whenever.

  38. 2009 December 22
    Thomas permalink

    “Most people don’t realize that making a backup of a VirtualBox Machine (.vdi) is more complex than just copy/paste.”

    And still many people don’t realize, that a VirtualBox Machine is not the same as a Virtual Disk Image (VDI), though in some cases it might give you the desired result when making a copy of a VDI. But it does not give you a full clone of the VM you want to copy but only a copy of the VDI, because a VM also has a history of snapshots and it’s virtual machine settings.

    So the title is totally misleading.

Trackbacks & Pingbacks

  1. How To: Install VirtualBox on Fedora 8 (Werewolf) « SendDerek’s Blog
  2. Simkin’s Musings » Blog Archive » VirtualBox Rides again
  3. Daily Digest for 2009-01-22 | Pedro Trindade
  4. How To: Properly Backup a VirtualBox Machine (.VDI) « 我
  5. Cloner facilement un disque VirtualBox
  6. How To: Install VirtualBox on Fedora 11 [Tutorial] | Derek Hildreth's Blog
  7. How To: Install VirtualBox 3 on Fedora 12 [Tutorial] | Derek Hildreth's Blog