How To Clone A Virtual Machine In VirtualBox
Moving, cloning and modifying Virtual Machines in VirtualBox and their associated Virtual Hard Disks has been no easy task. And to make matters worse, the steps are poorly documented at best.
In this step by steps guide, we’re going to clone a virtual machine using VirtualBox 3.2.10 r66523 running on Ubuntu 10.10 64bit host operation system.
Steps To Clone a Virtual Machine
Merge Snapshots
Merge all snapshots that we want to be included, delete the ones we don’t want. Unless we do this, we only get the base version and loose all changes contained in those snapshots.
Run VBoxManage
Using VBoxManage clonevdi to copy the virtual hard disk to a new VDI file. The basic syntax is: VBoxManage fullPathTooldVdiFile fullPathTonewVdiFile. We need to ensure that a hard disk with that name does not already exist, otherwise we’ll get errors.
VBoxManage clonevdi /data/VirtualMachines/Windows7.vdi /data/VirtualMachines/Windows7_clone.vdi
Add Disk To Virtual Media Manager
We’ll add the new created hard disk to the Virtual Media Manager. This step ensures that the hard disk has been properly cloned, has the proper permissions and that there are no conflicts with other disks and virtual machines. In VirtualBox, select File -> Virtual Media Manager -> Add and select the cloned file, in our case Windows7_clone.vdi. If there are no errors, we should now see the hard disk listed among the others and are ready to proceed with the new Virtual Machine.
Create new Virtual Machine
In VirtualBox, select Machine -> New and proceed with the steps to create a new Virtual Machine. At the point we we select a hard disk, click existing and select our new disk.
Start up the new Virtual Machine and change hostname in /etc/hostname and eventually the network configuration in /etc/network/interfaces.