How do I rename a KVM VM?

This example works on CentOS 7, but will likely work on other distributions too.


Save a copy of the Virtual Machines configuration (replacing VMNAME with the name of your VM as shown with "virsh list --all".

virsh dumpxml VMNAME > VMNAME.xml

Edit the VMNAME.xml file and search for 


and replace this with the new name for the VM and save the file.

Shutdown the VM (if the VM doesn't shutdown you can run "virsh destroy VMNAME" although data may be lost).

virsh shutdown VMNAME

To swap the server we need to undefine the old VM and define the new VM.

virsh undefine VMNAME
virsh define NEW_VMNAME VMNAME.xml

You can now start the VM to complete the rename.

virsh start NEW_VMNAME


You cannot comment on this entry