Project

Profile

Help

Cloning

Overview

Command will make clone of the disk images of any existing virtual machine, and define a new guest with an identical virtual hardware configuration. Elements which require uniqueness will be updated to avoid a clash between old and new guests.

Usage

  • Shutdown origin guest machine
    virsh shutdown ORIGIN_GUEST_NAME
  • Make clone
    sudo virt-clone -o ORIGIN_GUEST_NAME -n NEW_GUEST_NAME -f PATH_TO_NEW_IMAGE --connect=qemu:///system
    
    • o: origin guest name.
    • n: new guest name.
    • f: path to logical disk or partition of new guest.
    • --connect: hypervisor.
    • --auto-clone: do clone automatically using only name on origin gust

Timings

With machine created by mdbci, it took 1 minute to create clone (machine data was 1.5 gigabytes)

Examples

  • sudo virt-clone -o ORIGIN_NAME -n NEW_NAME -f PATH_TO_NEW_IMAGE --connect=qemu:///system
  • sudo virt-clone -o ORIGIN_NAME --auto-clone
    • creates machine viths name ORIGIN_NAME-clone

Getting ip address

arp -an | grep "`virsh dumpxml libvirt_node0-clone | grep 'mac address' | awk -F\' '{c[$2]++} END{for (w in c) print w}'`" | awk -F'[()]' '{print $(NF-1)}'

SSH to machine

Machine cloned from vagrant generated machine. In folder with Vagrantfile we can get private_key path of desired node with:

vagrant ssh-config

And then ssh to machine using key from origin guest machine like:

ssh -i PATH_TO_ORIGIN_GUEST_KEY vagrant@NEW_GUEST_IP_ADDRESS