Skip to content

Instantly share code, notes, and snippets.

@tensorfields
Last active August 9, 2017 07:03
Show Gist options
  • Save tensorfields/4447653 to your computer and use it in GitHub Desktop.
Save tensorfields/4447653 to your computer and use it in GitHub Desktop.
Rename KVM guest VM
# Shutdown the VM and rename storage (optional)
$ virsh shutdown old_vm
$ mv /path/to/old_vm.img /path/to/new_vm.img
# Edit virsh template with the new name and storage
$ virsh dumpxml old_vm > new_vm.xml
$ vim new_vm.xml
~~~ new_vm.xml
<name>new_vm</name> # <-- change this line
...
<devices>
...
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/path/to/new_vm.img'/> # <-- change this line
<target dev='vda' bus='virtio'/>
...
</disk>
~~~
# Redefine the KVM guest
$ virsh undefine old_vm
$ virsh define new_vm.xml
@apiemont
Copy link

apiemont commented Apr 7, 2016

instead of moving the img file, perhaps it is better to

# virsh vol-clone oldvolname newvolname --pool default
# virsh vol-delete oldvolname --pool default

that is, if you use virsh to manage your storage pool ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment