in Linux

RHEL7 rename VM in libvirt+KVM

Summary

I have created VM in libvirt + KVM under RHEL7 environment, but requires to rename the domain name of the VM, find out the way by export xml file, modify and import again, achieved the change domain name effect.

virsh command control

To start the Virtual Machine Manager

[root@localhost ~]# virt-manager 
[root@localhost ~]# 

The screenshot below shows the Virtual Machine Manager,
virt-manager command
To start, reboot, shutdown the guest machine.

[root@localhost ~]# virsh reboot Node1
Domain Node1 is being rebooted

[root@localhost ~]# virsh shutdown Node1
Domain Node1 is being shutdown

[root@localhost ~]# virsh start Node1
Domain Node1 started

[root@localhost ~]#

Requirement on change domain/VM name

My requirement on the virtual machine name as ‘node1’, however the name was wrongly created as ‘Node1’, the first letter is capital letter, should be small letter, wrong domain/VM name will cause the virtual machine to start fail, as the virsh command is case sensitive. as below command shows, so I need to change the domain/VM name from ‘Node1’ to ‘node1’.

[root@localhost ~]# virsh start node1
error: failed to get domain \'node1\'
error: Domain not found: no domain with matching name \'node1\'
[root@localhost ~]#

Procedure to change the domain / VM name

shutdown the virtual machine

[root@localhost ~]# virsh shutdown Node1
Domain Node1 is being shutdown

[root@localhost ~]#

dump xml to xml file

[root@localhost ~]# virsh dumpxml Node1 > node1.xml
[root@localhost ~]#

modify the xml file to change the domain/VM name

change the two lines, change the domain/VM name from ‘Node1’ to ‘node1’
<name>node1</name>
and
<source mode=\'bind\' path=\'/var/lib/libvirt/qemu/channel/target/domain-node1/org.qemu.guest_agent.0\'/>

After change the node1.xml is as below:

