How to Rename KVM Virtual Machine with virsh command

0
3450

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
    <name>cent-server</name>
            ...
    <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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here