VirtualBox is a cross-platform virtualization application. It installs on your existing computer (and operating system) and extends the capabilities of your existing computer so that it can run multiple operating systems (inside multiple virtual machines) at the same time.
I’m a huge fan of VirtualBox. I summarized it’s usefulness in one of my previous posts – VirtualBox And Virtualization: An Introduction.
VirtualBox allows us to copy a virtual machine from one host to another easily. You just copy the hard disk file (usually .vdi or .vhd) to the new host. Then you use the transferred hard disk file to start up a new virtual machine on the new host. That’s it!
However, I have found that if you use this method on a VM containing snapshots, you only get an old machine state of the original virtual machine. All saved snapshots are lost.
In this tutorial, I explain how to move a VirtualBox VM to a different host and still retain the snapshots on the original host. The technique involves cloning and may also be used to move virtual machines to an external hard disk.
Cloning A VirtualBox VM
Shut down the virtual machine you want to clone. A virtual machine in a saved or running state cannot be cloned.
To start the cloning process, right click the virtual machine and select “Clone”.
Alternatively, select the virtual machine you want to clone in the left pane of the VirtualBox main window. Click the Snapshots tab and then click the small sheep icon as shown in the image below. Notice that the selected VM contains quite a number of snapshots.
The wizard that opens will first ask you to enter a name for new machine. Enter your desired name and press “Next”. The name you choose must be unique. No other vm with that name should exist on the host machine.
On the next screen, you need to select the type of clone you want. Since we want to move our vm to a new host, select “Full clone”.
The final screen requires that you choose if you want only the current machine state or if you want to clone the snapshots too. We want the snapshots so choose the “Everything” option. In my experience, cloning with snapshots takes a significantly longer time.
Press “Clone” and the process begins.
Add A New VM Using The Clone
Now you need to copy the entire folder containing the cloned VM over to the new host. In my case, this folder is found in “C:\Users\Ehi Kioya\VirtualBox VMs”. The folder name will be the machine name you entered in Step 3 above. Make sure this folder contains a “VirtualBox Machine Definition” file (.vbox). Copy this folder to an external or shared drive and then copy it onto the new host (the location doesn’t matter).
Launch VirtualBox on the new host and press “Machine” on the menu. Select “Add” on the dropdown. A Windows explorer browser window will open. Browse to the folder you newly copied over and select the “VirtualBox Machine Definition” file within it. If your new host machine does not have any existing VMs, you should be fine. A new virtual machine containing all the snapshots from the original host will be created. That’s it. You’re done.
However, if your new host machine already has existing VMs, and assuming you always install “VirtualBox Guest Additions” accross all your VMs (which is very likely), then you should get an error like this:
We’ll fix this error in the next post.