Search This Blog

2015-02-27

Clone KVM VMs

virt-clone Method

Shutdown the guest:
# try safe shutdown
virsh shutdown $vm-name
# destroy if doesnt work
virsh destroy $vm-name

virt-clone --original $vm-name --name $new-name --file /var/lib/libvirt/images/$vm-name

Example:

[root@TPC-E9-07 ~]# virt-clone --original TPC-E9-07-020 --name TPC-E9-07-020-clone --file /var/lib/libvirt/images/TPC-E9-07-020-clone.qcow2
Allocating 'TPC-E9-07-020-clone.qcow2' | 25 GB 00:00:13

Clone 'TPC-E9-07-020-clone' created successfully.

[root@TPC-E9-07 ~]# virsh list --all | grep TPC-E9-07-020
- TPC-E9-07-020 shut off
- TPC-E9-07-020-clone shut off

[root@TPC-E9-07 ~]# virsh start TPC-E9-07-020-clone
Domain TPC-E9-07-020-clone started

[root@TPC-E9-07 ~]# virsh list --all
Id Name State
----------------------------------------------------
135 TPC-E9-07-020-clone running


Copy-Paste Method

virsh dumpxml $vm-name > /tmp/$new-name.xml
cp /var/lib/libvirt/images/$vm-name.qcow2 /var/lib/libvirt/images/$new-name.qcow2
virsh define /tmp/$vm-name.xml
virsh start $new-name


References:
http://linux.die.net/man/1/virt-clone
http://manpages.ubuntu.com/manpages/hardy/man1/virt-clone.1.html
http://ostolc.org/kvm-move-guest-to-another-host.html
http://linuxproblems.org/wiki/Clone_a_virtual_host_in_KVM_from_the_command_line



No comments:

Post a Comment