How to clone a KVM virtual machine on Linux

First, select the virtual machine that you want to clone.

 

[root@redhat ~]# ls /etc/libvirt/qemu/*.xml

/etc/libvirt/qemu/cp1.xml     /etc/libvirt/qemu/vcs5_sol_n1.xml      /etc/libvirt/qemu/vcs6_lin_vvr_n3.xml

/etc/libvirt/qemu/rhel6.xml   /etc/libvirt/qemu/vcs6_lin_vvr_n1.xml  /etc/libvirt/qemu/vcs6_sol_n1.xml

/etc/libvirt/qemu/rusher.xml  /etc/libvirt/qemu/vcs6_lin_vvr_n2.xml

Next, we need to see the disk size of the existing virtual machine:

 

[root@redhat ~]# lvs | grep -i rhel6

rhel6                     vg       -wi-a—-   8.00g

 

Now we create the logical volume to use for the new system:

 

[root@redhat ~]# lvcreate -L 8G -n shaun /dev/vg

Logical volume “shaun” created

 

Finally, we clone the existing virtual machine:

 

root@redhat ~]# virt-clone –prompt

What is the name of the original virtual machine?

rhel6

What is the name for the cloned virtual machine?

shaun

What would you like to use as the cloned disk (file path) for ‘/dev/vg/rhel6’?

/dev/vg/shaun

 

Now you can start the new virtual machine “shaun”

 

root@redhat ~]# virsh start shaun

root@redhat ~]# virsh list

 

Since we cloned the disk networking will not work until we reconfigure the interface.The Mac has an app called “Chicken of the VNC” installed. Connect to system “192.168.1.71 on display 1 ” to modify the Virtual Machines. The password for VNC is 123456

 

Once you see the Desktop, “Applications -> System Tools -> Virtual Machine Manager”

 

Click on your virtual machine to see the console display.

 

mv /etc/sysconfig/network-scripts/ifcfg-eth0  /etc/sysconfig/network-scripts/ifcfg-eth1

 

This will give you the MAC address: ifconfig eth1 | grep -i hwaddr | cut -c39-100

replace the HWADDR entry  in  /etc/sysconfig/network-scripts/ifcfg-eth1 with the correct address

replace DEVICE=”eth0″ to the new device name which is DEVICE=”eth1″

 

Change your hostname in /etc/sysconfig/network