How to rename KVM virtual machine (VM) domain with virsh command

To rename a KVM virtual machine (VM) domain using the virsh command, you can follow these steps:

  1. Check the name of the virtual machine:
    sudo virsh list --all
  2. Shut down the virtual machine:
    sudo virsh shutdown <old-vm-name>

    where <old-vm-name> is the current name of the virtual machine.

  3. Rename the virtual machine:
    sudo virsh dominfo <old-vm-name> | grep UUID
    sudo virsh dumpxml <old-vm-name> > <old-vm-name>.xml
    sudo sed -i "s/<name>.*<\/name>/<name><new-vm-name><\/name>/g" <old-vm-name>.xml
    sudo virsh define <old-vm-name>.xml

    where <new-vm-name> is the desired new name of the virtual machine.

  4. Start the renamed virtual machine:
    sudo virsh start <new-vm-name>

Now, the virtual machine will have a new name and you can verify this by running the virsh list --all command.

Leave a Comment