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
libvirt-12.7.0.tar.xz(10.2 MiB)
sha2567ec1a04e7e4f4069353d4daac117bbe869287f5b202695de61fe1b079efb6cb6
upstream: https://download.libvirt.org/libvirt-12.7.0.tar.xz
archive copy: sources-4/virt--libvirt-12.7.0.tar.xz
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.
-Dlibssh=disabled, line 71: libssh-Dcurl=disabled, line 72: curl-Dfuse=disabled, line 73: fuse-Dnumactl=disabled, line 77: numactl (explained with the switches below)-Dbash_completion=disabled, line 91: bash-completion-Dnss=disabled, line 94: nss (explained with the switches below)
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:
-Dremote_default_mode=legacy— clients connect tolibvirtd’s socket. The default,direct, makes them connect tovirtqemudand the other per-driver daemons, which nothing in KDOS starts, so everyqemu:///systemconnection would fail with the socket missing.-Dinit_script=none— install no init scripts of upstream’s (systemd or OpenRC);build.shwrites KDOS’s own two.-Dqemu_user=qemu— with-Dqemu_group=kvm: system-mode guests run as their own account rather than as root, and libvirt’s DAC driver gives each guest’s disk images to that account.postinstall.shcreatesqemuwithkvmas its group, the group udev gives/dev/kvm.-Ddriver_qemu=enabled— with the other drivers namedenabled: the QEMU driver, the remote driver andlibvirtd, the NAT and bridge network driver (with dnsmasq for DHCP and DNS), host interfaces through udev, secrets, and the test driver virt-manager opens astest:///default.-Ddriver_bhyve=disabled— and every other hypervisor driver nameddisabled(Cloud Hypervisor, ESX, Hyper-V, libxl, LXC, OpenVZ, VirtualBox, VMware, Virtuozzo): left toauto, each would be built whenever its probe happened to succeed.-Dstorage_dir=enabled— with-Dstorage_fs,-Dstorage_disk,-Dstorage_lvm,-Dstorage_scsi,-Dstorage_mpathand-Dstorage_iscsi_direct: storage pools in directories, file systems, whole disks, LVM, SCSI hosts, multipath devices, and iSCSI targets reached through libiscsi.-Dstorage_iscsi=disabled— no iSCSI pool throughiscsiadm, which needs open-iscsi, not a port;iscsi-directis the iSCSI pool.-Dstorage_gluster=disabled— with-Dstorage_rbd,-Dstorage_vstorageand-Dstorage_zfsdisabled, and-Dglusterfs,-Dnetcf,-Dnumad,-Dopenwsman,-Dsanlock,-Daudit,-Dselinux,-Dapparmorand-Ddtrace: backends and features whose library or tools are not ports.-Dnumactl=disabled— with-Dlibssh,-Dcurl,-Dfuse,-Dwireshark_dissectorand-Dbash_completiondisabled: no NUMA placement of guests, no libssh transport (-Dlibssh2is the SSH transport), no curl or FUSE support, no Wireshark dissector for libvirt’s protocol, and no bash completion. Each library is a port the build does not link.-Dfirewall_backend_priority=nftables— with-Dfirewalld=disabled: the network driver writes its rules into an nftables table of its own beside/etc/nftables.conf. nwfilter still runsebtables,iptablesandip6tables, the nftables-backed commands of the iptables port.-Dnbdkit=enabled— with-Dnbdkit_config_default=disabled: the QEMU driver can start nbdkit to serve a guest’s network disk to QEMU, and checks its socket through libnbd, whenstorage_use_nbdkitinqemu.confasks for it; QEMU’s own block drivers stay the default.-Dnbdkit=enabledfails the configure if libnbd is missing.-Ddocs=enabled— build the manual pages (virsh(1)and the rest) withrst2manandxsltproc, and generate/usr/share/libvirt/api/libvirt-api.xml. The Python binding generates itself from that file and cannot be built without it.-Dnss=disabled— nolibnss_libvirt, a glibc NSS module; musl has no NSS to load it into.-Dssh_proxy=disabled— no ssh-proxy for SSH over vsock, which writes a client configuration under/etc/ssh.-Dsysctl_config=disabled— no/usr/lib/sysctl.d/60-libvirtd.conf, which raisesfs.aio-max-nrfor hosts with many guest disks. The kernel’s default is enough for the handful of guests a desktop runs, and10_sysctlrunssysctl --system, so the file would take effect at every boot on every machine with libvirt installed, guests or none.-Dhost_validate=enabled— buildvirt-host-validate, which checks the host for what each driver needs.-Dlogin_shell=disabled— with-Dpm_utils=disabled: novirt-login-shell, and no pm-utils for host suspend.-Dno_git=true— with-Dgit_werror=disabled: do not update git submodules, and do not add-Werroras a build from git would.-Drunstatedir=/run— the run-time state directory; each daemon creates its own under/run/libvirtwhen it starts.
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.