183

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.

9
  • 4
    Awww, I was going to suggest symlinks (they solve Everything™), but you've blocked that idea... :(
    – DMA57361
    Mar 11, 2011 at 11:03
  • 2
    I 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
    Mar 11, 2011 at 11:25
  • 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
    Mar 11, 2011 at 11:32
  • 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
    Mar 11, 2011 at 12:13
  • 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
    Mar 11, 2011 at 12:16

16 Answers 16

148

(Edit: As of 6.0.4 there is now a built-in function to move a VM. See https://superuser.com/a/1401548/120738)

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

8
  • 2
    This 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. Jul 23, 2012 at 22:38
  • 5
    For Mac OS X users, VirtualBox.xml is located at ~/Library/VirtualBox/VirtualBox.xml. The VMs are located in ~/VirtualBox VMs. Sep 25, 2014 at 3:45
  • 4
    Virtual Box 4.3.0+ has solved the "Last Important Thing", I didn't even need to close it - instructions.
    – PCaetano
    Dec 16, 2014 at 18:16
  • 1
    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. Dec 20, 2015 at 8:07
  • 5
    Virtualbox now has an official "Move" option for VM's. Just shutdown your VM and right click it in the UI and select "Move"
    – Shadoninja
    Jun 4, 2020 at 22:30
61

(Edit: As of 6.0.4 there is now a built-in function to move a VM. See https://superuser.com/a/1401548/120738)

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.

9
  • 3
    +1 I think this is the best method. VirtualBox moves everything for you in a tidy little bundle. Aug 7, 2012 at 23:35
  • 3
    this is the best way, no manual cfg editing required Mar 7, 2013 at 23:01
  • how do you do this???
    – FlipFloop
    Jan 6, 2017 at 20:58
  • 1
    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
    Jan 26, 2019 at 15:36
  • 1
    @thomthom, There is already an answer that talks about the Move option but it only has 3 votes which means it is hidden under all of the older more complex answers.
    – AnthonyVO
    Nov 5, 2020 at 15:54
37

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.

2
  • 2
    i think this is by far the easiest way of doing this. Oct 4, 2016 at 20:18
  • I don't want to downvote but Virtualbox now has an official "Move" which renders all other answers obsolete. Just shut down your VM and right-click it in the UI and select "Move"
    – AnthonyVO
    Nov 2, 2020 at 16:44
26

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.

9
  • Even simpler than this is when you want to add the VMs back to VirtualBox, just click the *.vbox file in its folder. Sep 4, 2015 at 17:28
  • 3
    How things change in three years... Wish had been this easy back then. Added note to my answer for them to come see this one. Nov 20, 2015 at 3:36
  • 1
    This 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
    Apr 21, 2017 at 0:18
  • 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
    May 16, 2017 at 11:14
  • 3
    The "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
    Dec 26, 2018 at 0:50
14

On Mac, edit the paths in this file:

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

That was easy, presto!

4
  • 3
    He is using Windows, and he also doesn't want to edit VirtualBox.xml.
    – ChrisN
    Feb 5, 2013 at 23:29
  • 5
    This was helpful to me, though, since this question is still googlable if you're on mac.
    – NReilingh
    Nov 22, 2013 at 7:54
  • 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 :) Oct 28, 2017 at 9:26
  • 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
    Mar 4, 2018 at 0:58
11
+100

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

5
  • This was the only answer that worked for me. Should be higher up.
    – Max N
    May 16, 2017 at 15:16
  • 2
    VM_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
    Aug 27, 2017 at 9:19
  • ... 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
    Aug 27, 2017 at 9:27
  • 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
    Jan 26, 2019 at 15:36
  • There appears to be a dedicated command now, anyway: virtualbox.org/manual/ch08.html#vboxmanage-movevm
    – Michael P
    Mar 22, 2019 at 7:01
10

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!

3
  • @Moreaki:  By the way, “legibility” (and “legible”) are spelled without a “D”. Feb 4, 2019 at 4:36
  • 2
    This answer needs to bubble up to the top. This is 100% the correct and easiest way to do this now.
    – Shadoninja
    Jun 4, 2020 at 22:32
  • Only one drawback. The progress meter does not show any progress while an individual file is being copied. Kinda nasty when the files can be 100s of Gigs in size. Look at the disk activity in Taskmanager to validate that things are happening.
    – AnthonyVO
    Nov 14, 2020 at 0:31
8

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
    
1
  • 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. Oct 22, 2019 at 17:37
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}
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.

2
  • Please don't add "thank you" as an answer. Instead, vote up the answers that you find helpful. Aug 8, 2014 at 21:35
  • My answer isn't a 'thank you'. I edited the wording to make that more obvious. Thanks. Aug 8, 2014 at 22:45
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!

2
  • 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
    Mar 23, 2015 at 21:24
  • updated with content from archive.org
    – Rebecca
    Mar 24, 2015 at 16:26
2
  1. Close all instances of Oracle VM VirtualBox Manager
  2. Move VM folder to desired location (e.g. D:\vbox\8pro to E:\NAS\data\8pro)
  3. Open the file %USERPROFILE%\.VirtualBox\VirtualBox.xml in XML editor
  4. Find corresponding MachineEntry key and change the path to new one (e.g. change <MachineRegistry><MachineEntry uuid="{686ad360-b203-4fd6-bdd3-7d9ed6835e88}" src="D:\vbox\8pro\8pro.vbox"/> to <MachineRegistry><MachineEntry uuid="{686ad360-b203-4fd6-bdd3-7d9ed6835e88}" src="E:\NAS\data\8pro\8pro.vbox"/>
  5. Start the Oracle VM VirtualBox Manager
  6. No any additional modification required, nor in xml files nor in Oracle VM VirtualBox Manager

This will work with cascaded snapshots, multiple drives configuration even VM logs will be accessible. Tested on version 5.2.30r130521 (extension pack also installed)

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?

1
  • 1
    I 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
    Mar 11, 2011 at 11:29
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.

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.

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .