beta.blog

Linux (Ubuntu)

virsh: Rename a KVM Guest (script)

by on Sep.18, 2012, under Linux (Ubuntu)

Renaming a guest via virsh seems to be kinda messy but I found a solution for my problem.

Note: Make sure to replace vps01 and vps01-backup

First of all you need to dump/export the xml configuration of your KVM guest to name_of_vm.xml:

virsh dumpxml vps01 > name_of_vm.xml

Secondly you have to undefine/remove the xml configuration of this guest with virsh:

virsh undefine vps01

Thirdly use this command to replace vps01 with vps01-backup in this file

sed -i 's/<name>vps01<\/name>/<name>vps01-backup<\/name>/g' name_of_vm.xml

Then use virsh to re-define the VM using its new name:

virsh define name_of_vm.xml

Now you can remove the temporary xml dump:

rm name_of_vm.xml
Leave a Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!