How to move VirtualBox files?

166

67

By default VirtualBox stores all data in a directory below the home directory. I know how to change it but how can I change the location of existing images (without editing VirtualBox.xml manually)?

I'm working on Windows and don't want to try using any NTFS links.

maaartinus

Posted 2011-03-11T10:53:11.827

Reputation: 3 054

Why don't you want to edit your VirtualBox.xml manually? I think it is by far the easiest option. – hugo der hungrige – 2014-10-01T19:32:05.883

@hugoderhungrige No idea, it's too long ago. I guess, I mis-edited it once, you know once bitten, twice shy... – maaartinus – 2014-10-01T19:40:13.043

@maaartinus still interesting today though :) – hugo der hungrige – 2014-10-02T09:30:58.533

4Awww, I was going to suggest symlinks (they solve Everything™), but you've blocked that idea... :( – DMA57361 – 2011-03-11T11:03:57.113

2I don't trust links on Windows at all. While NTFS is capable of it, Windows XP knows nothing about it and there are enough problems with it already. I may be needlessly coward... – maaartinus – 2011-03-11T11:25:25.793

Ah, yeah, I wouldn't touch them on XP. But support on 7 is pretty solid - you still have to build them from the cmd line, but that's not really much of a chore. I'm not sure about Vista... – DMA57361 – 2011-03-11T11:32:27.383

It's even worse, XP version of NTFS does support hardlinks, but these cannot span volumes. Obviously, I wanted to move the data to a different partition.

– maaartinus – 2011-03-11T12:13:15.270

Hardlinks can't ever span volumes, only symlinks can (and can be used for this sort of thing, my user folders are all symlinked to my second HDD, for example). But, personally I'd still avoid hardlinks in XP (even if they were an option). – DMA57361 – 2011-03-11T12:16:30.367

Answers

138

If you mean to MOVE all your VM to an entirely new location, you should just follow these 2 replies:

Copying the post here:

  1. Shut down VirtualBox, back up your .VirtualBox\VirtualBox.xml file.
  2. Find your existing "Virtualbox VMs" folder, and copy (not move) the whole folder with contents to your new drive E:
  3. Run VirtualBox, then for each VM in turn:

    3.1 Right click the VM name and select "Remove" from the popup menu. Answer no to the "physically delete files?" question.

    3.1b after removing a VM from the UI you have to close VirtualBox, and leave it closed for long enough for the background VBoxSVC task to time out and terminate also. Then you can start the VirtualBox app again and use Machine|Add to add back the VMs removed in the previous step.

    3.2 Select the Machine|Add.. menu item, navigate to the VMs new location on drive E:, and select the .vbox file.

    3.3. Repeat for any remaining VMs.

  4. In File|Preferences, set the default machine path to "E:\VirtualBox VMs"
  5. Test each of the VMs. Only after you are sure they all work, delete the old VM containing folder, i.e. delete "C:\VirtualBox VMs".

Lucas Pottersky

Posted 2011-03-11T10:53:11.827

Reputation: 1 504

4For Mac OS X users, VirtualBox.xml is located at ~/Library/VirtualBox/VirtualBox.xml. The VMs are located in ~/VirtualBox VMs. – Siu Ching Pong -Asuka Kenji- – 2014-09-25T03:45:54.527

2

Virtual Box 4.3.0+ has solved the "Last Important Thing", I didn't even need to close it - instructions.

– PCaetano – 2014-12-16T18:16:22.783

Perhaps you could add the command line "version" too. 1) List existing VMs via VBoxManage list vms. 2) Next to the names of the VMs, inside curly brackets, their UUIDs are referenced. Copy the one of interest. Details about it, can be retrieved via VBoxManage showvminfo UUID. 3) Unregister the VM of interest via VBoxManage unregistervm UUID. 4) Move the directory of the VM of interest. 5) Finally, register the machine via VBoxManage register NameOfVM.vbox -- obviously, where NameOfVM is meant the actual name of the VMs .vbox file to be registered. – Nikos Alexandris – 2015-12-20T08:07:24.560

It will work even if the folder has been moved before unregistering! Simply retrieve and unregister the VMs UUID named after <inaccessible!>. Then, locate the .vbox file and register it. – Nikos Alexandris – 2015-12-20T08:09:10.100

@NikosAlexandris: care to turn your comment into an answer ? also, on my OS X 10.10 machine with VirtualBox 5.0.16, it's registervm, not register. – ssc – 2016-06-06T09:44:59.037

When I do this for linked-clone machine, they fail to start – Nam G VU – 2012-05-03T09:28:49.677

1This worked for me, though I also needed to update the paths to each HardDisk and snapshot image by editing the .VirtualBox\VirtualBox.xml file, and doing a find/replace. Also, I only moved the Machines and HardDisk folders, not all the files contained under .VirtualBox, since that's all the global configuration and logging and such. – Dave Andersen – 2012-07-23T22:38:36.333

59

I only had a couple of VMs, and I found that I could just change the default storage location for VirtualBox and then clone my VM's. The clones where created in the new location on the new HD where I wanted them. Everything intact, snapshots and no need to remap the location of the virtual HDs.

thomthom

Posted 2011-03-11T10:53:11.827

Reputation: 840

how do you do this??? – FlipFloop – 2017-01-06T20:58:21.333

This really should be the accepted answer – theV0ID – 2017-03-26T20:01:54.870

Could you post a list of steps followed? – sancho.s Reinstate Monica – 2018-04-05T06:13:13.723

1Warning: Clone doesn't produce a perfect copy and may trigger a need to update licenses for installed software as machine/disk ids change. Encountered this when moving an old copy of Quicken on a VM to a new disk. – MZB – 2019-01-26T15:36:18.857

3+1 I think this is the best method. VirtualBox moves everything for you in a tidy little bundle. – Dave Andersen – 2012-08-07T23:35:05.120

3this is the best way, no manual cfg editing required – Bojan Bjelic – 2013-03-07T23:01:19.420

36

The easiest method doesn't require removing your virtual machines and mucking up their settings.

  1. Copy your Virtualbox VMs folder to a new drive.

  2. Run the Virtual Box Machine Manager. Run the media Manager File -> Virtual Media Manager

    2a. Choose the VM to move storage for. Click the Release button and then the Remove button. On the next dialog, you can either remove or keep the virtual drive. Close the manager leaving you in your Virtualbox Machine Manager.

  3. Select the VM you just removed media for, click the Settings button, Click the Storage section. Add a controller for the media (SATA usually) and then add a hard drive and choose existing disk and select the VD at your new location.

  4. Repeat for each machine you're moving

Fire off your virtual machine at the new location to check. Next time you visit the Virtual Media Manager, hovering over the VM entry will show you where the VD is stored.

Make sure you change your snapshots folders to point to the new drive if you're using them. Each machine has a snapshot folder setting and the VM Manager has a Default Machine folder setting in File -> Settings that needs to be changed as well.

In addition I had to also modify path in xml file. After that it worked flawlessly.

NOTE: Things have changed a bit since this was written, see Rob's answer. It's extremely simple now.

Fiasco Labs

Posted 2011-03-11T10:53:11.827

Reputation: 6 368

2i think this is by far the easiest way of doing this. – Peter Perháč – 2016-10-04T20:18:39.313

19

MUCH, MUCH simpler. 1) move to new location 2) Right-click remove from virtualbox menu 3) Select 'add' from machine menu 4) Find the 8kb Blue icon that has a type of 'virtualbox machine definition' . Select it and it will add to your virtualbox list. double click virtual machine and it works.

Rob

Posted 2011-03-11T10:53:11.827

Reputation: 191

Even simpler than this is when you want to add the VMs back to VirtualBox, just click the *.vbox file in its folder. – Joel Mellon – 2015-09-04T17:28:21.850

2How things change in three years... Wish had been this easy back then. Added note to my answer for them to come see this one. – Fiasco Labs – 2015-11-20T03:36:36.763

1This should really be higher up. I fiddled around and couldn't make it work. Simply removing the "inaccessible" ones in the UI and then double-clicking the .vbox file re-added it using the new location. – wenbert – 2017-04-21T00:18:07.037

Does not work on Linux host. Getting this error: The VM session was closed before any attempt to power it on.

Result Code: NS_ERROR_FAILURE (0x80004005) Component: SessionMachine Interface: ISession {7844aa05-b02e-4cdd-a04f-ade4a762e6b7} – Max N – 2017-05-16T11:14:31.203

2The "remove" part of this mthod feels like a bad idea that will result in the loss of your settings but it doesn't. This method maintains all of your settings and is the easiest of all the methods I tried. It worked on a Windows 10 host with both Windows 7 and Windows Sever 2016 guests. – Night Owl – 2018-12-26T00:50:04.867

There is the same official documentation https://forums.virtualbox.org/viewtopic.php?f=35&t=55003

– Oleg Savelyev – 2019-02-25T14:10:33.603

13

On Mac, edit the paths in this file:

/Users/pleddy/Library//VirtualBox/VirtualBox.xml

That was easy, presto!

