Skip to content

Instantly share code, notes, and snippets.

@plembo
Last active August 29, 2022 14:44
Show Gist options
  • Save plembo/856750ef1c4a6b856cf8cec1ce6f2eea to your computer and use it in GitHub Desktop.
Save plembo/856750ef1c4a6b856cf8cec1ce6f2eea to your computer and use it in GitHub Desktop.
Rename a kvm machine

Rename a KVM (libvirtd) virtual machine

Credit to Amos Mibey for his excellent howto, How to Rename KVM Virtual Machine with virsh command. Kifarunix.com, 2 Sept 2018. Retrieved 21 July 2019.

Herein, "oldvmname" is the existing name of the vm, and "newvmname" is what its new name will be.

  1. Shut down target vm.
$ virsh destroy oldvmname
  1. Capture existing configuration.
$ virsh dumpxml oldvmname > newvmname.xml
  1. Edit xml file to change oldvmname to newvmname.
$ perl -pi -e 's/oldvmname/newnvmame/g' newvmname.xml
  1. Rename the disk image file wherever it is (on my systems /var/lib/libvirt/images is a symlink to another folder on a much bigger storage volume).
$ sudo mv /d1/images/oldvmname.qcow2 /d1/images/newvmname.qcow2
  1. Undefine (delete) the existing oldvmname configuration.
$ virsh undefine oldvmname
  1. Re-create the configuration under the new name by importing the modified xml.
$ virsh define newvmname.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment