I make frequent use of virtualized environments for testing and proof of concept work. One of the many great features of virtualized environments is that I do not have to start from scratch every time. I build base systems with the configured OS and any necessary software. Using these base systems I can spin up a new machine and get to the interesting work quickly.
The cloning processing is not as refined on VirtualBox as some of the other virtualization offerings but once you done it a few times you find that is not so painful of process to prevent frequent use. This document will detail the cloning process on a Windows 7 64bit host cloning an Oracle Linux 5 64bit guest. The version of VirtualBox used is 4.0.4 R70112.
Create a New Virtual Machine
First we will create a new VM with no virtual disk. On the VirtualBox Manager Dialog click the New icon on the button bar to start the virtual machine creation wizard.
Click the Next button on the wizard welcome screen to start the process.
On the VM Name and OS Type dialog provide a name and select and Operating System. Insure that the selected Operating System matches the OS on the virtual drive cloned later in the document. Click the next button to continue.
Provide a base memory size for this VM and click the Next button to continue.
On the Virtual Hard Disk dialog un-check the Boot Hard Disk checkbox. We do not want to create a virtual hard disk at this time as we will attach the clone disk created later. Click the Next button to continue.
A warning will appear after clicking the Next button because we did not create or attach a virtual hard disk on the last step. Click the Continue button.
The last dialog is the Summary Dialog click the Finish button to complete the New Virtual Machine Wizard.
Cloning the Virtual Hard Disk
The VirtualBox installation includes a program called VBoxManage. VBoxManage is a command line interface into the VirtualBox virtualization engine. Using VBoxManage you can perform any task that can be done through the user interface including many more functions that are not yet included in the interface. You can find more information on VBoxManage and it usage in Chapter 8 of the VirtualBox user’s guide. For the purpose of the cloning a VM we will only need to use the
C:\Users\ejenkinson>"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" clonehd Usage: VBoxManage clonehd <uuid>|<filename> <outputfile> [--format VDI|VMDK|VHD|RAW|<other>] [--variant Standard,Fixed,Split2G,Stream,ESX] [--existing] C:\Users\ejenkinson>
All we will be required to provide to
clonehd is just the source drive image and destination drive image including paths. You can find the location of the drive by opening the Virtual Media Manager found under the File Menu.
The Virtual Media Manager is where manage virtual hard disks as well as CD/DVD and floppy images. On the Hard Disks tab, select the disk you would like to clone. Once selected information about the drive such as the location, type and machine it is attached to is displayed at the bottom of the dialog.
Now that we know the name and path of the source virtual hard disk we can now use VBoxManage to clone the hard disk. In this situation we want to put the virtual hard disk clone in directory for the virtual machine we created earlier. Remember on Windows if you the paths have spaces you have to enclose the path in double quotes. Below is the output of executing the
clonehd command of VBoxManage.
C:\Users\ejenkinson>"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" clonehd "C:\Users\ejenkinson\VirtualBox VMs\OD Linux 11gR2\OD Linux 11gR2.vdi" "C:\Users\ejenkinson\VirtualBox VMs\OD Primary\OD Primary.vdi" 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% Clone hard disk created in format 'VDI'. UUID: fbcf1060-d494-4560-b1fb-e3bb385fd320 C:\Users\ejenkinson>
The speed of the
clonehd command depends on the size of the source virtual hard drive so expect to wait a while for the command to complete. Once the
clonehd command finished we can now attach the cloned virtual disk to the virtual machine created earlier.
Attaching the Cloned Drive to a Virtual Machine
Back on the VirtualBox Manager dialog select the virtual machine that you will use to attach the virtual disk and click the Settings icon the button bar.
On the Settings Dialog select Storage from the list on the left and select SATA Controller under the Storage Tree. With the SATA Controller highlighted click the second icon on right to add a hard disk.
Once you click the Add Hard Disk button a dialog will appear asking if you wish to create a new disk or choose and existing disk.
Click the Choose existing disk button to continue.
Browse to the location of the cloned disk, select the disk name in the list and click the Open button to continue.
Back on the Settings dialog you will see that the drive has been attached to the SATA Controller.
Click the OK button to close the Settings Dialog.
With cloned virtual disk attached to the new VM you have a successfully cloned your original VM. Keep in mind that all of the settings as well as the machine name in this new VM is the same as the original. You will need to make the necessary changes so this new machine will not have any conflicts with existing machines.