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.
You can get a list of Virtual Machines being managed by virsh using virsh list –all command:
- Clone the Virtual Machine. Here i want to clone asterisk-cloud virtual Machine to kamailio-cloud virtual machine.Below is the code to enter
Output is like below:
Allocating ‘kamailio-cloud.qcow2’ | 8.0 GB 00:01:21
Clone ‘kamailio-cloud’ created successfully.
If you’re connection to remote KVM/QEMU Host machine, put url before /system.It will look something like:
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.
If you now run the command virsh list –all, you should see cloned vm present in the list.
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
Look for the line below and change original domain name to point to new clone.
Original was:
To start cloned virtual Machine, just type:
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:
My original eth0 configuration file from asterisk-cloud vm looked like below:
I will change uuid replacing old with generated one:
Modify below configurations to fit your use cases.
The restart your network service:
That’s all. You should have a running/working cloned Virtual Machine. You can also do this form graphical interface using “Virt Manager”.