<domain type=\'kvm\' id=\'16\'>
  <name>node1</name>
  <uuid>b8a3a1af-f648-430c-b753-42b0bd9e3b82</uuid>
  <memory unit=\'KiB\'>524288</memory>
  <currentMemory unit=\'KiB\'>524288</currentMemory>
  <vcpu placement=\'static\'>1</vcpu>
  <resource>
    <partition>/machine</partition>
  </resource>
  <os>
    <type arch=\'x86_64\' machine=\'pc-i440fx-rhel7.0.0\'>hvm</type>
    <boot dev=\'hd\'/>
  </os>
  <features>
    <acpi/>
    <apic/>
  </features>
  <cpu mode=\'custom\' match=\'exact\'>
    <model fallback=\'allow\'>Broadwell</model>
  </cpu>
  <clock offset=\'utc\'>
    <timer name=\'rtc\' tickpolicy=\'catchup\'/>
    <timer name=\'pit\' tickpolicy=\'delay\'/>
    <timer name=\'hpet\' present=\'no\'/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <pm>
    <suspend-to-mem enabled=\'no\'/>
    <suspend-to-disk enabled=\'no\'/>
  </pm>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type=\'file\' device=\'disk\'>
      <driver name=\'qemu\' type=\'qcow2\'/>
      <source file=\'/var/lib/libvirt/images/node1.img\'/>
      <backingStore/>
      <target dev=\'vda\' bus=\'virtio\'/>
      <alias name=\'virtio-disk0\'/>
      <address type=\'pci\' domain=\'0x0000\' bus=\'0x00\' slot=\'0x07\' function=\'0x0\'/>
    </disk>
    <controller type=\'usb\' index=\'0\' model=\'ich9-ehci1\'>
      <alias name=\'usb\'/>
      <address type=\'pci\' domain=\'0x0000\' bus=\'0x00\' slot=\'0x06\' function=\'0x7\'/>
    </controller>
    <controller type=\'usb\' index=\'0\' model=\'ich9-uhci1\'>
      <alias name=\'usb\'/>
      <master startport=\'0\'/>
      <address type=\'pci\' domain=\'0x0000\' bus=\'0x00\' slot=\'0x06\' function=\'0x0\' multifunction=\'on\'/>
    </controller>
    <controller type=\'usb\' index=\'0\' model=\'ich9-uhci2\'>
      <alias name=\'usb\'/>
      <master startport=\'2\'/>
      <address type=\'pci\' domain=\'0x0000\' bus=\'0x00\' slot=\'0x06\' function=\'0x1\'/>
    </controller>
    <controller type=\'usb\' index=\'0\' model=\'ich9-uhci3\'>
      <alias name=\'usb\'/>
      <master startport=\'4\'/>
      <address type=\'pci\' domain=\'0x0000\' bus=\'0x00\' slot=\'0x06\' function=\'0x2\'/>
    </controller>
    <controller type=\'pci\' index=\'0\' model=\'pci-root\'>
      <alias name=\'pci.0\'/>
    </controller>
    <controller type=\'virtio-serial\' index=\'0\'>
      <alias name=\'virtio-serial0\'/>
      <address type=\'pci\' domain=\'0x0000\' bus=\'0x00\' slot=\'0x05\' function=\'0x0\'/>
    </controller>
    <interface type=\'network\'>
      <mac address=\'52:54:00:3a:47:12\'/>
      <source network=\'default\' bridge=\'virbr0\'/>
      <target dev=\'vnet0\'/>
      <model type=\'virtio\'/>
      <alias name=\'net0\'/>
      <address type=\'pci\' domain=\'0x0000\' bus=\'0x00\' slot=\'0x03\' function=\'0x0\'/>
    </interface>
    <serial type=\'pty\'>
      <source path=\'/dev/pts/5\'/>
      <target port=\'0\'/>
      <alias name=\'serial0\'/>
    </serial>
    <console type=\'pty\' tty=\'/dev/pts/5\'>
      <source path=\'/dev/pts/5\'/>
      <target type=\'serial\' port=\'0\'/>
      <alias name=\'serial0\'/>
    </console>
    <channel type=\'unix\'>
      <source mode=\'bind\' path=\'/var/lib/libvirt/qemu/channel/target/domain-node1/org.qemu.guest_agent.0\'/>
      <target type=\'virtio\' name=\'org.qemu.guest_agent.0\' state=\'disconnected\'/>
      <alias name=\'channel0\'/>
      <address type=\'virtio-serial\' controller=\'0\' bus=\'0\' port=\'1\'/>
    </channel>
    <channel type=\'spicevmc\'>
      <target type=\'virtio\' name=\'com.redhat.spice.0\' state=\'disconnected\'/>
      <alias name=\'channel1\'/>
      <address type=\'virtio-serial\' controller=\'0\' bus=\'0\' port=\'2\'/>
    </channel>
    <input type=\'tablet\' bus=\'usb\'>
      <alias name=\'input0\'/>
    </input>
    <input type=\'mouse\' bus=\'ps2\'/>
    <input type=\'keyboard\' bus=\'ps2\'/>
    <graphics type=\'vnc\' port=\'5900\' autoport=\'yes\' listen=\'127.0.0.1\' keymap=\'en-us\'>
      <listen type=\'address\' address=\'127.0.0.1\'/>
    </graphics>
    <sound model=\'ich6\'>
      <alias name=\'sound0\'/>
      <address type=\'pci\' domain=\'0x0000\' bus=\'0x00\' slot=\'0x04\' function=\'0x0\'/>
    </sound>
    <video>
      <model type=\'qxl\' ram=\'65536\' vram=\'65536\' vgamem=\'16384\' heads=\'1\'/>
      <alias name=\'video0\'/>
      <address type=\'pci\' domain=\'0x0000\' bus=\'0x00\' slot=\'0x02\' function=\'0x0\'/>
    </video>
    <redirdev bus=\'usb\' type=\'spicevmc\'>
      <alias name=\'redir0\'/>
    </redirdev>
    <redirdev bus=\'usb\' type=\'spicevmc\'>
      <alias name=\'redir1\'/>
    </redirdev>
    <memballoon model=\'virtio\'>
      <alias name=\'balloon0\'/>
      <address type=\'pci\' domain=\'0x0000\' bus=\'0x00\' slot=\'0x08\' function=\'0x0\'/>
    </memballoon>
  </devices>
  <seclabel type=\'dynamic\' model=\'selinux\' relabel=\'yes\'>
    <label>system_u:system_r:svirt_t:s0:c368,c972</label>
    <imagelabel>system_u:object_r:svirt_image_t:s0:c368,c972</imagelabel>
  </seclabel>
</domain>

Undefine old virtual machine

[root@localhost ~]# virsh undefine Node1
Domain Node1 has been undefined

[root@localhost ~]#

Define new virtual machine

[root@localhost ~]# virsh define node1.xml
Domain node1 defined from node1.xml

[root@localhost ~]#

Start the new VM by command, the whole procedure completed,

[root@localhost ~]# virsh start node1
Domain node1 started

[root@localhost ~]#

The result screenshot is as below,
change VM name result

Write a Comment

Comment

fourteen + ten =