pcharlesleddy

Posted 2011-03-11T10:53:11.827

Reputation: 141

I am a mac user and google landed me here and this solution is the simplest of all, makes perfect sense and worked for me :) – Mohit Singh – 2017-10-28T09:26:52.850

I'm on linux, and liked the sound of this answer, but I was put off by the warning at the top of the file. Would you still recommend editing the XML directly? The warning says: ** DO NOT EDIT THIS FILE. If you make changes to this file while any VirtualBox related application is running, your changes will be overwritten later, without taking effect. Use VBoxManage or the VirtualBox Manager GUI to make changes. ** – craq – 2018-03-04T00:58:36.233

3He is using Windows, and he also doesn't want to edit VirtualBox.xml. – ChrisN – 2013-02-05T23:29:43.687

4This was helpful to me, though, since this question is still googlable if you're on mac. – NReilingh – 2013-11-22T07:54:58.943

11

After wasting a whole day on this problem (using Virtualbox 5.0.12 on Arch Linux), I finally got it solved in the way thomthom's answer suggests. For those who are unsure about the exact procedure, the command which clones an entire machine (including snapshots) is:

VBoxManage clonevm --mode all --basefolder </new/path/> --register <VM_to_clone>

Obtain the VM's name with

VBoxManage list vms

If necessary, quote path and name.

Finally, check if all is well and remove the original.

That's all, really. No need to bother with xml files or a hex editor. No need to use a GUI, either.

http://www.virtualbox.org/manual/ch08.html#vboxmanage-clonevm

Michael P

Posted 2011-03-11T10:53:11.827

Reputation: 311

This was the only answer that worked for me. Should be higher up. – Max N – 2017-05-16T15:16:07.613

2VM_to_clone is the UUID or name of the VM. With the given command (using a UUID), a directory was created at /new/path/_<UUID>_ Clone, and the containing files also used _<UUID>_ Clone as name. To explicitly have a nicer name, use the --name "Your preferred name here" flag. – Rob W – 2017-08-27T09:19:22.757

... and to remove the original VM through the CLI, VBoxManage unregistervm UUID (UUID of VM that you obtained through VBoxManage list vms, do not use the VM name because if you use --name to preserve the original name, then you have multiple VMs with the same name) – Rob W – 2017-08-27T09:27:49.143

Warning: Clone doesn't produce a perfect copy and may trigger a need to update licenses for installed software as machine/disk ids change. Encountered this when moving an old copy of Quicken on a VM to a new disk. – MZB – 2019-01-26T15:36:47.423

There appears to be a dedicated command now, anyway: http://www.virtualbox.org/manual/ch08.html#vboxmanage-movevm

– Michael P – 2019-03-22T07:01:59.977

5

To do the same as in Lucas Pottersky answer but through command line (on Windows replace vboxmanage with VBoxManage.exe):

  1. List all virtual machines:

    vboxmanage list vms
    

    or only running:

    vboxmanage list runningvms
    

    which for each machine outputs name and UUID.

    Do the following steps for each machine you will move.

  2. Gracefully shutdown it:

    vboxmanage controlvm UUID acpipowerbutton
    
  3. Unregister:

    vboxmanage unregistervm UUID
    
  4. Move virtual machine folder to the new location.

  5. Register it back by providing path to .vbox file:

    vboxmanage registervm /path/to/machine.vbox
    

mixel

Posted 2011-03-11T10:53:11.827

Reputation: 311

Assuming the files have already been moved, one can unregister all machines in one go with for v in `VBoxManage list vms | cut -c 19-54`; do VBoxManage unregistervm $v; done. Re-registering is not that straightfoward though, because the Media Manager is a bit of a mess. – Giacomo Lacava – 2019-10-22T17:37:03.427

2

This worked for me with the MacOS release of VirtualBox as well (release 4.1.12). I waited 5-10 seconds for VirtualBox to quit before re-launching. I looked in Activity Monitor to make sure VBoxSVC had quit properly.

If you don't do this, you will get an error that looks something like the following (I'm copying and pasting someone else's error message which comes from Windows). If you get this error, it's simply because you didn't quit VirtualBox or wait long enough for VBoxSVC to quit.

Failed to open virtual machine located in E:/<path>/<machine_name>/<machine_name>.vbox.

Cannot register the hard disk 'E:\<path>\<machine_name>\Snapshots/{0ece4bff-9185-4cff-9069-b3d1f4536394}.vdi' {0ece4bff-9185-4cff-9069-b3d1f4536394} 
because a hard disk 'C:\<path>\<machine_name>\Snapshots/{0ece4bff-9185-4cff-9069-b3d1f4536394}.vdi' with UUID {0ece4bff-9185-4cff-9069-b3d1f4536394} already exists.

