Quantcast
Channel: Computing For Geeks
Viewing all articles
Browse latest Browse all 78

How To Clone and Use KVM Virtual Machine in Linux

$
0
0
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 usedfor cloning existing virtual machine images  that uses libvirt as hypervisor management library.
Follow steps below to clone a vm on KVM.
  1. Make sure the VM you wish to clone is powered off.Use command below, just replace "asterisk-cloud"with your vm name.
# virsh shutdown asterisk-cloud
You can get a list of Virtual Machines being managed by virsh using virsh list --all command:
# root at controller in ~ [22:06:29]
virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     asterisk-cloud                 shut off
 -     instance-00000004              shut off 
  1. Clone the Virtual Machine. Here i want to clone asterisk-cloud virtual Machine to kamailio-cloud virtual machine.Below is the code to enter
# root at controller in ~ [17:42:47]
virt-clone \
--connect=qemu:///system \
--original asterisk-cloud \
--name kamailio-cloud \
--file /var/lib/libvirt/images/kamailio-cloud.qcow2
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:
→ virt-clone \
--connect=qemu://192.168.1.30/system \
--original asterisk-cloud \
--name kamailio-cloud \
--file /var/lib/libvirt/images/kamailio-cloud.qcow2
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.
# root at controller in ~ [17:45:59]
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
# root at controller in ~ [17:47:07]
If you now run the command virsh list --all, you should see cloned vm present in the list.
# root at controller in ~ [17:49:48]
virsh list --all
Id Name State
----------------------------------------------------
- asterisk-cloud shut off
- instance-00000004 shut off
- kamailio-cloud shut off 
To start cloned virtual Machine, just type:
 # virsh start kamailio-cloud --console
That's all. You should have a running/working cloned Virtual Machine. You can also do this form graphical interface using "Virt Manager".


Viewing all articles
Browse latest Browse all 78

Trending Articles