Is it possible to rename KVM virtual machine? Yes, follow through this guide to learn how to rename KVM virtual machine with virsh command. virsh program is the main interface for managing virsh guest domains. The program can be used to create, pause, update and shutdown domains. It can also be used to list current domains.
Table of Contents
Renaming KVM Virtual Machine with virsh command
So, have you created 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.
Get the Name of the Virtual Machine
You can get the name of the virtual machine either from the Virt-manager or from command line using the virsh command;
virsh list --all
Sample output;
Id Name State
---------------------------------
- mon01 shut off
- vm01 shut off
- generic shut off
- stack shut off
- win10 shut off
Shut down the Virtual Machine
Shutdown the Virtual Machine to be renamed.
sudo virsh shutdown generic
Generate VM XML File
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
Rename the KVM Virtual Machine
Edit the generated xml file to rename the domain name between the name tags;
vim cent-server.xml
<name>generic</name>
to your new VM name;
<name>cent-server</name>
and the disk file in device section under source file=/var/lib/libvirt/images/generic.qcow2
.
<source file=/var/lib/libvirt/images/cent-server.qcow2>
After making the changes, save the file and exit the xm file.
Undefine the Virtual Machine
Delete all the existing configurations of the Virtual Machine;
sudo virsh undefine generic
Recreate the Virtual Machine from the XML file
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
Id Name State
---------------------------------
- mon01 shut off
- vm01 shut off
- cent-server shut off
- stack shut off
- win10 shut off
And that that is all about renaming KVM virtual machine through a command line with virsh command.
That concludes our guide on renaming KVM virtual machine with virsh command.
Hi guess is not the correct change, you can left source section as you have on pont 3 and only change it at the very begining tag generic to cent-server
Then continue with step 4, 5 & 6
Hi, thanks for the post.
As Israel commented, changing the source section in step 3 doesn’t change the file name so, should you change it you have to manually rename the file in ‘/var/lib/libvirt/images’ directory