My ongoing experiences with Ubuntu, and later Mythbuntu, as a media center with MythTV. I'm also using the system for a virtual machine server, a mediawiki server and a general all around home infrastructure base.

Sunday, January 25, 2009

Cloning a Ubuntu VM

I haven't yet found a good set of directions on the net for cloning a Ubuntu VM. These directions are for cloning a 8.04 Ubuntu server VM (it happens to also be running in a Ubuntu server, but these should work for any linux server).

These directions assume your VMs use static IP addresses and you want to clone an existing VM called "myvm" to a new VM called "mynewvm" with its own IP address.

Make sure "myvm" has no snapshots, as this method won't work on a VM with snapshots (the disk rename step will fail).

Also make sure you close the original VM in VMWare-Server or you may get file-locking problems.


Ok, first change to the directory where the original VM is stored and copy the directory (this will take a few minutes):
cd /usr/lib/Virtual Machines
cp -ax myvm mynewvm

Now rename the disk:
cd mynewvm
/usr/bin/vmware-vdiskmanager -n myvm.vmdk mynewvm.vmdk

Now rename the configuration file and change the name of the VM in the file:
mv myvm.vmx mynewvm.vmx
sed -i "s/myvm/mynewvm/" mynewvm.vmx

Now in VM-Ware server, select "File" then "Open" and "Browse". Select the "mynewvm" directory and the "mynewvm.vmx" file in that directory. The new VM should appear in the Inventory list.

Select the new VM and boot it. At this point it won't appear on the network. You'll need to log into the console as root and do the following:

rm /etc/udev/rules.d/70-persistent-net.rules

At this point, you could reboot the VM and it will come back up with original IP and hostname, which will cause a conflict if the original VM is also on the network, so you might just want to go ahead and do the following while you're hear:

Change the hostname by editing /etc/hostname.

Then edit /etc/network/interfaces and change the 'address' line to reflect the new IP address you want the VM to have.

Finally, etc /etc/hosts, change the line for '127.0.1.1' to reflect the new hostname and add (probably at the end of the file, but really where ever you want) a new line for the new hostname, e.g/:

192.168.1.50  mynewvm

That should do it. Now just reboot the VM and it should come back up with the new IP and hostname.

No comments: