Date: 6/3/2019
Server virtualization with KVM
Linux System Administration

Exercise: Cloning VMs in virt-manager

Cloning kvm1
  • In default KVM configuration, the VM disk images are stored in directory /var/lib/libvirt/images and the VM configurations in directory /etc/libvirt/qemu.
    The image files take large space, so we need to create an additional folder to store them:
    mkdir /home/hostadm/KVM
    chmod 755 /home/hostadm/KVM

  • Prepare kvm1 for cloning:
    On the VM, edit file /etc/hosts and remove the line containing kvm1.
    In the same file, also remove localhost in the line starting with '::1'. The line should look as follows now:
    ::1 ip6-localhost ip6-loopback

    If there is file /etc/udev/rules.d/70-persistent-net.rules, then remove it:
    ls /etc/udev/rules.d/70-persistent-net.rules && rm /etc/udev/rules.d/70-persistent-net.rules
    Execute command shutdown on the VM:
    shutdown now -h
    On the desktop, set the readable permission for all on the virtual drive:
    sudo chmod a+r /var/lib/libvirt/images/kvm1.qcow2

  • Launch virt-manager. Right click onto kvm1 and select to "clone". Name the cloned system kvm2.
    For the storage option, select "Details",
    then specify the new path: /home/hostadm/KVM/kvm2.qcow2
    Keep the default configuration settings for the other parameters.
    This will be a new VM with the systems configurations originally set in kvm1.
  • After the cloning procedure is completed, boot kvm2:
    virsh list --all
    virsh start kvm2
    Login to the system as user hostadm, elevate privileges by running sudo -s, then follow the procedure below to change the host name from kvm1 to kvm2:
    Edit file /etc/hostname and replace kvm1 by kvm2.

  • Reset the machine ID by running the following commands on kvm2:
    rm -f /etc/machine-id
    rm /var/lib/dbus/machine-id
    dbus-uuidgen --ensure=/etc/machine-id
    dbus-uuidgen --ensure
  • Clear the DHCP leased IP settings:
    dhclient -r ens3
  • Execute command reboot on kvm2:
    Exit the VM console with ^] key combination.

  • Login to kvm2 again after it boots up:
    virsh console kvm2
    Check if the system recognizes itself as kvm2:
    uname -n
    Shutdown kvm2 by running command shutdown on it:
    sudo -s
    shutdown now -h
    When the VM console exits, make sure kvm2 is no longer running:
    virsh list --all

  • Take me to the Course Website