184

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
  • 3,392
  • 8
  • 33
  • 42

16 Answers16

149

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

thomthom
  • 872
62

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

thomthom
  • 872
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.

Fiasco Labs
  • 6,864
27

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
  • 271
14

On Mac, edit the paths in this file:

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

That was easy, presto!

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
  • 311
11

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!

ikaerom
  • 836
9

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
  • 491
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)

bigS
  • 21
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

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
  • 121
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.

Jens Erat
  • 18,485
  • 14
  • 68
  • 80
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
  • 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
  • 3,950
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.

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
  • 4,448