Updated: April 6, 2009
If you're a fan of virtualization, you will sooner or later come across VMware Server. The Server is a free solution that allows you to run multiple instances of various operating systems on top of your existing desktop, opening a world of efficiency, productivity, modularity, testing, and tweaking before you.
Virtualization allows you to do lots of things you would not normally try on your real machines. For example, test a dual-boot configuration of Windows and Linux machines, without fear of destroying your partitions. Or you may want to try new software without soiling your actual setups.
For more about virtualization, you may want to read an entire section of tutorials I have dedicated to this end. These tutorials cover old DOS stuff, VMware Player and Server, VirtualBox, MojoPac, 3D acceleration in virtual machines, dual boot, general tips and tricks, and other useful stuff. Now ... It is also quite likely that you will want to run more than one instance of a specific operating system; a personal example, I have a mini farm of three CentOS 5 virtual machines running at home. Virtual machines are essentially real, fully capable systems. The major difference from physical machines is that they run on virtualized hardware. This means that you will have to install them just as you would any other (real) system.
If you're ever going to run only a single instance of any operating system available, the installation is a necessary one-time operation. But what happens if you intend to deploy tens of virtual machines of the same type? Does this mean you will have to repeat the tedious installation and post-install configuration process over and over again?
Luckily, the answer is no.
This is what this article is all about. Teach you how to create duplicates / copies of your virtual machines, quickly and easily, skipping hours of installation and tweaks. In other words, create identical clones.
Back again to my CentOS mini far. I had to install only a single virtual machine. The other two instances are copies, created in about 5-6 minutes it took to clones them, compared to the approx. 1 hour of installation and another 2-3 hours of necessary settings that I had to undergo with the first instance. So, if you're interested, please read on.
Cloning virtual machines
The task is very simple. Create identical copies of existing virtual machines. This means install the operating system once - this is a necessity, you can't beat the 2nd Law of Thermodynamics. But then, be lazy for ever after.
I will demonstrate with VMware Server installed on Windows. But the principle holds for VMware Server on any platform, including Linux, for any virtual machine.
Virtual machines are files
This is the most important thing you need to remember about virtual machines. They are entirely contained in files saved in folders on your hard disk. Copy the files / folders and you have effectively copied the virtual machines. That's it! But now, let's take a look at a more detailed procedure - with some pictures.
Step 1: Locate the virtual machine you wish to clone
Your virtual machines will most likely be kept in separate folders, for easier management. For example, an Ubuntu virtual machine will most likely be kept in a folder named Ubuntu, a Windows XP machine will most likely be kept in a folder named Windows XP and so on. If you're at least modestly tidy, then your virtual arsenal might look like this:
If all your files are kept in a single folder, you will have find it a little more difficult to locate the files you need for successful cloning. As you may have noticed, VMware virtual machines have quite a few extensions - .vmx, .vmdk, .vmsd etc. While this variety may confuse you, the reality is much simpler. For successful cloning, you need only two files, the .vmx virtual machine configuration file and the .vmdk virtual hard disk. The virtual hard disk may be split into several files, so there can be more than one of these. Once we have located the files you need, our next step is to copy the files to their new location.
Step 2: Copy the virtual machine folder
Create a destination folder. For example, if we're creating a copy of a PCLinuxOS virtual machine, then the copy will go into a folder called something like copy-of-pclinuxos or perhaps pclinuxos-2. Your best bet is to stick with logical names. This is as simple as copying files the normal way - Ctrl + C, Ctrl + V, Copy & Paste via the Menu, command line etc. Whatever you prefer or find most convenient.
Step 3: Register the newly cloned machine with the VMware Server
The next step is to open the virtual machine through the Server, so it gets registered and listed in the menu of available machines. Start VMware Server, then go to File > Open. Navigate to your clone and choose the .vmx configuration file. This will add the clone to your list.
It will have the exact same parameters as the original machines, so now you can edit the virtual machine settings and change its name. Anything goes, as long as the logic of monitoring the inventory makes sense to you. And believe it or not, that's the whole story!
If you need hundreds of copies, you can write a script that does this, along with editing the virtual machine names. In Linux, this can be a very simple example of looping through a list with grep and sed, for instance.
Cloning virtual machines will save you tons of time. Furthermore, clones are also full backups or your original virtual machines, so you can also use them to revert catastrophic changes inflicted on your virtual machines. VMware Server lets you keep only a single snapshot of your virtual machines, but you can easily overcome this limitation by creating your own manual copies.
I hope you enjoyed this simple yet highly useful tutorial. Next, we will see how to do the same thing using the free ESXi bare-metal hypervisor.