XML Format

This section describes the XML format used to represent domains, there arevariations on the format based on the kind of domains run and the optionsused to launch them:

The formats try as much as possible to follow the same structure and reuseelements and attributes where it makes sense.

Normal paravirtualized Xendomains:

The library use an XML format to describe domains, as input to virDomainCreateLinux()and as the output of virDomainGetXMLDesc(),the following is an example of the format as returned by the shell commandvirsh xmldump fc4, where fc4 was one of the running domains:

<domain type='xen' id='18'>
  <name>fc4</name>
  <os>
    <type>linux</type>
    <kernel>/boot/vmlinuz-2.6.15-1.43_FC5guest</kernel>
    <initrd>/boot/initrd-2.6.15-1.43_FC5guest.img</initrd>
    <root>/dev/sda1</root>
    <cmdline> ro selinux=0 3</cmdline>
  </os>
  <memory>131072</memory>
  <vcpu>1</vcpu>
  <devices>
    <disk type='file'>
      <source file='/u/fc4.img'/>
      <target dev='sda1'/>
    </disk>
    <interface type='bridge'>
      <source bridge='xenbr0'/>
      <mac address='aa:00:00:00:00:11'/>
      <script path='/etc/xen/scripts/vif-bridge'/>
    </interface>
    <console tty='/dev/pts/5'/>
  </devices>
</domain>

The root element must be called domainwith no namespace, thetypeattribute indicates the kind of hypervisor used, 'xen' isthe default value. The idattribute gives the domain id atruntime (not however that this may change, for example if the domain is savedto disk and restored). The domain has a few children whose order is notsignificant:

  • name: the domain name, preferably ASCII based
  • memory: the maximum memory allocated to the domain in kilobytes
  • vcpu: the number of virtual cpu configured for the domain
  • os: a block describing the Operating System, its content will bedependant on the OS type
    • type: indicate the OS type, always linux at this point
    • kernel: path to the kernel on the Domain 0 filesystem
    • initrd: an optional path for the init ramdisk on the Domain 0filesystem
    • cmdline: optional command line to the kernel
    • root: the root filesystem from the guest viewpoint, it may bepassed as part of the cmdline content too
  • devices: a list of disk, interfaceandconsoledescriptions in no special order

The format of the devices and their type may grow over time, but thefollowing should be sufficient for basic use:

A diskdevice indicates a block device, it can have twovalues for the type attribute either 'file' or 'block' corresponding to the 2options availble at the Xen layer. It has two mandatory children, and oneoptional one in no specific order:

  • source with a file attribute containing the path in Domain 0 to thefile or a dev attribute if using a block device, containing the devicename ('hda5' or '/dev/hda5')
  • target indicates in a dev attribute the device where it is mapped inthe guest
  • readonly an optional empty element indicating the device isread-only

An interfaceelement describes a network device mapped on theguest, it also has a type whose value is currently 'bridge', it also have anumber of children in no specific order:

  • source: indicating the bridge name
  • mac: the optional mac address provided in the address attribute
  • ip: the optional IP address provided in the address attribute
  • script: the script used to bridge the interfcae in the Domain 0
  • target: and optional target indicating the device name.

A consoleelement describes a serial console connection tothe guest. It has no children, and a single attribute ttywhichprovides the path to the Pseudo TTY on which the guest console can beaccessed

Life cycle actions for the domain can also be expressed in the XML format,they drive what should be happening if the domain crashes, is rebooted or ispoweroff. There is various actions possible when this happen:

  • destroy: The domain is cleaned up (that's the default normal processingin Xen)
  • restart: A new domain is started in place of the old one with the sameconfiguration parameters
  • preserve: The domain will remain in memory until it is destroyedmanually, it won't be running but allows for post-mortem debugging
  • rename-restart: a variant of the previous one but where the old domainis renamed before being saved to allow a restart

The following could be used for a Xen production system:

<domain>
  ...
  <on_reboot>restart</on_reboot>
  <on_poweroff>destroy</on_poweroff>
  <on_crash>rename-restart</on_crash>
  ...
</domain>

While the format may be extended in various ways as support for morehypervisor types and features are added, it is expected that this core subsetwill remain functional in spite of the evolution of the library.

Fully virtualized guests(added in 0.1.3):

Here is an example of a domain description used to start a fullyvirtualized (a.k.a. HVM) Xen domain. This requires hardware virtualizationsupport at the processor level but allows to run unmodified operatingsystems:

<domain type='xen' id='3'>
  <name>fv0</name>
  <uuid>4dea22b31d52d8f32516782e98ab3fa0</uuid>
  <os>
    <type>hvm</type>
    <loader>/usr/lib/xen/boot/hvmloader</loader>
    <boot dev='hd'/>
  </os>
  <memory>524288</memory>
  <vcpu>1</vcpu>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <features>
     <pae/>
     <acpi/>
     <apic/>
  </features>
  <devices>
    <emulator>/usr/lib/xen/bin/qemu-dm</emulator>
    <interface type='bridge'>
      <source bridge='xenbr0'/>
      <mac address='00:16:3e:5d:c7:9e'/>
      <script path='vif-bridge'/>
    </interface>
    <disk type='file'>
      <source file='/root/fv0'/>
      <target dev='hda'/>
    </disk>
    <disk type='file' device='cdrom'>
      <source file='/root/fc5-x86_64-boot.iso'/>
      <target dev='hdc'/>
      <readonly/>
    </disk>
    <disk type='file' device='floppy'>
      <source file='/root/fd.img'/>
      <target dev='fda'/>
    </disk>
    <graphics type='vnc' port='5904'/>
  </devices>
</domain>

There is a few things to notice specifically for HVM domains:

  • the optional <features>block is used to enablecertain guest CPU / system features. For HVM guests the followingfeatures are defined:
    • pae- enable PAE memory addressing
    • apic- enable IO APIC
    • acpi- enable ACPI bios
  • the <os>block description is very different, firstit indicates that the type is 'hvm' for hardware virtualization, theninstead of a kernel, boot and command line arguments, it points to an osboot loader which will extract the boot informations from the boot devicespecified in a separate boot element. The devattribute onthe boottag can be one of:
    • fd- boot from first floppy device
    • hd- boot from first harddisk device
    • cdrom- boot from first cdrom device
  • the <devices>section includes an emulator entrypointing to an additional program in charge of emulating the devices
  • the disk entry indicates in the dev target section that the emulationfor the drive is the first IDE disk device hda. The list of device namessupported is dependant on the Hypervisor, but for Xen it can be any IDEdevice hda-hdd, or a floppy devicefda, fdb. The <disk>elementalso supports a 'device' attribute to indicate what kinda of hardware toemulate. The following values are supported:
    • floppy- a floppy disk controller
    • disk- a generic hard drive (the default itomitted)
    • cdrom- a CDROM device
    For Xen 3.0.2 and earlier a CDROM device can only be emulated on thehdcchannel, while for 3.0.3 and later, it can be emulatedon any IDE channel.
  • the <devices>section also include at least oneentry for the graphic device used to render the os. Currently there isjust 2 types possible 'vnc' or 'sdl'. If the type is 'vnc', then anadditional portattribute will be present indicating the TCPport on which the VNC server is accepting client connections.

It is likely that the HVM description gets additional optional elementsand attributes as the support for fully virtualized domain expands,especially for the variety of devices emulated and the graphic supportoptions offered.

KVM domain (added in 0.2.0)

Support for the KVM virtualization is provided in recent Linux kernels (2.6.20 and onward). This requires specific hardware with acceleration support and the availability of the special version of the QEmu binary. Since this relies on QEmu for the machine emulation like fully virtualized guests the XML description is quite similar, here is a simple example:

<domain type='kvm'>
  <name>demo2</name>
  <uuid>4dea24b3-1d52-d8f3-2516-782e98a23fa0</uuid>
  <memory>131072</memory>
  <vcpu>1</vcpu>
  <os>
    <type>hvm</type>
  </os>
  <devices>
    <emulator>/home/user/usr/kvm-devel/bin/qemu-system-x86_64</emulator>
    <disk type='file' device='disk'>
      <source file='/home/user/fedora/diskboot.img'/>
      <target dev='hda'/>
    </disk>
    <interface type='user'>
      <mac address='24:42:53:21:52:45'/>
    </interface>
    <graphics type='vnc' port='-1'/>
  </devices>
</domain>

The specific points to note if using KVM are:

  • the top level domain element carries a type of 'kvm'
  • the <devices> emulator points to the special qemu binary required for KVM
  • networking interface definitions definitions are somewhat different due to a different model from Xen (@@TODO)

except those points the options should be quite similar to Xen HVM ones.

QEmu domain (added in 0.2.0)