How to Rename KVM Virtual Machine with virsh command

Last Updated:
How to Rename KVM Virtual Machine with virsh command

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.

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

to your new VM 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.

Other Tutorials

Install KVM on Oracle Linux

Change Windows Boot Device from IDE to Virtio on KVM


We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
I am the Co-founder of, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

2 thoughts on “How to Rename KVM Virtual Machine with virsh command”

  1. 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

  2. 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


Leave a Comment