Cloning an existing virtual machine is not an obvious part of the VirtualBox user interface, even in version 4 of Virtualbox. You have three options as far as I can tell
1) Export an existing virtual machine and import as a new machine
2) Create a new virtual machine using a cloned hard drive file
3) Create a new virtual machine using a copied hard drive file with a changed unique identification number (not official supported)
Your new virtual machine hard drive will use the
.vmdk file format, but everything else should be the same.
I would be interested to know if there are any limitations / issues using a .vmdk file for a hard drive over the VirtualBox .vdi file format.
Outstanding question: How does this process handle snap-shots???
You can clone just the hard drive of an existing machine using the Virtualbox command line tool - VBoxManger clonehd. When you create a new virtual machine you can use the cloned hard drive as the hard drive for the new virtual machine, saving you a reinstall.
You cannot simply copy all the files of an existing as each machines hard drive uses a unique identification number. The identification number is spread through the virtualbox machines xml configuration files, so updating it can be problematic.
The hard drive is the file inside your virtual machine directory with the .vdi file extension.
1) Merge any existing snapshots into the main hard drive
2) Turn the virtual machine off
3) Run the VboxManager clonehd command “hard-drive.vbox” “hard-drive-cloned.vbox”
VBoxManage clonehd ~/VirtualBox\ VMs/Ubuntu\ Server\ 32bit/Ubuntu\ Server\ 32bit.vdi ~/VirtualBox\ VMs/Ubuntu-Server-32bit-base.vdi ~/VirtualBox VMs/Ubuntu Server 32bit$ VBoxManage clonehd Ubuntu\ Server\ 32bit.vdi Ubuntu-Server-32bit-base2.vbox 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% Clone hard disk created in format 'VDI'. UUID: c90c5698-cf88-4452-849d-70ee6f950d13
Full path to files is not required, at least on Ubuntu Linux host, but may be necessary on other operating systems.
Refering to the hard drive meta-data, the .vbox file, will cause the command to fail. Virtualbox need to know the file name of the hard drive you want to clone, so use the .vdi file. If you refer to the .vbox file you will get the following error:
~/VirtualBox VMs/Ubuntu Server 32bit$ VBoxManage clonehd Ubuntu\ Server\ 32bit.vbox Ubuntu-Server-32bit-base3.vbox VBoxManage: error: Could not get the storage format of the medium '/home/johnny/VirtualBox VMs/Ubuntu Server 32bit/Ubuntu Server 32bit.vbox' (VERR_NOT_SUPPORTED) VBoxManage: error: Details: code VBOX_E_IPRT_ERROR (0x80bb0005), component Medium, interface IMedium, callee nsISupports Context: "OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, AccessMode_ReadWrite, pMedium.asOutParam())" at line 209 of file VBoxManageDisk.cpp
4) Create a new virtual machine and use the cloned hard drive instead of creating a new one.
There is an unsupported internal function of the VboxManger command called sethduuid. This will generate a new identification number for a hard drive.
So, if you copy the hard drive file and then run the following command on the copied hard drive file, you should be able to use that hard drive in a new virtual machine.
VboxManager internalcommands sethduuid “cloned-hd.vbox”
I manly use VirtualBox for Ubuntu server virtual machines and its often less fiddly just to create a new virtual machine from the Ubuntu server image (.iso) file. I have found that installing guest editions can be a little strange in Ubuntu server, so I am writing a guide to help.
See the VirtualBox manual for more information about VirtualBox configurations.
This work is licensed under a Creative Commons Attribution 4.0 ShareAlike License, including custom images & stylesheets. Permissions beyond the scope of this license may be available at @jr0cket