Cloning KVM virtual machine using CLI

To clone your VM and spawn new instances in KVML

# virt-clone --original {Domain-Vm-Name-Here} --auto-clone

OR

# virt-clone --original {Domain-Vm-Name-Here} --name {New-Domain-Vm-Name-Here} --auto-clone

OR

# virt-clone --original {Domain-Vm-Name-Here} \
--name {New-Domain-Vm-Name-Here} --file {/var/lib/libvirt/images/File.Name.here}

Examples: Cloning Guests with virt-clone

First VM/domain with devices to clone must be paused or shutoff. To gracefully shutdown a domain named ubuntu-box1, run:

$ sudo virsh shutdown ubuntu-box1

OR you can paused it as follows:

$ sudo virsh suspend ubuntu-box1
$ virsh list

Sample outputs:

Domain ubuntu-box1 suspended

Id Name State
----------------------------------------------------
1 freebsd running
5 ubuntu-box1 paused

Let us generate a new guest name, and paths for new storage automatically for a vm called ubuntu-box1

$ sudo virt-clone --original ubuntu-box1 --auto-clone

Sample outputs:

WARNING Setting the graphics device port to autoport, in order to avoid conflicting.
Allocating 'ubuntu-box-1-clone.qcow2' | 40 GB 00:00:04

Clone 'ubuntu-box1-clone' created successfully.

The above command cloned the guest called “demo” on the default connection, auto generating a new name called ubuntu-box1-clone and disk clone path. You can start or resume original domain:

$ sudo virsh start ubuntu-box1

OR

$ sudo virsh resume ubuntu-box1

Next, start ubuntu-box1-clone, enter:

$ sudo virsh start ubuntu-box1-clone

Verify it:

$ virsh list

For better managibility you can install virt-manager and use mobaxtreme tool to connect to the virt-manager GUI on your PC..

Share

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.