Skip to content

Instantly share code, notes, and snippets.

@rendoaw
Created June 6, 2015 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rendoaw/6d156caaf537dda14167 to your computer and use it in GitHub Desktop.
Save rendoaw/6d156caaf537dda14167 to your computer and use it in GitHub Desktop.
Clone KVM Guest

original source: http://unix.stackexchange.com/questions/8351/how-to-create-a-dupe-of-a-kvm-libvirt-virt-manager-vm

# You cannot "clone" a running vm, stop it.  suspend and destroy
# are also valid options for less graceful cloning
virsh shutdown this.vm

# copy the storage.
cp /var/lib/libvirt/images/{this-vm,that-vm}.img

# dump the xml for the original
virsh dumpxml this-vm > /tmp/that-vm.xml

# hardware addresses need to be removed, libvirt will assign
# new addresses automatically
sed -i /uuid/d /tmp/that-vm.xml
sed -i '/mac address/d' /tmp/that-vm.xml

# and actually rename the vm: (this also updates the storage path)
sed -i s/this-vm/that-vm /tmp/that-vm.xml

# finally, create the new vm
virsh define /tmp/that-vm.xml
virsh start this-vm
virsh start that-vm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment