How To Clone a VMWare Virtual Machine

How To Clone a VMWare Virtual Machine

Ok… So if you’re anything like me… then you’d rather work smart than work hard… As that relates to VMWare Virtual Machines. You just finished creating a Virtual Machine running your favorite OS, or may be you need to setup a number of like servers for testing one thing or another. Lets assume it took you 3hrs to create, update and harden your Virtual Machine (herein after referred to as the Master Virtual Machine) with all the latest and greatest patches and update.

Now given that you need multiple copies of the master version which took you a good 3hrs to build.

Do you:

  1. Start to create and install a new virtual machine from scratch and spend another 6hrs on the next two?
  2. Or do you copy your virtual machine to other VMWare Server Hosts and test on 3 independent VMWare Servers Hosts running a single copy of the master Virtual Machine? Which seems redundant and costly
  3. Or do you clone the Master Virtual Machine to create 2 other duplicate Virtual Machines to be hosted on one VMWare Server 2.0 Host?

Well I don’t know about you but option 3 seems the least time consuming, and the most reliable for reproducing exact copies of the Master with out any errors or miss-configurations.

So how do you Clone or Duplicate a VMWare Virtual Machine on the Same Virtual Server Host?

Here are the steps I took to reproduce exact copies of my master Virtual Machine.

Assuming we want to clone a Virtual Machine named WinXp to WinXp2 and WinXp3

  1. Locate where your Virtual Machines are being stored. If you have a default install with no customizations, then you’ll find the Virtual Machines in the following folder on a Linux VMWare Server Host/var/lib/vmware/Virtual Machines.
  2. Here you’ll find a compete set of files and folders for each of your Virtual Machines.
  3. First thing is to copy WinXp folder to WinXp2 and WinXp3 by typing the following command:cd /var/lib/vmware/Virtual Machines/cp -ax WinXp WinXp2

    cp -ax WinXp WinXp3

  4. Next we need to rename the Virtual Machines Disk Images. You could usevmware-diskmanager to do this which resides in the vmware binary directory (/vmware/bin).cd /var/lib/vmware/Virtual Machines/WinXp2

    WinXp2$ /vmware/bin/vmware-diskmanager -n WinXP.vmdk WinXp2.vmdk

    cd /var/lib/vmware/Virtual Machines/WinXp3

    WinXp3$ /vmware/bin/vmware-diskmanager -n WinXP.vmdk WinXp3.vmdk

  5. The last step in the process is to rename the Virtual Machine config?and change the disk image name in the config file.WARNING: Failing to do this will result in all three Virtual Machines referencing and modifying the one Disk Image (The Master Disk Image)cd /var/lib/vmware/Virtual Machines/WinXp2

    WinXp2$ mv WinXp WinXp2

    WinXp2$ sed -I ’s/WinXp.vmdk/WinXp2.vmdk/’ WinXp2

    cd /var/lib/vmware/Virtual Machines/WinXp3

    WinXp3$ mv WinXp WinXp3

    WinXp3$ sed -I ’s/WinXp.vmdk/WinXp3.vmdk/’ WinXp3

  6. That’s it… Enjoy

The only other thing you’ll need to do when you are done with the above steps is to start your new Virtual?Machines. You will be asked to change the Virtual Machines UUID (Its Virtual MAC Address). Upon changing the UUID the Virtual Machine will be able to accept IP addresses from a DHCP server.