Cloning a VirtualBox Disk

One nice thing about using virtual machines is that you can make copies of them. This way if you install and configure a machine to your liking, you can just clone it and get another machine without having to go through the hassle of installation and configuration again. You can't just copy the .vdi file, however, because each virtual disk has a unique id. You can however, clone a disk relatively easily with the VBoxManage command.

In this tutorial we will be using a Windows 7 host, and cloning the hard disk for the CentOS 5.5 install that we performed in an earlier post. We will also assume that VBoxManage is in the Windows path. Open up a command prompt on the Windows host by clicking "Start" and typing "cmd" into the search box.

Once we open up a command prompt, we need to navigate to the directory where our hard disks are stored. These are in the your user's directory in the ".Virtualbox\HardDisks" subfolder. When you first open the command prompt, you should already be in your user's directory. Change to the hard disks folder by typing the following:

cd .VirtualBox\HardDisks

At this point, you can type "dir" to get a list of your .vdi files. If you followed along in the previous tutorial, you probably installed CentOS on a disk named "CentOS.vdi".

The syntax for the command to clone the disk is simple, "VBoxManage clonehd [infile.vdi] [outfile.vdi]". To clone disk named "CentOS.vdi" and create a duplicate "CentOS2.vdi" we type:

VBoxManage clonehd CentOS.vdi CentOS2.vdi

This process will take a few minutes.

To make the disk available to VirtualBox, we need to add it in the "Virtual Media Manager." From the main VirtualBox window, go to "File > Virtual Media Manager." Click "Add" and select the new disk we just cloned. Click "OK" and it should now be available in the dropdown box when you create a new machine.

blog comments powered by Disqus  -  Home