18
Nov

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

Update on 27 July 2011:

The VM cloning tool is now built into the GUI as of VirtualBox 4.1. See the changelog:

VirtualBox 4.1.0 (released 2011-07-19)

This version is a major update. The following major new features were added:

    Support for cloning of VMs (bug #5853, see the manual for more information): full clones can be created through the GUI and VBoxManage, linked clones only through VBoxManage
    GUI: enhanced wizard for creating new virtual disks
    GUI: new wizard for copying virtual disks
    ...

Original Post:

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 donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:


There's 66 Comments So Far

  • maumac
    December 18th, 2007 at 12:12 pm

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

  • Gareth
    December 21st, 2007 at 12:32 pm

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

  • sendderek
    December 21st, 2007 at 11:45 pm

    @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.

  • Neil
    January 1st, 2008 at 7:46 am

    Thanks for posting this – it was very helpful.

  • Anthony A.
    January 24th, 2008 at 3:53 am

    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 = 0x80004005
    [!] Full error info present: true , basic error info present: true
    [!] Result Code = 0x80004005
    [!] 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.

  • Media Addicted
    February 14th, 2008 at 6:34 pm

    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!

  • sendderek
    February 19th, 2008 at 10:49 am

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

    Do you have an XP host or guest?

  • Media Addicted
    February 19th, 2008 at 1:31 pm

    Hi derek,

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

    Thx in advance…

  • BigFunkyChief
    February 22nd, 2008 at 1:00 am

    In WinXP, you just need to open a command prompt, cd to the c:program filesinnotek 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.

  • sendderek
    February 22nd, 2008 at 10:07 am

    Thanks Chief. I had no idea…

  • Avi
    February 27th, 2008 at 2:06 pm

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

  • David S
    April 11th, 2008 at 8:31 pm

    “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.

  • Hans Linkels
    June 28th, 2008 at 8:20 am

    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.

  • j. rose
    July 8th, 2008 at 6:15 am

    test: clone vdi

  • david
    October 3rd, 2008 at 9:55 am

    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!

  • Akshat
    October 10th, 2008 at 12:13 am

    Cheers! thanks!

  • Fernando
    October 23rd, 2008 at 8:32 am

    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 Machinesubuntu.vdi” “C:Virtual Machinesubuntu_clone.vdi”

  • Dan
    October 27th, 2008 at 4:43 am

    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 FilesSunxVM VirtualBoxVBoxManage.exe”
    SET options=”clonevdi”

    ECHO on

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

    (PAUSE)

    :End quote. Good luck

  • Paul
    December 15th, 2008 at 4:26 pm

    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!

  • Jason
    December 18th, 2008 at 7:40 pm

    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.

  • mashcaster
    January 13th, 2009 at 5:12 am

    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.

  • SendDerek
    January 13th, 2009 at 10:49 am

    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.

  • quixote
    January 16th, 2009 at 8:51 pm

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

  • Vjeko
    February 14th, 2009 at 12:57 pm

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

  • SendDerek
    February 15th, 2009 at 11:06 am

    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

  • Chaz
    February 15th, 2009 at 10:11 am

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

  • SendDerek
    February 15th, 2009 at 11:21 am

    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.

  • Keith
    April 7th, 2009 at 11:58 pm

    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.

  • SendDerek
    April 11th, 2009 at 11:03 pm

    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

  • axel
    April 24th, 2009 at 11:38 am

    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

  • SendDerek
    April 25th, 2009 at 9:05 am

    And this guide isn’t interesting? 😉 j/k

    Thanks for the extra link.

  • axel
    April 25th, 2009 at 4:15 pm

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

  • SendDerek
    April 26th, 2009 at 10:33 am

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

  • Jim March
    April 26th, 2009 at 3:54 pm

    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?

  • koshari
    May 3rd, 2009 at 11:51 pm

    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?

  • Joakim K
    May 20th, 2009 at 8:30 am

    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:VirtualBoxHardDisksXPHomeSP3-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 { }.

  • Stephan Wehner
    July 7th, 2009 at 7:54 pm

    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 (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

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

    Maybe I’ll use rsync instead.

    Stephan

  • Stephan Wehner
    July 7th, 2009 at 7:57 pm

    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

  • Harish
    July 27th, 2009 at 8:52 am

    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.
    ————————————————————
    [email protected]:~$ 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

  • Harish
    July 27th, 2009 at 8:54 am

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

    Cheers,
    Harish

  • stupid setup
    August 5th, 2009 at 1:28 pm

    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.

  • Dave Abrahams
    October 10th, 2009 at 2:29 pm

    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?

  • PCNetSpec
    November 9th, 2009 at 7:20 am

    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.

  • SendDerek
    November 9th, 2009 at 8:33 am

    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.

  • Thomas
    December 22nd, 2009 at 4:33 am

    “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.

  • John
    June 3rd, 2010 at 2:04 am

    Hi,

    Using a UUID in Virtual Box is a complete stuff up and cloning or changing UUID on windows disks doesn’t work properly. The UUID is a Linux requirement because it doesnt use disk identifiers A B C like windows and uses UUID instead

    To start when a vdi with windows is cloned it requires initiallising again – waste of time for virtual machines you soon run out of activation attempts and Microsoft wont be very helpfull.

    If you simply copy a vdi disk it will work fine you just cant load both disks to the virtual file manager at same time but at least the copied disks work.

  • Jeff
    August 4th, 2010 at 12:09 pm

    Can someone show me in the manual where the VM has to be released before clonehd? I don’t see it in there and have never had a problem cloning attached VMs…although on the surface it seems to make sense.

  • Bob
    October 13th, 2010 at 2:16 pm

    Isn’t this what export appliance is for?

  • Shiki
    March 31st, 2011 at 2:45 am

    This worked nicely. Thanks for the quick and easy post!

  • wieb
    May 17th, 2011 at 1:29 am

    In windows you can just copy the vdi, and create a new machine and select the vdi during the process of the wizard.

  • Kelly
    June 13th, 2011 at 12:31 pm

    So even if I have all these files below, plus my vdi file (I unfortunately just cut and pasted all these…!), is there NO way to restore these files in a new VM??? There’s no recovery program or anything I can do???

    Thank you!
    Kelly

    These are the files that I copied and pasted before reinstalling the VM, thinking I was covered since I had them all copied:

    VirtualBox original
    compreg.dat
    HardDisks
    Machines
    Vista on my Mac
    Logs
    VBox.log
    VBox.log.1
    VBox.log.2
    VBox.log.3
    Snapshots
    Vista on my Mac.xml
    Vista on my Mac.xml-prev

  • [email protected]
    June 16th, 2011 at 8:34 am

    The file that contains the actual virtual machine has a .vdi extension. I don’t see that in your list, so I would search for that and copy it before removing anything.

    Some folks have had success in a simple copy/paste of this file, but my experience was different (couldn’t startup the VM). When I read that there were proper steps to backing up a VM, I made this blog post about it so I wouldn’t forget.

  • Bill
    May 17th, 2015 at 1:26 pm

    I’ve successfully backed up VirtualBox using rsync and have rsync’d the backups to the primary directory and able to open them without issue, works great if the primary crashes need to overwrite unwanted material – Linux Host pc

  • AntonioFR
    November 22nd, 2015 at 8:24 am

    I do backups with this method:

    http://www.michublog.com/informatica/script-batch-para-crear-copias-de-seguridad-de-maquinas-virtuales-de-virtualbox-desde-windows

    I hope it works to you!

Who Linked To This Post?

  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
  8. How To: Install VirtualBox on Fedora 10 [Tutorial] | Derek Hildreth's Blog
  9. Need to take backup of Virtual Machine
  10. Hard drive failure is imminent! How do I back everything up, including what repos/packages, etc?
  11. Virtualization with VirtualBox (running Windows inside Linux)
  12. Ryan, Debi, and Toren Cragun's Blog » Ubuntu Fresh Install

Share your thoughts, leave a comment!