wiki/xml.md

247 lines
8.5 KiB
Markdown
Raw Normal View History

2021-08-12 09:43:26 +00:00
---
title: XML commented
description: An XML file describing a virtual machine
published: true
2021-08-12 10:02:27 +00:00
date: 2021-08-12T10:02:24.355Z
2021-08-12 09:43:26 +00:00
tags:
editor: markdown
dateCreated: 2021-08-12T09:43:20.587Z
---
# Libvirt-based XML file commented
## Dumping XML description
> **Requirements** : To dump the XML configuration of an existing virtual machine to a file, make sure your current user is part of the *libvirt* group and has access to the virtual machine.
{.is-info}
Any XML configuration associated to the a specific virtual machine can be dumped to a file using the following command :
```
$ virsh dumpxml {VM_NAME} > {VM_NAME}.xml
```
### Example
* List current virtual machines
```
$ virsh list --all
Id Name State
-------------------------------------------
- phyllome shut off
```
* Dump the XML description of the phyllome machine to a file
```
$ virsh dumpxml phyllome > phyllome.xml
```
## XML commented
This is the description of an XML file associated to a virtio-based virtual machine. Only relevant features to Phyllome are commented.
```
<!-- Domain type refers to the kind of hypervisor in use. Instead of only relying on kvm, we add the xmlns:qemu bits, which allow us to extend <domain type='kvm'>, and most notably to add specific qemu-command at the end of the file -->
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<!-- The name of the virtual machine must be unique. Intendation matters -->
<name>phyllome</name>
<!-- The Universally Unique Identifier (UUID) must be unique (ahem). It can be generated using the uuidgen command line tool. -->
<uuid>12345678-1234-1234-1234-12345678912</uuid>
<!-- Metada are information on the virtual machine itself, its user-generated description or the kind of operating system it runs -->
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
<libosinfo:os id="http://fedoraproject.org/fedora/34"/>
</libosinfo:libosinfo>
</metadata>
<!-- Memory allocated to the virtual machine. An upward limit can be set by the "memory" line. If the guest OS supports it, you may set the currentMemory value bellow the memory. -->
<memory unit='KiB'>4145152</memory>
<currentMemory unit='KiB'>4145152</currentMemory>
<!-- vcpu assignement can either be dynamic or static -->
<vcpu placement='static'>2</vcpu>
<!-- Architecture and machine type. Here, an x86-64 PCI-express Q35 based machine is being used -->
<os>
<type arch='x86_64' machine='pc-q35-5.2'>hvm</type>
<!-- UEFI-based loader -->
<loader readonly='yes' type='pflash'>/usr/share/edk2/ovmf/OVMF_CODE.fd</loader>
<nvram>/var/lib/libvirt/qemu/nvram/phyllome.fd</nvram>
<bootmenu enable='no'/>
</os>
<!-- Specific features for the machine. It equates to UEFI settings-->
<features>
<acpi/>
<apic/>
<vmport state='off'/>
<ioapic driver='qemu'/>
</features>
<!-- CPU mode -->
<cpu mode='host-model' check='partial'/>
<!-- Insert comment here -->
<clock offset='utc'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
</clock>
<!-- Insert comment here -->
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<!-- Insert comment here -->
<pm>
<suspend-to-mem enabled='no'/>
<suspend-to-disk enabled='no'/>
</pm>
<!-- Insert comment here -->
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<!-- Virtio-based disk image using the raw format -->
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/var/lib/libvirt/images/phyllome.img'/>
<target dev='vda' bus='virtio'/>
<boot order='1'/>
<address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
</disk>
<!-- Emulated USB 3 controller -->
<controller type='usb' index='0' model='qemu-xhci' ports='15'>
<address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
</controller>
2021-08-12 10:02:27 +00:00
<!-- SCSI controller -->
2021-08-12 10:00:23 +00:00
<controller type='scsi' index='0'>
2021-08-12 09:43:26 +00:00
<address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
</controller>
2021-08-12 10:00:23 +00:00
<!-- PCI-root -->
<controller type='pci' index='0' model='pcie-root'/>
2021-08-12 10:02:27 +00:00
<!-- PCI-express slots. 8 are created. Only two are shown -->
2021-08-12 10:00:23 +00:00
<controller type="pci" index="1" model="pcie-root-port">
<model name="pcie-root-port"/>
<target chassis="1" port="0x10"/>
<address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x0" multifunction="on"/>
</controller>
<controller type="pci" index="2" model="pcie-root-port">
<model name="pcie-root-port"/>
<target chassis="2" port="0x11"/>
<address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x1"/>
</controller>
2021-08-12 09:43:26 +00:00
<!-- Insert comment here -->
<controller type='virtio-serial' index='0'>
<address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
</controller>
<!-- Virtio-based network device using NAT -->
<interface type='network'>
<mac address='52:54:00:6d:5d:e2'/>
<source network='default'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</interface>
<!-- Insert comment here -->
<channel type='unix'>
<target type='virtio' name='org.qemu.guest_agent.0'/>
<address type='virtio-serial' controller='0' bus='0' port='1'/>
</channel>
<!-- Insert comment here -->
<channel type='spicevmc'>
<target type='virtio' name='com.redhat.spice.0'/>
<address type='virtio-serial' controller='0' bus='0' port='2'/>
</channel>
<!-- Legacy PS/2 input mouse input device. Hard-coded on QEMU -->
<input type='mouse' bus='ps2'/>
<!-- Legacy PS/2 input mouse input device. Hard-coded on QEMU -->
<input type='keyboard' bus='ps2'/>
2021-08-12 09:55:28 +00:00
<!-- Virtio-input mouse device -->
<input type="tablet" bus="virtio">
2021-08-12 09:43:26 +00:00
<address type="pci" domain="0x0000" bus="0x01" slot="0x00" function="0x0"/>
</input>
2021-08-12 09:55:28 +00:00
<!-- Virtio-input keyboard device -->
2021-08-12 09:43:26 +00:00
<input type="keyboard" bus="virtio">
<address type="pci" domain="0x0000" bus="0x07" slot="0x00" function="0x0"/>
</input>
2021-08-12 10:02:27 +00:00
<!-- Output the guest display to Spice, for local use only. Use image compression and OpenGL (Only works with Intel GPUs, perhaps AMD ones too) -->
2021-08-12 09:43:26 +00:00
<graphics type='spice'>
<listen type='none'/>
2021-08-12 09:55:28 +00:00
<image compression="auto_glz"/>
<jpeg compression="auto"/>
<zlib compression="auto"/>
<playback compression="on"/>
<image compression='off'/>
2021-08-12 09:43:26 +00:00
<gl enable='yes' rendernode='/dev/dri/by-path/pci-0000:00:02.0-render'/>
</graphics>
2021-08-12 09:55:28 +00:00
<!-- Virtio-gpu device with 3D acceleration -->
2021-08-12 09:43:26 +00:00
<video>
<model type='virtio' heads='1' primary='yes'>
<acceleration accel3d='yes'/>
</model>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
</video>
2021-08-12 09:55:28 +00:00
<!-- Virtio-based memballoon device, to allow memory to grow dynamically in a virtual machine. For Windows-guests, it is better to turn this feature off -->
2021-08-12 09:43:26 +00:00
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>
</memballoon>
2021-08-12 09:55:28 +00:00
<!-- Virtio random number generator -->
2021-08-12 09:43:26 +00:00
<rng model='virtio'>
<backend model='random'>/dev/urandom</backend>
<address type='pci' domain='0x0000' bus='0x06' slot='0x00' function='0x0'/>
</rng>
2021-08-12 09:55:28 +00:00
<!-- Virtio-iommu device, compatible with AMD and Intel CPUs -->
<iommu model='intel'>
2021-08-12 09:43:26 +00:00
<driver intremap='on' iotlb='on'/>
</iommu>
2021-08-12 09:55:28 +00:00
<!-- End of device section -->
2021-08-12 09:43:26 +00:00
</devices>
2021-08-12 09:55:28 +00:00
<!-- Start of qemu:commandline section. Requires <domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'> at the beginning of the XML file -->
2021-08-12 09:43:26 +00:00
<qemu:commandline>
<qemu:env name="DISPLAY" value=":1"/>
<qemu:env name="GDK_SCALE" value="1.0"/>
<qemu:env name='INTEL_DEBUG' value='norbc'/>
<qemu:arg value='-set'/>
<qemu:arg value='device.hostdev0.x-igd-opregion=on'/>
<qemu:arg value="-set"/>
<qemu:arg value='device.hostdev0.driver=vfio-pci-nohotplug'/>
<qemu:arg value='-set'/>
<qemu:arg value='device.hostdev0.ramfb=on'/>
<qemu:arg value='-set'/>
<qemu:arg value="device.hostdev0.display=on"/>
<qemu:arg value='-set'/>
<qemu:arg value="-display"/>
<qemu:arg value='-set'/>
<qemu:arg value="gtk,gl=on"/>
<qemu:arg value='-set'/>
</qemu:commandline>
2021-08-12 09:55:28 +00:00
<!-- End of domain section. -->
2021-08-12 09:43:26 +00:00
</domain>
```
## Reference
For a more thorough description, see https://libvirt.org/formatdomain.html