Red Hat Enterprise Linux Diagnostics and Troubleshooting
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.
Begin by re-creating the issue. Note any errors, and try to interpret them.
Log in to
serveraand switch to therootuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#Define the virtual machine by using the
vm-guest1.xmlfile.[root@servera ~]#
virsh define vm-guest1.xmlerror: Failed to define machine from vm-guest1.xml error: (domain_definition):20: Opening and ending tag mismatch: acpi line 17 and features </features> -------------^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 thevm-guest1.xmlfile is malformed.
Locate and correct the XML errors in the
vm-guest1.xmlfile.Use the
xmllintcommand to locate errors in thevm-guest1.xmlfile. Remember that the first reported error can have a cascading effect; therefore fix errors one at a time, starting with the first error that thexmllintcommand reports.[root@servera ~]#
xmllint vm-guest1.xmlvm-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.Edit the file to close the unclosed tag on line 17 in the
vm-guest1.xmlfile:<acpi/>
Repeat the previous steps to locate and correct errors in the
vm-guest1.xmlfile.[root@servera ~]#
xmllint vm-guest1.xmlvm-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
xmllintcommand identifies an issue. In this output, it appears that there is a syntax issue near line132.Use your chosen editor to locate the error near line
132in thevm-guest1.xmlfile:<memballoon model='virtio'>
Run the
xmllintcommand 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>
Verify that the
vm-guest1.xmlfile now adheres to thelibvirtXML schema.[root@servera ~]#
virt-xml-validate vm-guest1.xmlvm-guest1.xml validatesDefine a virtual machine by using the
vm-guest1.xmlfile.[root@servera ~]#
virsh define vm-guest1.xmlDomain vm-guest1 defined from vm-guest1.xmlReturn to
workstationas thestudentuser.[root@servera ~]#
exit[student@servera ~]$exit[student@workstation ~]$