To rename a KVM virtual machine (VM) domain using the virsh
command, you can follow these steps:
- Check the name of the virtual machine:
sudo virsh list --all
- Shut down the virtual machine:
sudo virsh shutdown <old-vm-name>
where
<old-vm-name>
is the current name of the virtual machine. - 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. - 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.