Skip to content
TrySitePrice

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

Best/Tutorial

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 UUIDrnsudo virsh dumpxml <old-vm-name> > <old-vm-name>.xmlrnsudo sed -i "s/<name>.*<\/name>/<name><new-vm-name><\/name>/g" <old-vm-name>.xmlrnsudo 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>

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