Skip to content
Bots!
Bots!
  • About
    • Myself
    • আমার দোয়া
  • Bookmarks
    • Bookmarks
    • My OCI Bookmarks
    • Useful Proxmox Commands & Links
    • Learning Nano
    • Useful Sites
    • Useful Virtualbox Command
    • Useful MySQL Command
    • Useful Linux Command
    • BTT-CAS
  • Resources
    • Webinar on Cloud Adoption for Project Managers
  • Photos
  • Videos
  • Downloads
Bots!

Clone KVM-based Virtual Machines on Redhat / CentOS Linux

Rumi, February 24, 2020

Prerequisite: Operating System and Software Versions

  • Operating System: – Redhat 7.3
  • Software: – libvirtd (libvirt) 2.0.0

Obtain Source Virtual Machine’s information

Before we begin cloning any virtual machine we first need to obtain some basic information about it. The absolute minimum information required about the source virtual machine we are about to clone would be its name and number of disk in use. To get virtual machines name run:

# virsh list
Id Name State
----------------------------------------------------
1 server1.local running

Next, we may would like to know the number of disk our source virtual machines is using as well as its location. The information about disks location is optional as it only provides us with a hint on where to store new clone disk files for the sake of consistency: # virsh dumpxml server1.local | grep "source file"
<source file='/var/lib/libvirt/images/server1.local.qcow2'/>
<source file='/var/lib/libvirt/images/server1.local-1.qcow2'/>
<source file='/var/lib/libvirt/images/server1.local-2.qcow2'/>

From the above output we can see that our original virtual machine has three disks stored in location /var/lib/libvirt/images/.

Suspend Source Virtual Machine

Before cloning can take place our source virtual machine needs to pause/suspended:

# virsh suspend server1.local
Domain server1.local suspended

Auto-Clone Virtual Machine

One way of cloning KVM-based Virtual Machines on Redhat Linux is to use –auto-clone switch. The main advantage of –auto-clone switch is that it automatically clones any number of source disks hence the user does not necessary need to know the location and number of the disk attached to the original virtual machine.

The disadvantage is that the user is unable to specify disk names and pride an alternative location to new cloned virtual disks. The following linux command will clone original virtual machine server1.local to new clone virtual machine server2.local automatically using –auto-clone switch.

# virt-clone --original=server1.local --name=server2.local --auto-clone
WARNING Setting the graphics device port to autoport, in order to avoid conflicting.
Allocating 'server2.local.qcow2' | 10 GB 00:00:00 
Allocating 'server1.local-1-clone.qcow2' | 5.0 GB 00:00:07 
Allocating 'server1.local-2-clone.qcow2' | 5.0 GB 00:00:00 
Clone 'server2.local' created successfully.

As we can see from the above output the –auto-clone automatically cloned all virtual disks attached to the original virtual machine and appended clone keyword to any additional disks. New cloned virtual machine should be now waiting in shut off state to be started:

# virsh list --all
Id Name State
----------------------------------------------------
1 server1.local paused
- server2.local shut off

Clone Manually Multiple Disk
To gain more control over the new cloned disk location and name we can omit the –auto-clone switch and supply all new cloned disk name and destination path using –file switch. Note the number of –file arguments supplied must be equal to the number of disks attached to the original virtual machine. Example:

# virt-clone --original=server1.local --name=server2.linuxconfig.org --file /var/lib/libvirt/images/server2.linuxconfig.org.img --file /var/lib/libvirt/images/server2.linuxconfig.org-1.img --file /var/lib/libvirt/images/server2.linuxconfig.org-2.img
WARNING Setting the graphics device port to autoport, in order to avoid conflicting.
Allocating 'server2.local.img' | 10 GB 00:00:00 
Allocating 'server2.local-1.img' | 5.0 GB 00:00:07 
Allocating 'server2.local-2.img' | 5.0 GB 00:00:00

Clone 'server2.local' created successfully.

Resume/Start

At this stage we are ready to resume our original virtual machine server1.local:# virsh resume server1.linuxconfig.org
Domain server1.local resumed and also start the newly cloned virtual machine server2.local:

# virsh start server2.local
Domain server2.local started

Check the state of all virtual machines:

# virsh list --all
Id Name State
----------------------------------------------------
1 server1.local running
3 server2.local running
Administrations KVM CentOS 7KVM

Post navigation

Previous post
Next post

Leave a Reply Cancel reply

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

Myself…

Hi, I am Hasan T. Emdad Rumi, an IT Project Manager & Consultant, Virtualization & Cloud Savvyfrom Dhaka, Bangladesh. I have prior experience in managing numerous local and international projects in the area of Telco VAS & NMC, National Data Center & PKI Naitonal Root and CA Infrastructure. Also engaged with several Offshore Software Development Team.

Worked with Orascom Telecom-Banglalink, Network Elites as VAS partner, BTRC, BTT (Turkey) , Mango Teleservices Limited and Access to Informaiton (A2I-UNDP)

Currently working at Oracle Corporation as Principal Technology Solution and Cloud Architect.

You can reach me [h.t.emdad at gmail.com] and I will be delighted to exchange my views.

Tags

Apache Bind Cacti CentOS CentOS 6 CentOS 7 Debain Debian Debian 10 Debian 11 Debian 12 DKIM Docker endian icinga iptables Jitsi LAMP Letsencrypt Linux Munin MySQL Nagios Nextcloud NFS nginx pfsense php Postfix powerdns Proxmox RDP squid SSH SSL Ubuntu Ubuntu 16 Ubuntu 18 Ubuntu 20 Varnish virtualbox vpn Webmin XCP-NG zimbra

Topics

Recent Posts

  • Install Jitsi on Ubuntu 22.04 / 22.10 April 30, 2025
  • Key Lessons in life April 26, 2025
  • Create Proxmox Backup Server (PBS) on Debian 12 April 19, 2025
  • Add Physical Drive in Proxmox VM Guest April 19, 2025
  • Mount a drive permanently with fstab in Linux April 16, 2025
  • Proxmox 1:1 NAT routing March 30, 2025
  • Installation steps of WSL – Windows Subsystem for Linux March 8, 2025
  • Enabling Nested Virtualization In Proxmox March 8, 2025
  • How to Modify/Change console/SSH login banner for Proxmox Virtual Environment (Proxmox VE / PVE) March 3, 2025
  • Install Proxmox Backup Server on Debian 12 February 12, 2025

Archives

Top Posts & Pages

  • Install Jitsi on Ubuntu 22.04 / 22.10
©2025 Bots! | WordPress Theme by SuperbThemes