Have you Installed KVM Virtual Machines on your system and feel like the names assigned to them are not up to your taste? Worry not for this is how to simply rename that virtual machine.
Take for example, as in my case, your virtual machine is assigned a name like generic and you want to rename it to at least reflect the OS type name like cent-server. Well, lets have a look at how to.
- Shutdown the Virtual Machine to be renamed.
# sudo virsh shutdown generic
- Generate the xml configuration file of the VM to some file, say generic.xml in the current directory.
# sudo virsh dumpxml generic > cent-server.xml
- Edit the generated xml file to rename the domain name between the name tags and the disk file in device section under source file=/var/lib/libvirt/images/generic.qcow2.
# vim cent-server.xml
<name>cent-server</name> ... <source file=/var/lib/libvirt/images/cent-server.qcow2>
After making the changes, save the file and quit.
- Delete all the existing files of the Virtual Machine
# sudo virsh undefine generic
- Create a new xml file for the Virtual Machine using the edited xml file.
# sudo virsh define cent-server.xml
- Finally, list all the Virtual Machines to confirm the changes.
# sudo virsh list --all
That was all about renaming KVM virtual machine through a command line with virsh command.