Cloning KVM Virtual Machines: A Practical Guide

After provisioning a virtual machine, repeatedly running virt-install followed by VNC-based OS installation becomes tedious. Instead, cloning an existing VM and adjusting a few configuration parameters is far more efficient. This approach works well for creating multiple instances with similar base configurations.

  1. Performing the Clone Operation

The virt-clone utility handles the cloning process. Execute the following command to create a new VM based on an existing one:

  1. Updating the Hostname

After cloning completes, connect to the new VM using the source machine's IP address. Two files require modification to set the hostname properly:

  • /etc/hostname
  • /etc/hosts

Edit both files and replace the hostname with the new VM name. A system reboot is necessary for changes to persist permanently. Note that using hostname -f only applies the change temporarily and will reset after restart.

  1. Configuring Network Settings

Assign a new IP address within the same subnet as the source VM by editing the network configuration file:

source /etc/network/interfaces.d/*

Loopback interface

auto lo iface lo inet loopback

Primary network interface

auto ens3 iface ens3 inet static address 192.168.122.10 netmask 255.255.255.0 gateway 192.168.122.1


</div>4. Restarting Network Services
------------------------------

Apply the new network configuration by restarting the networking service:

<div>```
sudo /etc/init.d/networking restart

Helpful Tips

Changing the virsh Editer

By default, virsh edit opens nano. To switch to vim, add the following line to ~/.bashrc:

Locating a VM's IP Address

When you need to find a VM's IP but lack direct access:

  1. Run virsh edit <vm-name> and locate the MAC address in the interface configuraton
  2. Execute on the host: arp -a | grep -i <MAC>

This reveals the IP address currently associated with that MAC address.

Tags: libvirt KVM virtualization virt-clone Ubuntu

Posted on Sun, 25 Oct 2026 16:37:00 +0000 by twmcmahan