Renaming KVM Virtual Guest Running on RHEL
This below docs covers how to rename any of the guest running on RHL5.4 and later KVM+libvirt Host
Log in as root on the Host because Most of below virsh commands require root privileges to run due to the communications channels used to talk to the hypervisor. Running as non root will return an error.
Then run the virsh - management user interface tool from the command line
What is virsh?
The virsh program is the main interface for managing virsh guest domains. The program can be used to create, pause, and shutdown domains.
The basic structure of most virsh usage is:
virsh <command> <domain-id> [OPTIONS]
Where command is one of the commands listed below, domain-id is the numeric domain id, or the domain name (which will be internally translated to domain id), and OPTIONS are command specific options.
The virsh program can be used either to run one command at a time by giving the command as an argument on the command line, or as a shell if no command is given in the command line, it will then start a minimal interpreter waiting for your commands and the quit command will then exit the program.
After execute the "list" command it will list all the running guest with Name is the name of the domain. ID the domain numeric id. State is the run state . If you want to list all the guest run "list --all" inside a virsh shell
In our next step we are going to select the guest we wish to rename in our case its RHEL6-JON with the ID 11 and its in running state .
[root@kvm7-hp-dl-380G6 ~]# virsh
Welcome to virsh, the virtualization interactive terminal.
Type: 'help' for help with commands
'quit' to quit
virsh # list
Id Name State
----------------------------------
4 RHEVM2.2-Win2k8R2 running
11 RHEL6-JON running
virsh # list --all
Id Name State
----------------------------------
4 RHEVM2.2-Win2k8R2 running
11 RHEL6-JON running
- Win2k3 shut off
- RHEL-WEB shut off
virsh # edit 11 (it will open the guest xml file in vi editor modify the name and save it)
<domain type='kvm'>
<name>RHEL6-JON</name> --->change the name from RHEL6-JON to RHEL6-X86_64_JON and save it
<uuid>3a0a2cb7-095a-8ad9-624c-5163cf52692a</uuid>
<memory>1048576</memory>
<currentMemory>1048576</currentMemory>
virsh # edit 11
error: operation failed: domain 'RHEL6-JON' is already defined with uuid 3a0a2cb7-095a-8ad9-624c-5163cf52692a
The above error is exactly the expected behavior. virsh edit does not support changing the name or UUID. If you want to change either of those, you'll need to the following.
Shut down the vm using the virsh command line or using virt-manager
#virsh shutdown RHEL6-JON
Change to the directory
cd /etc/libvirt/qemu/
An easy way to obtain the definition of a pre-existing guest is by using dumpxml command.
# virsh dumpxml RHEL6-JON > RHEL6-X86_64_JON.xml
Now Undefine the configuration for an inactive guest (RHEL6-JON)
[root@kvm7-hp-dl-380G6 qemu]# virsh undefine RHEL6-JON
Domain RHEL6-JON has been undefined
Now edit the new xml file and save it
[root@kvm7-hp-dl-380G6 qemu]# vi RHEL6-X86_64_JON.xml
<domain type='kvm'>
<name>RHEL6-X86_64_JON</name> --> RHEL6-JON was replaced by RHEL6-X86_64_JON
<uuid>3a0a2cb7-095a-8ad9-624c-5163cf52692a</uuid>
Once you saved it Define a new domain from an XML (RHEL6-X86_64_JON.xml)
[root@kvm7-hp-dl-380G6 qemu]# virsh define RHEL6-X86_64_JON.xml
Domain RHEL6-X86_64_JON defined from RHEL6-X86_64_JON.xml
Now go to virt-manager or visrh command line and start the renamed guest.
#virsh start RHEL6-X86_64_JON
[root@kvm7-hp-dl-380G6 qemu]# virsh list --all
Id Name State
----------------------------------
4 RHEVM2.2-Win2k8R2 running
5 RHEL6-X86_64_JON running
This below docs covers how to rename any of the guest running on RHL5.4 and later KVM+libvirt Host
Log in as root on the Host because Most of below virsh commands require root privileges to run due to the communications channels used to talk to the hypervisor. Running as non root will return an error.
Then run the virsh - management user interface tool from the command line
What is virsh?
The virsh program is the main interface for managing virsh guest domains. The program can be used to create, pause, and shutdown domains.
The basic structure of most virsh usage is:
virsh <command> <domain-id> [OPTIONS]
Where command is one of the commands listed below, domain-id is the numeric domain id, or the domain name (which will be internally translated to domain id), and OPTIONS are command specific options.
The virsh program can be used either to run one command at a time by giving the command as an argument on the command line, or as a shell if no command is given in the command line, it will then start a minimal interpreter waiting for your commands and the quit command will then exit the program.
After execute the "list" command it will list all the running guest with Name is the name of the domain. ID the domain numeric id. State is the run state . If you want to list all the guest run "list --all" inside a virsh shell
In our next step we are going to select the guest we wish to rename in our case its RHEL6-JON with the ID 11 and its in running state .
[root@kvm7-hp-dl-380G6 ~]# virsh
Welcome to virsh, the virtualization interactive terminal.
Type: 'help' for help with commands
'quit' to quit
virsh # list
Id Name State
----------------------------------
4 RHEVM2.2-Win2k8R2 running
11 RHEL6-JON running
virsh # list --all
Id Name State
----------------------------------
4 RHEVM2.2-Win2k8R2 running
11 RHEL6-JON running
- Win2k3 shut off
- RHEL-WEB shut off
virsh # edit 11 (it will open the guest xml file in vi editor modify the name and save it)
<domain type='kvm'>
<name>RHEL6-JON</name> --->change the name from RHEL6-JON to RHEL6-X86_64_JON and save it
<uuid>3a0a2cb7-095a-8ad9-624c-5163cf52692a</uuid>
<memory>1048576</memory>
<currentMemory>1048576</currentMemory>
virsh # edit 11
error: operation failed: domain 'RHEL6-JON' is already defined with uuid 3a0a2cb7-095a-8ad9-624c-5163cf52692a
The above error is exactly the expected behavior. virsh edit does not support changing the name or UUID. If you want to change either of those, you'll need to the following.
Shut down the vm using the virsh command line or using virt-manager
#virsh shutdown RHEL6-JON
Change to the directory
cd /etc/libvirt/qemu/
An easy way to obtain the definition of a pre-existing guest is by using dumpxml command.
# virsh dumpxml RHEL6-JON > RHEL6-X86_64_JON.xml
Now Undefine the configuration for an inactive guest (RHEL6-JON)
[root@kvm7-hp-dl-380G6 qemu]# virsh undefine RHEL6-JON
Domain RHEL6-JON has been undefined
Now edit the new xml file and save it
[root@kvm7-hp-dl-380G6 qemu]# vi RHEL6-X86_64_JON.xml
<domain type='kvm'>
<name>RHEL6-X86_64_JON</name> --> RHEL6-JON was replaced by RHEL6-X86_64_JON
<uuid>3a0a2cb7-095a-8ad9-624c-5163cf52692a</uuid>
Once you saved it Define a new domain from an XML (RHEL6-X86_64_JON.xml)
[root@kvm7-hp-dl-380G6 qemu]# virsh define RHEL6-X86_64_JON.xml
Domain RHEL6-X86_64_JON defined from RHEL6-X86_64_JON.xml
Now go to virt-manager or visrh command line and start the renamed guest.
#virsh start RHEL6-X86_64_JON
[root@kvm7-hp-dl-380G6 qemu]# virsh list --all
Id Name State
----------------------------------
4 RHEVM2.2-Win2k8R2 running
5 RHEL6-X86_64_JON running
3 comments:
thanks for your blog. It helped me a lot.
The only suggestion I have is that you might want to label the steps. I missed the "undefine" step and it complains -- but not a big deal.
Your blog is the 3rd on the list when I googled with "rename a vm kvm"
Great blog. Thanks!
Yi
Nice article. Very good explanations.
There are a lot management tools that will make KVM deployment easier and quicker:
http://www.linux-kvm.org/page/Management_Tools
Since IBM and Redhat start to endorse KVM, many companies are deploying KVM cloud farms now.
Here are some Unix Benchmarks test scores to show KVM virtual machines perform better than average standalone servers:
KVM Performance Data
Nice blog. solved my problem.
Post a Comment