Page 1 of 1

Moving a VM

PostPosted: 8. Apr 2013, 18:47
by mpack
Just FYI before we start: The "File|Preferences|General|Default Machine Folder" setting only controls where new VMs will be created, i.e. if you create a new VM, or clone or import a VM then the new/copy VM will go there. This setting does NOT control where existing VMs are to be found, existing VMs can be located anywhere you like. This tutorial tells you how to move one.

Users might want to move a VM for any of several reasons. Perhaps you are running out of space on the original drive, perhaps you want to move the files so that a different user (or all users) can access them. Perhaps you have a new PC and you want to move all your VMs there. Perhaps you are backing up your VM or restoring from a backup. In VirtualBox v4.0.0 and later the folder structure changed so that all files belonging to a VM are stored in a single folder, the "VM folder", which makes it easy to move a VM whatever your reason might be.

VirtualBox v6.x and later

VirtualBox v6.x has made it easier still to move a registered VM around on a single host: just right click the VM in the manager and select "Move...". If for some reason the built in feature isn't suitable (e.g. the VM not registered), or if you want to move the VM to a different host then read on, as the v4 method still works...

VirtualBox v4.x and Later (a.k.a. Manual Method)

The basic procedure for moving VMs created by VirtualBox v4.x and later is to copy/move the VM folder (with contents) to your preferred location, then use the manager's Machine|Add menu item to register the .vbox file (found in the VM folder) from its new location.

Of course, if the copy is on the same host as the original VM then VirtualBox will object to your attempt to register the same UUID twice. You must remove the original VM from the manager before the copy can be added (*).

(*) There was a bug in VirtualBox versions prior to v4.3.0 in which the background VBoxSVC process retains a memory of media filenames and UUIDs even after the front end has apparantly removed them. If using an affected version then to work around this you must shut down VirtualBox entirely, wait several seconds or until VBoxSVC unloads, then you can run the GUI again. At this point you should be able to add the VM back without complaint.

If you want the original and the copy to be registered at the same time on the same host then you actually need to make a clone rather than a simple copy. To clone a VM you right click it in the GUI and select "Clone". [ VirtualBox v4.1.0 and later ].

If you are running on a Windows host then be wary of moving VMs to removable storage. Windows has a nasty habit of changing the drive letters of removable drives, which will invalidate the VM path stored when you used Machine|Add.

Re: Moving a VM

PostPosted: 8. Apr 2013, 19:05
by mpack
VirtualBox v3.x and earlier

If your VM control file is a .xml file, and you have difficulty identifying the VM folder, then you actually have a VM which was created by VirtualBox v3.x or even earlier. It is important to recognize that VirtualBox tries to be backwards compatible: when you update an existing VirtualBox program to v4.x or later it will continue using any legacy VMs which it finds, retaining the legacy settings xml file and folder structure.

The problem with the v3.x folder structure was that important information about a VM was scattered across multiple files, and entangled with similar data from other VMs. A list of registered media across all VMs was stored in the <userdoc>/.VirtualBox/VirtualBox.xml file. The VM's own settings were stored in <userdoc>/.VirtualBox/Machines/<VM name>.xml, the main VDI file was stored in the <userdoc>/.VirtualBox/HardDisks folder, and so on. And if your VM used snapshots... well, let's not dwell on nasty thoughts.

Suffice to say that moving a v3.x VM is something only an expert would undertake. However the good news is that upgrading the VM to a v4.x layout can be trivially easy. Just make sure you have VirtualBox v4.1.x or later installed, then use the Clone feature of the GUI to clone the old VM (right click on old VM, select "Clone"). If asked, tell it you want a full clone (not linked), current state only, keep the old MAC address (do not reset). The cloned VM will use the v4.x layout, and can be moved as described in the first post. In fact if you set the File | Preferences | General | Default Machine Folder field before you start, then the clone will be created in your preferred new location and you won't even have to move it.