≡ Menu

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

How do I rename KVM-powered virtual machine from foo to bar using virsh command line option on Linux?

There are two ways to rename a domain/VM. Let us see how to change the name of a domain or vm under KVM.
Rename KVM Virtual Machine with virsh

Method 1 – Rename KVM VM with virsh

The syntax is:
# virsh domrename {domain} {new-name}
To rename VM from foo to bar, type:
# virsh shutdown foo
Domain foo is being shutdown

Now rename a VM, run:
# virsh domrename foo bar
Domain successfully renamed

Start a VM/domain, enter:
# virsh start bar
Domain bar started

Method 2 – Rename KVM domain with virsh

First get domain information in XML and save it to a new file:
# virsh dumpxml foo > bar.xml
Edit the XML file and change the name between the <name></name>
# vi bar.xml
Update it as follows from foo to bar:

<name>bar</name>

Shutdown the foo domain/vm:
# virsh shutdown foo
Domain foo is being shutdown

You need to undefine the old VM name:
# virsh undefine foo
Domain foo has been undefined

Finally, import the edited XML file to define the VM bar:
# virsh define bar.xml
Domain bar defined from bar.xml

Start the domain bar, enter:
# virsh start bar
Domain bar started

Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:



{ 2 comments… add one }
  • Programster February 18, 2017, 8:10 am

    Thanks for the post. I wouldn’t have discovered “virsh domrename” otherwise which is soooo much easier!

  • Aram Iskenderian March 13, 2017, 2:52 am

    “Edit the XML file and change the name between the ”

    I would not recommend this.
    It is much safer to

    virsh edit

    That will land you in vi too, but the difference is, if you have a typing error, no changes will be saved.

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: , , , , ,