238.1. qemu-11.1.1
Machine emulator and virtualiser
| Version | 11.1.1, release 2 |
| Shelf | virt — Virtual machines, their tooling, and remote-desktop and VNC protocols |
| Phase | 43_toolkits (Toolkits), 276 of 344 in build order |
| Licence | GPL-2.0-only AND LGPL-2.1-or-later |
| Homepage | https://www.qemu.org/ |
| Build time | 22.4 SBU |
| Installed size | 294.0 MiB in 107 files |
| Recipe | ports/core/virt/qemu/kpkgbuild |
About
QEMU emulates a whole machine, and with KVM runs one at the speed of the host processor. A container shares the host’s kernel, so QEMU is what KDOS has for running another operating system: testing a kernel, opening a disk image whose contents are not trusted, booting the installer of another distribution. It is the emulator under libvirt and virt-manager, and QEMU is also what KDOS’s own test rig drives. The port builds three system emulators, the tools (among them qemu-img, qemu-io, qemu-nbd, qemu-storage-daemon, and qemu-vnc, a standalone VNC server for a D-Bus display), and the guest firmware those emulators boot, compiled from the sources in the tarball’s roms/.
Why it is in KDOS
The comment above it in script/phases/43_toolkits/packages.d/virt.txt:
Containers share the host kernel, so nothing else on the image could run another OS — test a kernel, open an untrusted disk image, boot the installer of the distro being migrated from. KDOS's own test rig boots the system under qemu.
Sources
qemu-11.1.1.tar.xz(135.3 MiB)
sha256079ffbff8a7111bbc89022107cbabf3bbfd614d5fc9d7cc675991196aca12482
upstream: https://download.qemu.org/qemu-11.1.1.tar.xz
archive copy: sources-4/virt--qemu-11.1.1.tar.xz
Dependencies
Depends on: meson, ninja, pkgconf, python3, glib, pixman, zlib, zstd, libslirp, libaio, ncurses, libpng, libjpeg-turbo, gnutls, libusb, libcap-ng, python3-wheel, dtc, curl, bzip2, lzo, eudev, elfutils, libseccomp, alsa-lib, pipewire, fuse, libbpf, cyrus-sasl, passt, liburing, capstone, acpica, nasm, clang, lld, llvm, perl, util-linux, xz, gtk3, vte3, libX11, sdl2-compat, libepoxy, mesa, spice, spice-protocol, usbredir, libcacard, libiscsi.
Required by (2): 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.
--disable-nettle, line 78: nettle (explained with the switches below)--disable-gcrypt, line 79: libgcrypt--disable-numa, line 83: numactl--disable-libnfs, line 86: libnfs (explained with the switches below)--disable-libssh, line 87: libssh--disable-snappy, line 90: snappy--disable-libcbor, line 112: libcbor--disable-xkbcommon, line 114: libxkbcommon--disable-libkeyutils, line 115: keyutils
Patches
build.sh applies these; kpkg applies nothing by itself.
edk2-gcc-no-werror.patch— adds-Wno-errorafter the-WerrorinGCC_ALL_CC_FLAGSof edk2’stools_def.template, which neither edk2’s build command nor the platform files can reach. It is applied beforeefirom, because that step runs edk2’s setup, which copies those flags intoConf/tools_def.txt, and every later edk2 build reads the copy (see An upstream-Werror).ipxe-arch-i386.patch— puts a.code16or.code32directive ahead of.arch i386or.arch i586in the x86 assembly files iPXE shares between its BIOS and x86_64 EFI builds, and drops the directive from the two stack files. GNU as 2.41 and later reject those.archlines while the assembler is still in 64-bit mode, so without the patch every one of these files fails in thebin-x86_64-efibuild theefi-*.romNIC option ROMs come from.
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 qemu'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/virt/qemu.
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/qemu
echo '079ffbff8a7111bbc89022107cbabf3bbfd614d5fc9d7cc675991196aca12482 qemu-11.1.1.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/qemu
SRC=$SRC_ROOT/qemu-11.1.1
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf qemu-11.1.1.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:
./configure \
--prefix=/usr \
--sysconfdir=/etc \
--localstatedir=/var \
--libexecdir=/usr/lib/qemu \
--target-list=x86_64-softmmu,aarch64-softmmu,riscv64-softmmu \
--enable-kvm \
--enable-curses \
--enable-vnc \
--enable-slirp \
--enable-linux-aio \
--enable-linux-io-uring \
--enable-virtfs \
--enable-tools \
--enable-gnutls \
--enable-cap-ng \
--enable-libusb \
--enable-pixman \
--enable-png \
--enable-vnc-jpeg \
--enable-zstd \
--enable-fdt=system \
--enable-curl \
--enable-bzip2 \
--enable-lzo \
--enable-libudev \
--enable-libdw \
--enable-capstone \
--enable-bpf \
--enable-fuse \
--enable-fuse-lseek \
--enable-vnc-sasl \
--enable-gio \
--enable-dbus-display \
--enable-qemu-vnc \
--enable-passt \
--enable-tpm \
--enable-attr \
--enable-iconv \
--enable-slirp-smbd \
--enable-stack-protector \
--enable-multiprocess \
--enable-hv-balloon \
--enable-vhost-kernel \
--enable-vhost-net \
--enable-vhost-user \
--enable-vhost-crypto \
--enable-vhost-vdpa \
--enable-vhost-user-blk-server \
--enable-libvduse \
--enable-vduse-blk-export \
--enable-l2tpv3 \
--enable-keyring \
--enable-replication \
--enable-colo-proxy \
--enable-bochs \
--enable-cloop \
--enable-dmg \
--enable-qcow1 \
--enable-vdi \
--enable-vhdx \
--enable-vmdk \
--enable-vpc \
--enable-vvfat \
--enable-qed \
--enable-parallels \
--disable-nettle \
--disable-gcrypt \
--disable-malloc-trim \
--disable-gettext \
--disable-selinux \
--disable-numa \
--disable-mpath \
--enable-libiscsi \
--disable-libnfs \
--disable-libssh \
--disable-rbd \
--disable-rdma \
--disable-snappy \
--disable-lzfse \
--disable-vde \
--disable-netmap \
--disable-blkio \
--disable-libdaxctl \
--disable-libpmem \
--disable-qpl \
--disable-uadk \
--disable-qatzip \
--disable-af-xdp \
--disable-igvm \
--enable-usb-redir \
--enable-smartcard \
--disable-u2f \
--disable-canokey \
--enable-spice-protocol \
--disable-rutabaga-gfx \
--disable-oss \
--disable-sparse \
--disable-auth-pam \
--disable-brlapi \
--disable-libcbor \
--disable-valgrind \
--disable-xkbcommon \
--disable-libkeyutils \
--enable-seccomp \
--enable-alsa \
--disable-pa \
--enable-pipewire \
--disable-jack \
--disable-sndio \
--enable-gtk \
--enable-vte \
--enable-sdl \
--disable-sdl-image \
--enable-opengl \
--disable-virglrenderer \
--enable-spice \
--disable-xen \
--disable-docs \
--disable-debug-info \
--disable-guest-agent \
--disable-werror \
--disable-install-blobs \
--disable-containers \
--disable-download
make
make DESTDIR=$PKG install
fw=$PKG/usr/share/qemu
install -d "$fw/firmware"
(
unset CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
export CC="gcc -std=gnu11" EXTRA_OPTFLAGS=-Wno-error
make -C roms bios vgabios qboot PYTHON=python3 FIRMWARE_EXTRAVERSION=-kdos
patch -p1 -i "$PORT_SRC/ipxe-arch-i386.patch"
patch -p1 -i "$PORT_SRC/edk2-gcc-no-werror.patch"
make -C roms pxerom efirom PYTHON=python3 NO_WERROR=1 \
EXTRA_CFLAGS=-std=gnu11 BUILD_TIMESTAMP="$SOURCE_DATE_EPOCH"
mkdir -p optionrom-build
printf '%s\n' "TOPSRC_DIR=$SRC" 'CC=gcc' 'OBJCOPY=objcopy' 'PYTHON=python3' \
> optionrom-build/config.mak
make -C optionrom-build -f "$SRC/pc-bios/optionrom/Makefile"
while read -r key _ value; do
printf -v "$key" '%s' "$value"
done < roms/edk2-version
cat > roms/kdos-edk2.config <<'EDK2'
[global]
core = edk2
[opts.common]
NETWORK_HTTP_BOOT_ENABLE = TRUE
NETWORK_IP6_ENABLE = TRUE
NETWORK_TLS_ENABLE = TRUE
NETWORK_ISCSI_ENABLE = TRUE
NETWORK_ALLOW_HTTP_CONNECTIONS = TRUE
TPM2_ENABLE = TRUE
TPM2_CONFIG_ENABLE = TRUE
TPM1_ENABLE = TRUE
CAVIUM_ERRATUM_27456 = TRUE
[opts.ovmf.sb.smm]
SECURE_BOOT_ENABLE = TRUE
SMM_REQUIRE = TRUE
BUILD_SHELL = FALSE
[opts.armvirt.silent]
DEBUG_PRINT_ERROR_LEVEL = 0x80000000
[pcds.nx.broken.shim.grub]
PcdDxeNxMemoryProtectionPolicy = 0xC000000000007FD1
PcdUninstallMemAttrProtocol = TRUE
[build.ovmf.x86_64]
conf = OvmfPkg/OvmfPkgX64.dsc
arch = X64
opts = common
plat = OvmfX64
dest = ../pc-bios
cpy1 = FV/OVMF_CODE.fd edk2-x86_64-code.fd
cpy2 = FV/OVMF_VARS.fd edk2-i386-vars.fd
[build.ovmf.x86_64.secure]
conf = OvmfPkg/OvmfPkgX64.dsc
arch = X64
opts = common
ovmf.sb.smm
plat = OvmfX64
dest = ../pc-bios
cpy1 = FV/OVMF_CODE.fd edk2-x86_64-secure-code.fd
[build.armvirt.aa64]
tool = CLANGDWARF
conf = ArmVirtPkg/ArmVirtQemu.dsc
arch = AARCH64
opts = common
armvirt.silent
pcds = nx.broken.shim.grub
plat = ArmVirtQemu-AARCH64
dest = ../pc-bios
cpy1 = FV/QEMU_EFI.fd edk2-aarch64-code.fd
cpy2 = FV/QEMU_VARS.fd edk2-arm-vars.fd
EDK2
cd roms
env -u MAKEFLAGS -u GNUMAKEFLAGS CLANGDWARF_BIN=/usr/bin/ python3 edk2-build.py --config kdos-edk2.config \
--version-override "$EDK2_STABLE-kdos" --release-date "$EDK2_DATE" \
--silent --no-logs
cd ..
truncate -s 64M pc-bios/edk2-aarch64-code.fd pc-bios/edk2-arm-vars.fd
for xlen in 64 32; do
mkdir -p "$SRC/opensbi-rv$xlen"
make -C roms/opensbi LLVM=1 PLATFORM=generic PLATFORM_RISCV_XLEN=$xlen \
REPRODUCIBLE_FLAGS=-Wno-error O="$SRC/opensbi-rv$xlen"
cp "$SRC/opensbi-rv$xlen/platform/generic/firmware/fw_dynamic.bin" \
"pc-bios/opensbi-riscv$xlen-generic-fw_dynamic.bin"
done
)
for f in bios.bin bios-256k.bin bios-microvm.bin qboot.rom \
vgabios.bin vgabios-stdvga.bin vgabios-cirrus.bin vgabios-vmware.bin \
vgabios-qxl.bin vgabios-virtio.bin vgabios-bochs-display.bin \
vgabios-ramfb.bin vgabios-ati.bin \
pxe-e1000.rom pxe-eepro100.rom pxe-ne2k_pci.rom pxe-pcnet.rom \
pxe-rtl8139.rom pxe-virtio.rom \
efi-e1000.rom efi-e1000e.rom efi-eepro100.rom efi-ne2k_pci.rom \
efi-pcnet.rom efi-rtl8139.rom efi-virtio.rom efi-vmxnet3.rom \
edk2-x86_64-code.fd edk2-x86_64-secure-code.fd edk2-i386-vars.fd \
edk2-aarch64-code.fd edk2-arm-vars.fd \
opensbi-riscv64-generic-fw_dynamic.bin \
opensbi-riscv32-generic-fw_dynamic.bin edk2-licenses.txt; do
install -m644 "pc-bios/$f" "$fw/$f"
done
install -m644 optionrom-build/kvmvapic.bin optionrom-build/linuxboot_dma.bin \
optionrom-build/multiboot_dma.bin optionrom-build/pvh.bin "$fw/"
for f in edk2-riscv-code.fd edk2-riscv-vars.fd; do
bzip2 -dc "pc-bios/$f.bz2" > "$fw/$f"
chmod 644 "$fw/$f"
done
for f in 50-edk2-x86_64-secure 60-edk2-x86_64 60-edk2-aarch64 60-edk2-riscv64; do
d=$(<"pc-bios/descriptors/$f.json")
printf '%s\n' "${d//@DATADIR@//usr/share/qemu}" > "$fw/firmware/$f.json"
done
The switches, and why each is set:
--target-list=x86_64-softmmu,aarch64-softmmu,riscv64-softmmu— build three system emulators: this machine’s own architecture, aarch64 (64-bit ARM), and riscv64. The target list is the largest lever on the size of the package.--libexecdir=/usr/lib/qemu— the directory of the helper programs QEMU starts, such asqemu-bridge-helper, which QEMU looks for there by the path compiled in.qemu-bridge-helperis installed without its setuid bit and with no/etc/qemu/bridge.conf, so-netdev bridgeserves only root, and only once root writes anallow <bridge>line there (see A qemu guest cannot join a host bridge as an ordinary user);--enable-passtis the unprivileged network, through passt.--enable-gtk— with--enable-vte: the window QEMU opens by default, a GTK 3 Wayland client. vte3 gives the window its text tabs, where the monitor and the serial console appear. meson linkslibX11into it whenever GTK’s X11 backend is installed, with no option to stop it, so libX11 is independs.--enable-sdl—-display sdl, through sdl2-compat.--enable-opengl— GL scanout in the GTK and SDL windows and on the D-Bus display, and theegl-headlessdisplay, through libepoxy on Mesa’s EGL.--disable-virglrenderer— with--disable-rutabaga-gfx: no 3D for the guest (virtio-vga-gl). virglrenderer is not a port, so a guest renders in software.--enable-curses— a text-mode console,-display curses.--enable-vnc— with--enable-vnc-jpeg,--enable-pngand--enable-vnc-sasl: a guest’s screen served to any VNC viewer. KDOS’s owntesting/vnc-shot.pydrives a virtual machine that way.--enable-spice— with--enable-spice-protocol: the SPICE display thatremote-viewerand virt-manager attach to, with a shared clipboard.--enable-usb-redir— theusb-redirdevice, which takes a USB device redirected from spice-gtk orusbredirect, through usbredir.--enable-smartcard— the emulated CCID reader a host smart card is passed through, built on libcacard.--enable-libiscsi— theiscsi://block driver, which opens a LUN with no kernel initiator.--enable-tpm— the TPM backend, which talks to a swtpm process. Like the virtiofsd daemon behind-device vhost-user-fs-pci, swtpm is a separate program a guest’s command line names, not a library this build links.--enable-capstone— disassembly:-d in_asm,out_asmand the monitor’sx/iprint instructions instead of bytes. capstone is independs, because with the switch named a missing one is a configure error.--enable-pipewire— with--enable-alsa,--disable-pa,--disable-jack,--disable-sndioand--disable-oss: the guest’s sound goes to PipeWire directly, or through ALSA.--enable-fdt=system— link the dtc port’slibfdt. The tarball carries no copy, onlysubprojects/dtc.wrap, a git checkout meson would fetch, which--disable-downloadforbids.--disable-download— keep configure off the network. With downloads allowed, its default, configure’s Python environment drops the offline flag and goes to the network for packages the tarball already carries (see A build that reaches the network).--disable-containers— without it, configure answers a missing cross compiler by planning to build firmware in a podman image, which a build with no network cannot pull.--disable-install-blobs— do not installpc-bios/, upstream’s prebuilt firmware for every board of every architecture QEMU emulates. What ships instead is built bybuild.shfromroms/.--disable-docs—docs/conf.pyrequiressphinx_rtd_themeeven for the manual pages, and that theme is not a port.--enable-keyring— with--disable-libkeyutils:-object secret_keyringreads a secret from the kernel keyring through the system call built in by--enable-keyring. QEMU links libkeyutils only into its crypto unit test, so leaving it out costs nothing at run time.--disable-nettle— with--disable-gcryptand--enable-gnutls: QEMU’s cipher and hash code uses GnuTLS, which meson prefers unless nettle or libgcrypt is asked for.--disable-libnfs— with--disable-libssh,--disable-snappy,--disable-numa,--disable-libdaxctl,--disable-brlapi,--disable-libcbor,--disable-valgrind,--disable-xkbcommon,--disable-sdl-imageand--disable-auth-pam: thenfs://andssh://block drivers, snappy compression for migration, NUMA host-memory policy,libdaxctl, the braille character device,libcbor, Valgrind support for coroutine stacks, xkbcommon keymaps, SDL window icons and PAM access control for VNC are left out. Each library is a port the build does not link.--disable-selinux— andmpath,rbd,rdma,lzfse,vde,netmap,blkio,libpmem,qpl,uadk,qatzip,af-xdp,igvm,u2f,canokey,sparseandxen: features whose library is not a port.--disable-guest-agent— noqemu-ga, the agent that runs inside a guest.--disable-malloc-trim— do not call the C library’smalloc_trim(), which musl does not have.--disable-werror— with--disable-debug-info: warnings do not stop the build, and nothing is compiled with-g.--enable-kvm— and the rest of the--enable-list: KVM acceleration, and each feature named so that a missing library stops configure.
The common switches of each build system are explained in the Flag glossary.
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/qemu, 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 qemu-11.1.1-2.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/qemu, and runs the triggers its paths call for.
Contents
Installed programs: elf2dmp, qemu-edid, qemu-img, qemu-io, qemu-nbd, qemu-pr-helper, qemu-storage-daemon, qemu-system-aarch64, qemu-system-riscv64, qemu-system-x86_64, qemu-vmsr-helper.
Installed directories: /usr/lib/qemu, /usr/share/licenses/qemu, /usr/share/qemu/firmware, /usr/share/qemu/keymaps.
Notes
The firmware is built in a subshell that clears the host’s CFLAGS, CXXFLAGS, CPPFLAGS and LDFLAGS. It is freestanding code for the guest, laid out by its own linker scripts; qboot’s meson would otherwise compile -fPIC into a real-mode BIOS. CC keeps -std=gnu11 because edk2’s BaseTools and iPXE’s drivers declare functions with empty parentheses and call them with arguments, which C23 makes an error. EXTRA_OPTFLAGS=-Wno-error is the last word of the flags edk2’s BaseTools compile their host programs with, after upstream’s -Werror. Every makefile is given PYTHON=python3 (see A build calling python).
What is built, in order:
- SeaBIOS and SeaVGABIOS:
bios-256k.bin, whichpcandq35load,bios.binfor old machine types,bios-microvm.bin, and one VGA BIOS per emulated display adapter; and qboot, microvm’s fast-boot BIOS. - iPXE, with
NO_WERROR=1: every emulated network card loads its option ROM at start-up, and a missing one stops QEMU.efi-*.rom, the default, is the BIOS image and the x86_64 UEFI driver joined by edk2’sEfiRom;pxe-*.romis the BIOS-only image old machine types use. - The option ROMs
-kernelboots through (linuxboot_dma.bin,multiboot_dma.bin,pvh.bin,kvmvapic.bin), built from QEMU’s own makefile. configure builds them only when a probe links a-m32object against a 32-bit libgcc, which the tree’s gcc, built without multilib, does not have; the ROMs link-nostdliband need none. - OVMF for x86_64, plain and Secure Boot with SMM, and ArmVirtQemu for aarch64, through QEMU’s own
edk2-build.pywith a config of the three builds only. aarch64 is compiled by clang, which cross-compiles for every target the llvm port builds; x86_64 by the native gcc; acpica’siaslcompiles the ACPI tables and nasm the x86 assembly.MAKEFLAGSis removed for this step: edk2 runs one make per module on its own threads, and an inherited-jraces a module’s.efiagainst the firmware volume that packs it. The aarch64 images are then padded to 64 MiB, the size thevirtmachine’s flash banks require. - OpenSBI, the firmware every riscv machine loads by default, with
LLVM=1(clang andld.lld) for the position-independent image it needs, in both widths, sinceqemu-system-riscv64also runs rv32 CPUs. Each output directory is created first and passed absolute, because the makefile resolvesO=withreadlink -f.
The riscv64 virt UEFI image is the one image installed as upstream built it, unpacked from pc-bios/; see What is not built from source. Firmware is built only for what the three targets boot by default or through their firmware descriptors; the BMC boards inside qemu-system-aarch64 have none (see qemu carries firmware only for its three targets’ default machines).
The firmware descriptors in /usr/share/qemu/firmware are how libvirt and other front ends find a UEFI image and its variable-store template for a machine. configure_file fills their @DATADIR@ only when it installs the blobs, so build.sh writes them with the path filled in. The x86_64 variable store is named edk2-i386-vars.fd because the i386 and x86_64 OVMF builds share one layout, and the descriptors name it so.
qemu builds in 43_toolkits because its display backend depends on GTK 3 and vte directly.