Need help?

Our experts have had an average response time of 11.7 minutes in August 2021 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

Clone KVM Virtual Machine – How we use it in Linux

by | Jan 2, 2021

Need help to clone KVM Virtual Machine in Linux? We can help you.

Here at Bobcares, we assist our customers with several Linux queries as part of our Server Management Services.

Today, let us see how to do it using the virt-clone command.

 

What is virt-clone

virt-clone is a command-line tool to clone existing virtual machine images that use libvirt as a hypervisor management library. First, it will copy the disk images of any existing virtual machine. Then it will define a new guest with an identical virtual hardware configuration.

Now let us proceed to learn how our Support Techs clone KVM Virtual Machine in Linux

 

Clone KVM Virtual Machine

Our Support Engineers suggest to follow the steps below to clone a VM on KVM:

Step 1: Make sure that the VM to clone is off.

We use the command below. Replace “asterisk-cloud” with the VM name.

$ sudo virsh shutdown asterisk-cloud

Then we run the below command to get a list of Virtual Machines virsh manages:

$ sudo virsh list –all
Id Name State
—————————————————-
– asterisk-cloud shut off
– instance-00000004 shut off

Step 2: Clone the Virtual Machine.

To clone asterisk-cloud virtual Machine to kamailio-cloud virtual machine, we run:

$ sudo virt-clone
–connect=qemu:///system
–original asterisk-cloud
–name kamailio-cloud
–file /var/lib/libvirt/images/kamailio-cloud.qcow2

Subsequently, the output will look like this:

Allocating ‘kamailio-cloud.qcow2’ | 8.0 GB 00:01:21
Clone ‘kamailio-cloud’ created successfully.

If we are connecting to a remote KVM/QEMU Host machine, we put the URL before /system.

It will look something like this:

$ sudo 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.

Clone KVM Virtual Machine in Linux

Then we 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 we now run the command virsh list –all, we 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, change the channel source mode path from the original.

We do this by editing the file /etc/libvirt/qemu/kamailio-cloud.xml

$ sudo vi /etc/libvirt/qemu/kamailio-cloud.xml

Then we look for the line below and change the original domain name to point to the new clone.

<channel type=’unix’>
<source mode=’bind’ path=’/var/lib/libvirt/qemu/channel/target/domain-kamailio-cloud/org.qemu.guest_agent.0’/>

Original was:

<channel type=’unix’>
<source mode=’bind’ path=’/var/lib/libvirt/qemu/channel/target/domain-asterisk-cloud/org.qemu.guest_agent.0’/>

Subsequently, to start the cloned virtual Machine, we type:

$ sudo virsh start kamailio-cloud –console

After logging in, we change uuid for the network interface. The one on CentOS 7.x Guest machine is eth0.

Similarly, to generate a new uuid for this interface, we type:

$ uuidgen eth0
29e28904-c8f6-4ac0-93f0-d5d2cedb8555

Original eth0 configuration file from asterisk-cloud VM look like below:

TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eth0
UUID=230e87b1-f847-4cab-86b9-df4268a0a0a3
DEVICE=eth0
ONBOOT=yes
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes

Then we change uuid replacing old with generated one:

$ sudo vim /etc/sysconfig/network-scripts/ifcfg-eth0

On the other hand, we modify the below configurations to fit use cases.

TYPE=Ethernet
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eth0
UUID=29e28904-c8f6-4ac0-93f0-d5d2cedb8555
DEVICE=eth0
ONBOOT=yes
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes

Then we restart network service:

$ sudo service network restart
$ sudo systemctl restart network.service

[Find it hard to clone KVM? We’d be happy to assist you]

 

Conclusion

To conclude, we learned how to use the virt-clone command which provides a number of options to clone a KVM VM. Today, we saw an effective method employed by our Support Techs in this regard.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF