How to set the guest hardware time for QEMU from libvirt

libvirtqemu

I wish to set the virtualized hardware time to a fixed value upon
bootup. In Qemu, this is easy:

qemu-kvm \
    -rtc base=2011-11-11T11:11:00 \
    …

However I fail to see a way of adding this to a guest
configuration in libvirt (v2.2.0). Some of the
parameters

of Qemu appear to be supported, but it would appear that date
is not among them. Is there another way?

Best Answer

Turns out libvirt supports direct passing of command line arguments to the Qemu backend. In order to “unlock” this functionality, one needs to include the relevant namespace in the guest definition:

-<domain type='kvm'>
+<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>

Now one has access to the tag commandline. Inside it, arguments are specified using a series of arg elements:

<qemu:commandline>
  <qemu:arg value='-rtc'/>
  <qemu:arg value='base=2011-11-11T11:11:00'/>
</qemu:commandline>

That end up being appended to Qemu’s argv[].

Related Question