Blog

03/06/2019

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.

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

Posted by: SXI ADMIN

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

14/08/2019

How to KVM, QEMU start or stop virtual machine from command line (CLI)

KVM or Kernel Based Virtual Machine is a popular virtualization technology. It allows you to run virtual guest machines over a host machine. To start...
14/08/2019

How to Docker backup Saving and restoring your volumes

Running a Docker volume backup First, we spin up a temporary container, and we mount the backup folder and the target Docker volume to this container....
12/08/2019

How to Start and Enable Firewalld on CentOS 7

In this article, we discuss how to start and enable firewalld. It is highly recommended that you have a firewall protecting your server.Pre-Flight CheckThese...