How to Rename KVM Virtual Machine with virsh command


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.

  1. Shutdown the Virtual Machine to be renamed.
    # sudo virsh shutdown generic
  2. 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
  3. 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
    <source file=/var/lib/libvirt/images/cent-server.qcow2>

    After making the changes, save the file and quit.

  4. Delete all the existing files of the Virtual Machine
    # sudo virsh undefine generic
  5. Create a new xml file for the Virtual Machine using the edited xml file.
    # sudo virsh define cent-server.xml
  6. 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.


  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


Please enter your comment!
Please enter your name here