Result Code: E_INVALIDARG (0x80070057)
Component: VirtualBox
Interface: IVirtualBox {c28be65f-1a8f-43b4-81f1-eb60cb516e66}

withfries2

Posted 2011-03-11T10:53:11.827

Reputation: 31

2

There is a default storage location in the settings under VirtualBox: http://mattvelic.com/default-vm-location/

Now dead. Wayback machine has the content:

http://web.archive.org/web/20131116130725/http://mattvelic.com/default-vm-location

...check out the Preferences in the File menu. Behold! The first item in the General tab is Default Machine Folder. http://web.archive.org/web/20131116130725im_/http://54.225.211.105/wp-content/uploads/2012/11/VB_Preferences.png I edited the location to point to my storage drive, and quickly remade my VM. This time VirtualBox created both the machine files and the VDI in the correct location. The real lesson here is that sometimes the solution need not be technical. I think that as IT professionals, we tend to think that answer to a problem will be complicated. Keep your eyes open for the obvious solutions!

Rebecca

Posted 2011-03-11T10:53:11.827

Reputation: 121

This link is now dead. Try not to post links as answers. When they go dead, SU is left with cruft to clean up. – mrtsherman – 2015-03-23T21:24:30.653

updated with content from archive.org – Rebecca – 2015-03-24T16:26:27.560

2

In OS X with VirtualBox v4.3.14, all I had to do was double-click the .vbox file from the new location, and it opened VirtualBox and added it to the list of available VMs.

Tyson Phalp

Posted 2011-03-11T10:53:11.827

Reputation: 121

Please don't add "thank you" as an answer. Instead, vote up the answers that you find helpful. – Scott – 2014-08-08T21:35:36.703

My answer isn't a 'thank you'. I edited the wording to make that more obvious. Thanks. – Tyson Phalp – 2014-08-08T22:45:52.983

1

I tried the original method (remove the VDI, attach the new copy), got the message that the old one still exists, and couldn't attach the new copy even when I restarted the OS (on Mac OS X El Capitan).

The fix was in menu / File / Virtual Media Manager, remove the existing VDI. This works even if there are snapshots; just remove all the snapshot VDIs in reverse order. No need to close and reopen VirtualBox.

marty39

Posted 2011-03-11T10:53:11.827

Reputation: 21

1

I do not think this is possible.

You can move the VDI to the new location, but I don't think you can avoid XML modification. As an alternative (but that is in fact the same as XML edition) would creating a new virtual machine with the GUI and choosing the moved image as disk would suit your needs?

M'vy

Posted 2011-03-11T10:53:11.827

Reputation: 3 540

1I had a second look at the xml and it's actually very simple. Creating a new machine is not good since I'd like to preserve my settings (I don't remember what I've change, it may be completely unimportant or not). – maaartinus – 2011-03-11T11:29:48.597

0

I use this method:

  1. From VirtualBox GUI, pick your VM and remove the attached HDD
  2. Copy the file (ie. vdi) to the new location
  3. Generate a new UUID for the .vdi in the new location with the command vboxmanage internalcommands sethduuid "my path to myhdd.vdi" 6912BF7F-13BB-4E70-A2CA-C92300FEC3DC

    (In the previous example use your own UUID, or dont add it at all: the command will autogenerate one. Also if you omit this step, when adding the .vdi from the new location you'll get an error that the UUID already exists).

  4. Now back to the VirtualBox GUI, pick your VM and in Setttings / Storage attach the HD (.vdi file) from its new location.

and done.

Fernando Gonzalez Sanchez

Posted 2011-03-11T10:53:11.827

Reputation: 141

0

I never used virtualbox on windows but on ubuntu you move the VDI and in virtualbox GUI you right click on the VM and use Configuration Menu -> storage where you can change the VDI localization to where you moved the file. Regarding the other machine files definition, you move them and in GUI you go to Preferences and change the position of default machines directory to the diretory you moved.

laurent

Posted 2011-03-11T10:53:11.827

Reputation: 4 166

-1

In Oracle VM VirtualBox (tested with version 6.0.4), simply shut down your VM --> right click the VM in the VirtualBox Manager --> click "Move ..."--> choose the new directory. That's it!

Silvio Jäger

Posted 2011-03-11T10:53:11.827

Reputation: 1

@Moreaki:  By the way, “legibility” (and “legible”) are spelled *without* a “D”. – Scott – 2019-02-04T04:36:23.130