The syntax is to rename a KVM VM with virsh is as follows:
# virsh domrename {domain} {new-name}
Let’s see an example of renaming a VM using virsh.
1. To rename VM from serverA to serverB, first shutdown the VM:
# virsh shutdown serverA
2. Now to rename a VM, run:
# virsh domrename serverA serverB Domain successfully renamed
3. To start the VM/domain:
# virsh start serverB
Rename KVM domain with virsh and XML
1. First get domain information in XML and save it to a new file:
# virsh dumpxml serverA > serverB.xml
2. Edit the XML file and change the name between the <name></name>
# vi serverB.xml
Update it as follows from serverA to serverB:
<name>serverB</name>
3. Shutdown the serverA domain/vm:
# virsh shutdown serverA
4. You need to undefine the old VM name:
# virsh undefine serverA
5. Finally, import the edited XML file to define the VM serverB:
# virsh define serverB.xml
6. Start the domain serverB, enter:
# virsh start serverB