Credit to Amos Mibey for his excellent howto, How to Rename KVM Virtual Machine with virsh command. Kifarunix.com, 2 Sept 2018. Retrieved 21 July 2019.
Herein, "oldvmname" is the existing name of the vm, and "newvmname" is what its new name will be.
- Shut down target vm.
$ virsh destroy oldvmname
- Capture existing configuration.
$ virsh dumpxml oldvmname > newvmname.xml
- Edit xml file to change oldvmname to newvmname.
$ perl -pi -e 's/oldvmname/newnvmame/g' newvmname.xml
- Rename the disk image file wherever it is (on my systems /var/lib/libvirt/images is a symlink to another folder on a much bigger storage volume).
$ sudo mv /d1/images/oldvmname.qcow2 /d1/images/newvmname.qcow2
- Undefine (delete) the existing oldvmname configuration.
$ virsh undefine oldvmname
- Re-create the configuration under the new name by importing the modified xml.
$ virsh define newvmname.xml