PCs optimize

Clone and move virtual machines in VirtualBox

Jack Wallen describes cloning and moving virtual machines in VirtualBox. He tested this process going from Linux to Linux, Linux to Windows, and Windows to Linux hosts.

I'm a big fan of VirtualBox. The tool enables me to extend a machine beyond its normal capabilities, test operating systems without getting invasive with my host, and kick the tires on various software titles without installing them on my production machine. But sometimes I get a virtual machine up and running and want to copy it (to move it to another machine or to have a second instance to test); when that time comes, I don't want to completely re-install the operating system and get it to the state I need. In this situation, I clone the virtual machine.

When you clone a drive, you make an exact copy of the virtual machine that can be used on either the same host or moved to another VirtualBox host. The process of cloning and moving a virtual machine is now easy in VirtualBox. In fact, there are no more commands for cloning, as the process is built into the GUI. I'll walk through this process and then move the resulting clone to another machine for use.

What you need

  • VirtualBox installed (the host platform doesn't matter)
  • A running virtual machine
  • The ability to move the clone from one machine to another (shared drive, external drive, disk, etc.)

Cloning a virtual machine

Step 1: Close the virtual machine

You cannot pause the machine that is going to be cloned and then clone it -- the machine must be turned off.

Step 2: Start the cloning process Select the virtual machine you want to clone in the left pane of the VirtualBox main window. Click the Snapshots tab (Figure A) and then click the small sheep icon. Figure A

A Ubuntu 12.04 virtual machine with no snapshots taken.
The wizard that opens is a simple two-step process. The first step requires you to give the clone a name; you must give this clone a different name than the source virtual machine. By default, VirtualBox will append "clone" at the end of the name of the source virtual machine. You can keep this, and it should work fine. The second phase of the wizard asks the type of clone you want to create (Figure B). You will want to create a full clone, since our goal is to move this virtual machine to a new host. Figure B

Read carefully the difference between full and linked clones.
Step 3: Locate and move the clone

You will be looking for a .vdi file. The location of this file will depend upon the host platform. On my Linux host, the file will be found in ~/VirtualBox VMs. Within that directory, you will find sub-directories of all your virtual machines. Within the virtual machine directory in question, you will find the .vdi file of the cloned virtual machines -- that is, the file that must be moved to the new host. Copy that file to an external or shared drive and then copy it onto the new host (the location doesn't matter).

Step 4: Create a new virtual machine The process of creating the new virtual machine will be the same as if you were creating a standard virtual machine until you get to the Virtual Hard Disk creation screen (Figure C). You will select Use Existing Hard Disk, click the folder icon, navigate to the newly copied .vdi file, select the file in question, and then click Next. Figure C

I'm almost finished adding my clone to a new host.

Once the new virtual machine is created, that virtual machine should fire up as expected and regardless of platform (I have tested this going from Linux to Linux, Linux to Windows, and Windows to Linux hosts).

Summary

The ability to clone and move virtual machines in VirtualBox as easily as shown above makes this a great tool for anyone who needs to expand their world with virtual machines. Give this a try and see how far you extend the reach of your hosts and guests with VirtualBox.

More about VirtualBox on TechRepublic

About

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website getjackd.net.

5 comments
matworld2000
matworld2000

Easier is to just copy the *.VDI image (either way you need to copy the file to other location anyway) with any file manager like Windows Explorer then run the VBoxManage command to change the UUID. VBoxManage internalcommands sethduuid VMName.vdi

Bruce Epper
Bruce Epper

If you copy the entire folder that contains the clone into the VirtualBox VM directory on the destination machine, you don't need to create a new VM and point it at the associated .vdi since it also has the configuration settings for the VM in the .vbox file. Move the entire folder for your third step and fire up VirtualBox on the desintation machine. It will already see the new (cloned) VM in the folder and populate the list of available VMs appropriately.

opensourcepcs
opensourcepcs

I've been wanting to clone some virtual box images from one PC to another but didn't know if it could be done. Thank you.

gkiefferjfk2
gkiefferjfk2

ONE HUGE EXAMPLE.... You are running an OS and you run a VIRUS SCANNER... You update the virus scanner & there is a BUG that kills off you rebooting back up & you are left with going to see the computer tech... [Which actually did happen a few yrs ago with one virus software vendor's update] NOW using cloning with VIRTUAL MACHINE you could have 2 or more of them and update one and if there is a BUG you could just delete the messed up clone that you updated & with the BUG it messed up your new clone... THUS you deleter the clone & fire up one of the other clones you created BUT DID NOT UPDATE YET.... And maybe wait until there is a fix for the problem that when you update the bug messed up the OS... AND save yourself the big huge tech visit & shelling out hundreds of $$$ for a El-quick computer fix...

emitretsam
emitretsam

I have tested and rollbacked changes such as OS updates to a VM (Windows 7) and have used the VM Snapshot for this purpose. The advantage of this over cloning is that it is quicker to create/save, and you can load the Snapshot state before the changes. I have similarly used cloning to troubleshoot problems with a VM to see if it was somehow corrupted or start out with a clean slate. A disadvantage of the snapshot is that you have to manage different ones and clean them up over time by deleting or merging them and this may take as much time to do this as it would to create a clone. Both options are useful depending on what you are trying to do.