The most important and most used feature in world of Virtualization is the ability to clone a VM,take snapshot of the current state of a VM, Live migrate a VM, e.t.c. Lately i have been playing with KVM and Openstack Cloud computing platform.At times you have to clone a VM to use it for a different project and in this small guide, i will show you how to do it using virt-clone command.
virt-clone is a command line tool used for cloning existing virtual machine images that uses libvirt as hypervisor management library.
Follow steps below to clone a vm on KVM.
Make sure the VM you wish to clone is powered off.Use command below, just replace “asterisk-cloud” with your vm name.
$ sudo virsh shutdown asterisk-cloud
You can get a list of Virtual Machines being managed by virsh using virsh list –all command:
$ sudo virsh list --all
Id Name State
----------------------------------------------------
- asterisk-cloud shut off
- instance-00000004 shut off
Clone the Virtual Machine. Here i want to clone asterisk-cloud virtual Machine to kamailio-cloud virtual machine.Below is the code to enter
asterisk-cloud: Name of VM cloning from kamailio-cloud: Name given to resulting VM after cloning kamailio-cloud.qcow2: Image saved that kamailio-cloud boots from.
Check to confirm that kamailio-cloud.qcow2 file is successfully stored in /var/lib/libvirt/images folder.
$ ls /var/lib/libvirt/images
total 6946188
-rw-r--r-- 1 root root 3238789120 Mar 20 17:42 asterisk-cloud.qcow2
-rwxr-xr-x 1 qemu qemu 666894336 Mar 16 04:14 CentOS-7-x86_64-Minimal-1503-01.iso
-rw-r--r-- 1 root root 3207331840 Mar 20 17:44 kamailio-cloud.qcow2
If you now run the command virsh list –all, you should see cloned vm present in the list.
$ sudo virsh list --all
Id Name State
----------------------------------------------------
- asterisk-cloud shut off
- instance-00000004 shut off
- kamailio-cloud shut off
Before starting the kamailio-cloud, i have to change channel source mode path from original. DO this by editing the file /etc/libvirt/qemu/kamailio-cloud.xml
$ sudo vi /etc/libvirt/qemu/kamailio-cloud.xml
Look for the line below and change original domain name to point to new clone.
Original was:
To start cloned virtual Machine, just type:
$ sudo virsh start kamailio-cloud --console
After logging in, i’ll have to change uuid for network interface. The one on My CentOS 7.x Guest machine is eth0. To generate new uuid for this interface, just type:
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.