In our previous article, you would have seen How to Install Xen Virtualization Software on Linux and Launch a VM using virt-manager? Today, we shall see how to clone a VM on Xen HyperVisor using virt-clone.
Step 1: Firstly, we need to find virt-clone utility is available using the below commands:
#rpm -qa | grep 'virtinst\|libvirt' libvirt-0.8.2-29.el5_9.1 libvirt-python-0.8.2-29.el5_9.1 python-virtinst-0.400.3-13.el5
or
#which virt-clone /usr/bin/virt-clone Wed Oct 21>#
If virt-clone utility is not found, then you need to install libvirt and virtinst packages using the yum installer.
#yum install virtinst libvirt
Step 2: Find out the list of VM’s using the below command:
#xm list Domain Name ID Mem(MiB) VCPUs State Time(s) Domain-0 0 5911 4 r----- 15870.6 centos-2 6 1032 1 ------ 4.6
Then, shutdown the virtual machine that you want to clone using one of the following commands:
#xm shutdown <domain-name>
or
#virsh -c xen:/// Welcome to virsh, the virtualization interactive terminal.
Type: 'help' for help with commands 'quit' to quit
virsh # shutdown <domain-name>
Step 3: Use the virt-clone command to create the clone as shown below:
Certain questions would be prompted as shown below, which you have to answer.
#virt-clone --connect xen:/// --prompt What is the name of the original virtual machine? centos-2 What is the name for the cloned virtual machine? centos-clone-2 ERROR Domain with devices to clone must be paused or shutoff.
Note: The above error would occur, if you don’t shutdown/pause the VM’s you intend to clone.
#virt-clone --connect xen:/// --prompt What is the name of the original virtual machine? centos-2 What is the name for the cloned virtual machine? centos-clone-2 What would you like to use as the cloned disk (file path) for '/var/lib/xen/images/centos-2-3.img'? /var/lib/xen/images/centos-2-4.img Cloning /var/lib/xen/images/centos-2-3.img | 7.8 GB 01:04 Clone 'centos-clone-2' created successfully.
Or
if you know the original VM name, you can directly run the below command:
#virt-clone --original centos-2 --name centos-clone-2 --file /var/lib/xen/images/centos-clone-2.img
Step 4: Now boot the new cloned VM as shown below:
#xm create centos-clone-2 Using config file "/etc/xen/centos-2". Started domain centos-2
Step 5: Make the network settings appropriately:
Find the MAC address with the below command:
#ifconfig -a | grep HWaddr eth0 Link encap:Ethernet HWaddr 00:16:3E:3D:48:8D
Open the file: /etc/sysconfig/network-scripts/ifcfg-eth0 and change the IP address and MAC address accordingly.
Make sure the network service are up and there you go. Your VM is now available over network.