Bookmark this page

Guided Exercise: Resolving Virtualization Issues

Fix an invalid domain XML specification for a virtual machine.

Outcomes

You should be able to fix a malformed libvirt domain XML file.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

[student@workstation ~]$ lab start hardware-virtualization

Instructions

One of your colleagues is unable to import a virtual machine on the servera system. This virtual machine is defined in the /root/vm-guest1.xml file. Importing it with virsh define /root/vm-guest1.xml returns errors about a malformed XML file.

You are asked to investigate and fix this issue.

Important

For the purpose of this exercise, the virtual machine needs only to be defined, not started. The disk images that are referenced in the virtual machine definition do not exist, and do not need to be created.

  1. Begin by re-creating the issue. Note any errors, and try to interpret them.

    1. Log in to servera and switch to the root user.

      [student@workstation ~]$ ssh student@servera
      ...output omitted...
      [student@servera ~]$ sudo -i
      [sudo] password for student: student
      [root@servera ~]#
    2. Define the virtual machine by using the vm-guest1.xml file.

      [root@servera ~]# virsh define vm-guest1.xml
      error: Failed to define machine from vm-guest1.xml
      error: (domain_definition):20: Opening and ending tag mismatch: acpi line 17 and features
         </features>
      -------------^
    3. The first error, Failed to define domain, indicates that the operation did not successfully complete.

      The second error, Opening and ending tag mismatch, indicates that the XML in the vm-guest1.xml file is malformed.

  2. Locate and correct the XML errors in the vm-guest1.xml file.

    1. Use the xmllint command to locate errors in the vm-guest1.xml file. Remember that the first reported error can have a cascading effect; therefore fix errors one at a time, starting with the first error that the xmllint command reports.

      [root@servera ~]# xmllint vm-guest1.xml
      vm-guest1.xml:20: parser error : Opening and ending tag mismatch: acpi line 17 and features
        </features>
                   ^
      ...output omitted...

      It appears that an unclosed <acpi> tag exists on or around line 20.

    2. Edit the file to close the unclosed tag on line 17 in the vm-guest1.xml file:

      <acpi/>
    3. Repeat the previous steps to locate and correct errors in the vm-guest1.xml file.

      [root@servera ~]# xmllint vm-guest1.xml
      vm-guest1.xml:132: parser error : Unescaped '<' not allowed in attributes values
            <address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/
            ^
      ...output omitted...

      Errors might appear before where the xmllint command identifies an issue. In this output, it appears that there is a syntax issue near line 132.

    4. Use your chosen editor to locate the error near line 132 in the vm-guest1.xml file:

      <memballoon model='virtio'>
    5. Run the xmllint command again to verify that no more XML issues exist.

      [root@servera ~]# xmllint vm-guest1.xml
      <?xml version="1.0"?>
      <domain type="kvm">
        <name>vm-guest1</name>
        <uuid>9b94dde1-d145-45ee-8c65-0c133c3d5b01</uuid>
        <metadata>
          <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
            <libosinfo:os id="http://redhat.com/rhel/8.4"/>
          </libosinfo:libosinfo>
        </metadata>
        <memory unit="KiB">1048576</memory>
        <currentMemory unit="KiB">1048576</currentMemory>
        <vcpu placement="static">2</vcpu>
        <os>
          <type arch="x86_64" machine="pc-q35-5.2">hvm</type>
          <boot dev="hd"/>
        </os>
        <features>
          <acpi/>
          <apic/>
          <vmport state="off"/>
        </features>
      ...output omitted...
          <memballoon model="virtio">
            <address type="pci" domain="0x0000" bus="0x05" slot="0x00" function="0x0"/>
          </memballoon>
          <rng model="virtio">
            <backend model="random">/dev/urandom</backend>
            <address type="pci" domain="0x0000" bus="0x06" slot="0x00" function="0x0"/>
          </rng>
        </devices>
      </domain>
  3. Verify that the vm-guest1.xml file now adheres to the libvirt XML schema.

    [root@servera ~]# virt-xml-validate vm-guest1.xml
    vm-guest1.xml validates
  4. Define a virtual machine by using the vm-guest1.xml file.

    [root@servera ~]# virsh define vm-guest1.xml
    Domain vm-guest1 defined from vm-guest1.xml
  5. Return to workstation as the student user.

    [root@servera ~]# exit
    [student@servera ~]$ exit
    [student@workstation ~]$

Finish

On the workstation machine, use the lab command to complete this exercise. This is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish hardware-virtualization

Revision: rh342-8.4-6dd89bd