How to clone virtual machine with VmWare Server
8 Apr2007

Today I was doing some pre-release testing of our software and to test it I was needed three separate servers running MySQL. After some thinking I decided to use my “old” workstation (actually it is pretty powerful Sempron with 2Gb of RAM, but now I use my macbook as a primary workstation) and start 3 separate virtual servers there. Of course, as all admins, I’m little bit lazy and installing Debian on all three machines was not appropriate solution ;-). So, I’ve created one machine, installed brand-new Debian Etch there and then begun to look for solution to clone this machine to run it in three copies. After all these operations were done, I’ve decided to spend time I’ve saved with this simple trick to describe here how to clone VmWare Server virtual machine without any pain.

First of all, we need to find where all our virtual machines are in our system. After small search I’ve found vmware files in /var/lib/vmware/Virtual Machines. There are some set of directories each corresponds to some of your already created virtual machines. In my case I was interested in cloning virtual machine with name db1 to new machine db2 and then to db3.

I’ve copied entire db1 directory to new one:

1
scoundrel@scoundrel-desktop:/var/lib/vmware/Virtual Machines$ cp -ax db1 db2

Next step was to rename virtual machine’s disk image (maybe it is not necessary but I decided that it would be better to perform this operation). To manage vmware disk images you could use vmware-diskmanager tool which resides in vmware’s binary directory (/vmware/bin in my case):

1
scoundrel@scoundrel-desktop:/var/lib/vmware/Virtual Machines/db2$ /vmware/bin/vmware-vdiskmanager -n db1.vmdk db2.vmdk

Next (and, actually, last) step was to rename virtual machine config and change disk image name in this config file:

1
2
scoundrel@scoundrel-desktop:/var/lib/vmware/Virtual Machines/db2$ mv db1 db2
scoundrel@scoundrel-desktop:/var/lib/vmware/Virtual Machines/db2$ sed -i 's/db1.vmdk/db2.vmdk/' db2

That’s it! Now we can start this new machine with VMware server console, it would ask as to change machine’s UUID (which is machines MAC address) and after uuid change this machine will get new IP address from dhcp server (in my case – wifi router). As always it was easy and funny. Stay tuned and I’ll say you why you should not use MySQL’s config file (my.cnf) to setup replication (this hint is for my next post).