Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

238.2. libvirt-12.7.0

Virtualisation API and the libvirtd daemon, driving QEMU/KVM guests, networks and storage; virsh

Version 12.7.0, release 1
Shelf virt — Virtual machines, their tooling, and remote-desktop and VNC protocols
Phase 43_toolkits (Toolkits), 277 of 344 in build order
Licence LGPL-2.1-or-later AND GPL-2.0-or-later
Homepage https://libvirt.org
Build time 4.6 SBU
Installed size 22.4 MiB in 472 files
Recipe ports/core/virt/libvirt/kpkgbuild

About

libvirt is a library and a daemon, libvirtd, that manage virtual machines, their networks and their storage through one API, with virsh as its command line. In KDOS it drives QEMU/KVM guests, and it is what virt-manager talks to, through qemu:///system or qemu:///session. The package installs two services, 62_virtlogd and 63_libvirtd, and upstream’s polkit rule that lets members of the libvirt group manage system guests (see Services).

Sources

Dependencies

Depends on: meson, ninja, pkgconf, python3, perl, python3-docutils, libxml2, libxslt, glib, gnutls, libtirpc, rpcsvc-proto, json-c, libnl, libpcap, libpciaccess, eudev, util-linux, attr, acl, libcap-ng, cyrus-sasl, libssh2, readline, polkit, lvm2, parted, qemu, dnsmasq, nftables, iptables, iproute2, dmidecode, libiscsi, libnbd, nbdkit.

Required by (3): libvirt-glib, python3-libvirt, virt-manager.

Optional, off in KDOS

These switches in build.sh turn off a feature whose library is a port here. The recipe may turn each off on purpose, or because the library was not yet a port when the recipe was written; this list cannot tell which.

Installation

From the repository root, inside the build container, this is the line kdosbuild runs for the port:

script/chroot/exec.sh bash -c 'source script/phases/43_toolkits/phase.env && kpkg install libvirt'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/virt/libvirt.

1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.

cd /ports/core/virt/libvirt
echo '7ec1a04e7e4f4069353d4daac117bbe869287f5b202695de61fe1b079efb6cb6  libvirt-12.7.0.tar.xz' | sha256sum -c -

2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.

SRC_ROOT=/var/cache/kpkg/work/libvirt
SRC=$SRC_ROOT/libvirt-12.7.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf libvirt-12.7.0.tar.xz -C "$SRC" --strip-components=1

Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.

3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

meson setup build --prefix=/usr --sysconfdir=/etc --libdir=lib \
	--localstatedir=/var \
	--buildtype=release \
	-Drunstatedir=/run \
	-Dno_git=true \
	-Dgit_werror=disabled \
	-Drpath=disabled \
	-Dtests=disabled \
	-Dexpensive_tests=disabled \
	-Ddocs=enabled \
	-Dinit_script=none \
	-Dlibvirtd=enabled \
	-Ddriver_libvirtd=enabled \
	-Ddriver_remote=enabled \
	-Dremote_default_mode=legacy \
	-Ddriver_qemu=enabled \
	-Dqemu_user=qemu \
	-Dqemu_group=kvm \
	-Ddriver_network=enabled \
	-Ddriver_interface=enabled \
	-Ddriver_secrets=enabled \
	-Ddriver_test=enabled \
	-Ddriver_bhyve=disabled \
	-Ddriver_ch=disabled \
	-Ddriver_esx=disabled \
	-Ddriver_hyperv=disabled \
	-Ddriver_libxl=disabled \
	-Ddriver_lxc=disabled \
	-Ddriver_openvz=disabled \
	-Ddriver_vbox=disabled \
	-Ddriver_vmware=disabled \
	-Ddriver_vz=disabled \
	-Dstorage_dir=enabled \
	-Dstorage_fs=enabled \
	-Dstorage_disk=enabled \
	-Dstorage_lvm=enabled \
	-Dstorage_scsi=enabled \
	-Dstorage_mpath=enabled \
	-Dstorage_gluster=disabled \
	-Dstorage_iscsi=disabled \
	-Dstorage_iscsi_direct=enabled \
	-Dstorage_rbd=disabled \
	-Dstorage_vstorage=disabled \
	-Dstorage_zfs=disabled \
	-Dfirewalld=disabled \
	-Dfirewalld_zone=disabled \
	-Dfirewall_backend_priority=nftables \
	-Djson_c=enabled \
	-Dlibnl=enabled \
	-Dlibpcap=enabled \
	-Dpciaccess=enabled \
	-Dudev=enabled \
	-Dblkid=enabled \
	-Dattr=enabled \
	-Dcapng=enabled \
	-Dpolkit=enabled \
	-Dreadline=enabled \
	-Dsasl=enabled \
	-Dlibssh2=enabled \
	-Dlibssh=disabled \
	-Dcurl=disabled \
	-Dfuse=disabled \
	-Dglusterfs=disabled \
	-Dlibiscsi=enabled \
	-Dnetcf=disabled \
	-Dnumactl=disabled \
	-Dnumad=disabled \
	-Dopenwsman=disabled \
	-Dsanlock=disabled \
	-Dselinux=disabled \
	-Dsecdriver_selinux=disabled \
	-Dapparmor=disabled \
	-Dsecdriver_apparmor=disabled \
	-Dapparmor_profiles=disabled \
	-Daudit=disabled \
	-Ddtrace=disabled \
	-Dnbdkit=enabled \
	-Dnbdkit_config_default=disabled \
	-Dwireshark_dissector=disabled \
	-Dbash_completion=disabled \
	-Dhost_validate=enabled \
	-Dlogin_shell=disabled \
	-Dnss=disabled \
	-Dnls=disabled \
	-Dpm_utils=disabled \
	-Dssh_proxy=disabled \
	-Dsysctl_config=disabled
meson compile -C build
DESTDIR=$PKG meson install --no-rebuild -C build

rm -rf "$PKG/usr/lib/sysusers.d"

rm "$PKG/etc/libvirt/qemu/networks/autostart/default.xml"

rm -rf "$PKG/run"

install -d "$PKG/etc/nftables.d"
cat > "$PKG/etc/nftables.d/40-libvirt.nft" <<'NFT'
table inet filter {
	chain forward {
		iifname "virbr*" accept
	}

	chain input {
		iifname "virbr*" udp dport { 53, 67 } accept
		iifname "virbr*" tcp dport 53 accept
	}
}
NFT
chmod 644 "$PKG/etc/nftables.d/40-libvirt.nft"

install -d "$PKG/etc/init.d"
cat > "$PKG/etc/init.d/62_virtlogd.sh" <<'KDOS_SH'
#!/bin/bash
. /etc/init.d/service_helper

NAME="virtlogd"
DAEMON="/usr/sbin/virtlogd"

case "$1" in
    start)
        [ ! -x "$DAEMON" ] && { echo "[SKIP] $NAME: $DAEMON not found"; exit 0; }
        echo "[KDOS] Starting $NAME..."
        mkdir -p /run/libvirt
        supervise "$NAME" "$DAEMON" --pid-file /run/libvirt/virtlogd.pid
        ;;
    stop)   stop_service "$NAME" ;;
    status) check_status "$NAME" ;;
    *)      echo "Usage: $0 {start|stop|status}"; exit 1 ;;
esac
KDOS_SH
chmod 755 "$PKG/etc/init.d/62_virtlogd.sh"

cat > "$PKG/etc/init.d/63_libvirtd.sh" <<'KDOS_SH'
#!/bin/bash
. /etc/init.d/service_helper

NAME="libvirtd"
DAEMON="/usr/sbin/libvirtd"

case "$1" in
    start)
        [ ! -x "$DAEMON" ] && { echo "[SKIP] $NAME: $DAEMON not found"; exit 0; }
        echo "[KDOS] Starting $NAME..."
        mkdir -p /run/libvirt
        supervise "$NAME" "$DAEMON" --pid-file /run/libvirt/libvirtd.pid
        ;;
    stop)   stop_service "$NAME" ;;
    status) check_status "$NAME" ;;
    *)      echo "Usage: $0 {start|stop|status}"; exit 1 ;;
esac
KDOS_SH
chmod 755 "$PKG/etc/init.d/63_libvirtd.sh"

The switches, and why each is set:

The common switches of each build system are explained in the Flag glossary.

postinstall.sh runs on the installed system after the package is adopted:

root="${PKG_ROOT:-/}"
grep -q '^libvirt:' "$root/etc/group" 2>/dev/null || groupadd -R "$root" -r libvirt
grep -q '^qemu:' "$root/etc/passwd" 2>/dev/null || \
	useradd -R "$root" -r -g kvm -d /var/lib/libvirt -s /sbin/nologin qemu

4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/libvirt, prunes what the image does not ship, lints the tree and rolls it reproducibly:

tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
    --mtime=@$SOURCE_DATE_EPOCH \
    --use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
    -cf libvirt-12.7.0-1.tar.xz -C "$PKG" .

5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/libvirt, and runs the triggers its paths call for.

Contents

Installed programs: libvirtd, virsh, virt-admin, virt-host-validate, virt-pki-query-dn, virt-pki-validate, virt-qemu-qmp-proxy, virt-qemu-run, virt-qemu-sev-validate, virt-ssh-helper, virt-xml-validate, virtinterfaced, virtlockd, virtlogd, virtnetworkd, virtnodedevd, virtnwfilterd, virtproxyd, virtqemud, virtsecretd, virtstoraged.

Installed libraries: libvirt-admin.so, libvirt-lxc.so, libvirt-qemu.so, libvirt.so.

Installed directories: /etc/libvirt, /etc/logrotate.d, /etc/nftables.d, /etc/sasl2, /usr/include/libvirt, /usr/lib/libvirt, /usr/share/augeas, /usr/share/doc/libvirt, /usr/share/libvirt, /usr/share/licenses/libvirt, /var/cache/libvirt, /var/lib/libvirt, /var/log/libvirt, /var/log/swtpm.

Short descriptions

libvirtd libvirt management daemon
virsh management user interface
virt-admin daemon administration interface
virt-host-validate validate host virtualization setup
virt-pki-query-dn extract Distinguished Name from a PEM certificate
virt-pki-validate validate libvirt PKI files are configured correctly
virt-qemu-qmp-proxy Expose a QMP proxy server for a libvirt QEMU guest
virt-qemu-run Run a standalone QEMU guest
virt-qemu-sev-validate validate a domain AMD SEV launch measurement
virt-ssh-helper libvirt socket proxy
virt-xml-validate validate libvirt XML files against a schema
virtinterfaced libvirt host network interface management daemon
virtlockd libvirt lock management daemon
virtlogd libvirt log management daemon
virtnetworkd libvirt virtual network management daemon
virtnodedevd libvirt host device management daemon
virtnwfilterd libvirt network filter management daemon
virtproxyd libvirt proxy daemon
virtqemud libvirt QEMU management daemon
virtsecretd libvirt secret data management daemon
virtstoraged libvirt storage pool management daemon
libvirt.pc libvirt library
libvirt-admin.pc libvirt admin library
libvirt-lxc.pc libvirt LXC library
libvirt-qemu.pc libvirt QEMU library

Notes

build.sh deletes /usr/lib/sysusers.d, systemd’s account mechanism, which meson installs whatever -Dinit_script says; postinstall.sh makes the libvirt group and the qemu account instead. It also deletes the empty /run tree meson installs: /run is a tmpfs mounted over whatever the image holds there.

build.sh deletes /etc/libvirt/qemu/networks/autostart/default.xml, the link meson’s install script makes to the default network, and keeps the network itself in /etc/libvirt/qemu/networks/default.xml. With the link, every boot that starts libvirtd, the live medium’s included, brings up virbr0 at 192.168.122.1/24 with its dnsmasq whether or not any guest is ever run. Without it the network is defined and inactive: virt-manager offers to start it when a new guest is set up on it, and virsh net-start default starts it by hand, or virsh net-autostart default at every boot. No meson option leaves the link out.

/etc/nftables.d/40-libvirt.nft lets the NAT bridges (virbr0 for the default network) forward and reach their dnsmasq. libvirt’s own table accepts the guests’ traffic, but an accept ends only the chain that issued it, and the forward and input chains of /etc/nftables.conf drop what they were not told to pass. Without the file a guest boots, gets no DHCP lease and reaches nothing. The rules match only virbr*, and the file belongs to this package, so it goes when libvirt does (see /etc/nftables.conf).

virtlogd holds every QEMU guest’s console and log file open across a restart of libvirtd, and the QEMU driver refuses to start a system-mode guest when it cannot reach virtlogd’s socket, so 62_virtlogd comes before 63_libvirtd. Both run without --daemon, so the supervisor watches the daemon itself (see Supervision and logging). Both are also given --pid-file /run/libvirt/<name>.pid, which keeps each daemon’s own pid file in libvirt’s run directory rather than loose in /run; the supervisor keeps the service’s process id in /run/kdos-svc.<name>.pid. libvirtd opens its pid file before it creates /run/libvirt, so each script creates the directory first.