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

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

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.

Patches

build.sh applies these; kpkg applies nothing by itself.

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:

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:

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.