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

436. Virtual machines

This page is for anyone who wants to run virtual machines on KDOS, or to run KDOS itself inside one. It covers checking that the processor’s virtualisation reaches QEMU, starting a guest with qemu-system-x86_64 from a prompt, managing guests through libvirt and Virtual Machine Manager, giving a guest UEFI firmware, a TPM (Trusted Platform Module) and a shared folder, and what changes when KDOS is the guest. How the services start is explained in rcS and the service scripts, and who may ask polkit for what in the security model; this page gives the procedures.

Installation

Hardware virtualisation is part of the kernel and of the base system:

The emulator and the management stack are ports:

Port Provides
qemu qemu-system-x86_64, qemu-system-aarch64 and qemu-system-riscv64 (the three targets the recipe builds), qemu-img, qemu-nbd and the other tools, and the guest firmware under /usr/share/qemu
libvirt libvirtd, virtlogd and virsh, and the service scripts 62_virtlogd and 63_libvirtd
virt-manager Virtual Machine Manager, with virt-install, virt-clone and virt-xml
swtpm The software TPM that a guest’s emulated TPM runs on
virtiofsd The daemon that shares a host directory with a guest over virtio-fs
passt User-mode networking with no tap device and no privilege
spice-gtk, gtk-vnc The SPICE and VNC console widgets Virtual Machine Manager draws a guest’s screen with
libosinfo, osinfo-db The operating-system facts virt-install and Virtual Machine Manager choose defaults from

None of the ports in the table but passt is in the base the ISO carries. Install the ones you need, on an installed machine or on the live medium (where they go into the overlay in RAM), with kdos update install; see Installing software:

sudo kdos update install qemu
sudo kdos update install libvirt
sudo kdos update install virt-manager

The libvirt package brings its two service scripts with it, and the image ships no /etc/service.disabled marker for either, so virtlogd and libvirtd start at every boot while the package is installed. Removing the package removes the scripts. kpkg info libvirt says whether it is installed; with it installed, service status shows both [ OK ].

The KVM checks, a UEFI guest started with qemu-system-x86_64, passt, the default network and its firewall fragment are confirmed on KDOS with these packages installed, inside a virtual machine with nested virtualisation, and Virtual Machine Manager opens from the application menu. The password request when connecting to qemu:///system, the Virtual Machine Manager steps for creating and running a guest, an emulated TPM and a virtio-fs share follow polkit’s rules, the recipes and upstream’s documentation and are not yet confirmed on KDOS; see Known gaps.

On the live medium, a guest’s disk image is written to the overlay in RAM and is gone at power-off, unless you put it on a mounted disk.

Configuration

The service scripts

The libvirt recipe writes both scripts as heredocs. They run their daemon under ksvc supervise, in the foreground, so the supervisor restarts it after a crash:

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

ports/core/virt/libvirt/build.sh, lines 145–163

62_virtlogd has the same shape. Each gives its daemon a pid file under /run/libvirt, libvirt’s own run directory; the supervisor’s is /run/kdos-svc.<name>.pid. -Dremote_default_mode=legacy makes clients connect to the single libvirtd, which serves qemu:///system and the other drivers; the recipe writes no service script for upstream’s per-driver daemons.

Who may manage system guests

A connection to qemu:///system asks polkit for org.libvirt.unix.manage. For a member of wheel at the machine, the KDOS rules file answers it with a request for that member’s own password, and keeps the answer for a few minutes, so one password covers the connections Virtual Machine Manager makes in that time:

    /*
     * Administrative applications, one password per agent session rather
     * than one per action: GParted re-running itself through pkexec, K3b
     * setting the burner's group and permissions, KTextEditor (Kate,
     * KDevelop) writing a file the user cannot, virt-manager reaching
     * qemu:///system, and Resources ending another user's process. Each
     * writes a raw disk or a root-owned file, which is what a prompt is for.
     */
    case "org.gnome.gparted":
    case "org.kde.k3b.updatepermissions":
    case "org.kde.ktexteditor6.katetextbuffer.savefile":
    case "org.libvirt.unix.manage":
    case "net.nokyan.Resources.kill":
        return polkit.Result.AUTH_ADMIN_KEEP;
    }

fs/etc/polkit-1/rules.d/50-kdos.rules, lines 126–140

Every other request falls through to the rules after it. libvirt installs its own, /usr/share/polkit-1/rules.d/50-libvirt.rules, which grants the action to members of the libvirt group with no password. polkit reads the rules files of /etc and /usr/share together in name order, and 50-kdos.rules sorts before 50-libvirt.rules, so:

The group has no member until you add one. The package creates it and the qemu account its guests run as, a member of kvm:

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

ports/core/virt/libvirt/postinstall.sh, lines 12–15

Who polkit asks for a password, and which actions KDOS’s rule grants without one, is in polkit and the authentication agent.

The firewall

The libvirt package adds a fragment to the firewall. It forwards the traffic of libvirt’s NAT bridges (virbr0 and the rest) and lets guests reach the network’s dnsmasq for DHCP and DNS:

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

ports/core/virt/libvirt/build.sh, lines 109–120

It is installed as /etc/nftables.d/40-libvirt.nft and loaded with the rest of the ruleset; see The firewall.

libvirt’s own configuration

libvirtd.conf, qemu.conf and the other files under /etc/libvirt are upstream’s, installed with every setting commented out at its default. The recipe sets the defaults that matter here at build time: guests run as the qemu account in the kvm group, the firewall back end is nftables, and there is no SELinux or AppArmor driver. Upstream also installs the default network, /etc/libvirt/qemu/networks/default.xml: a NAT bridge virbr0 on 192.168.122.1/24, handing out addresses from .2 to .254. The recipe removes upstream’s mark that starts it with the daemon, so no bridge or dnsmasq runs until a guest needs one.

Guest firmware

The recipe compiles SeaBIOS, iPXE, EDK2 for x86_64 and aarch64, and OpenSBI from the sources in QEMU’s tarball, and installs them in /usr/share/qemu. The riscv64 UEFI images are the prebuilt ones the tarball carries, decompressed. Four firmware descriptors are written to /usr/share/qemu/firmware, which is where libvirt looks when a guest asks for UEFI:

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

ports/core/virt/qemu/build.sh, lines 257–260

Descriptor Firmware Machines
60-edk2-x86_64.json edk2-x86_64-code.fd, variables from edk2-i386-vars.fd pc-i440fx-*, pc-q35-*
50-edk2-x86_64-secure.json edk2-x86_64-secure-code.fd (Secure Boot, needs SMM), variables from edk2-i386-vars.fd pc-q35-*
60-edk2-aarch64.json edk2-aarch64-code.fd, edk2-arm-vars.fd aarch64 virt
60-edk2-riscv64.json edk2-riscv-code.fd, edk2-riscv-vars.fd riscv64 virt

The Secure Boot descriptor has no enrolled-keys feature, and its variable template is the same edk2-i386-vars.fd as the plain build’s, so a Secure Boot guest starts with no keys enrolled.

Shared folders

virtiofsd’s recipe writes the descriptor libvirt reads to find the daemon:

install -d "$PKG/usr/share/qemu/vhost-user"
cat > "$PKG/usr/share/qemu/vhost-user/50-virtiofsd.json" <<'JSON'
{
  "description": "virtiofsd vhost-user-fs",
  "type": "fs",
  "binary": "/usr/bin/virtiofsd",
  "features": [
      "migrate-precopy",
      "posix-acl-negotiation-mode",
      "security-label-negotiation-mode",
      "separate-options"
  ]
}
JSON

ports/core/virt/virtiofsd/build.sh, lines 18–31

Virtual Machine Manager

The recipe makes VNC the default console for a new guest and QEMU the default hypervisor:

meson setup build --prefix=/usr --sysconfdir=/etc --libdir=lib \
	--buildtype=release \
	-Dcompile-schemas=false \
	-Dupdate-icon-cache=false \
	-Ddefault-graphics=vnc \
	-Ddefault-hvs=qemu \
	-Dtests=disabled

ports/core/virt/virt-manager/build.sh, lines 12–18

Usage

Checking that KVM is available

  1. Check that the processor offers hardware virtualisation (vmx is Intel’s flag, svm AMD’s); a count of zero means it is off in the firmware set-up or absent:

    grep -cE 'vmx|svm' /proc/cpuinfo
  2. Check that the module is loaded and the device node is there:

    lsmod | grep kvm
    ls -l /dev/kvm

    With no kvm_intel or kvm_amd line, load the one for your processor:

    sudo modprobe kvm_intel
  3. Check that the node is open to you. ls -l /dev/kvm should show crw-rw-rw- and the group kvm; any account can then use it. On an AMD machine:

    kvm_amd               266240  0
    kvm                  1470464  1 kvm_amd
    crw-rw-rw- 1 root kvm 10, 232 … /dev/kvm

    /dev/vhost-net and /dev/vhost-vsock show the same owner and mode.

Running a guest with QEMU directly

This needs no daemon and no root. The example boots an installer image on UEFI with a virtio disk, virtio graphics in a window, and user-mode networking.

  1. Make a disk image and a private copy of the UEFI variable store:

    mkdir -p ~/vm/test && cd ~/vm/test
    qemu-img create -f qcow2 disk.qcow2 32G
    cp /usr/share/qemu/edk2-i386-vars.fd vars.fd
  2. Boot it:

    qemu-system-x86_64 -enable-kvm -cpu host -smp 4 -m 4G \
      -drive if=pflash,format=raw,readonly=on,file=/usr/share/qemu/edk2-x86_64-code.fd \
      -drive if=pflash,format=raw,file=vars.fd \
      -drive file=disk.qcow2,if=virtio,format=qcow2 \
      -cdrom installer.iso \
      -device virtio-vga -display gtk \
      -nic user,model=virtio-net-pci

    -nic user is QEMU’s built-in user-mode network. For passt instead, replace it with -netdev passt,id=n0 -device virtio-net-pci,netdev=n0. Neither needs privilege. passt prints No IPv6 nameserver available for NDP/DHCPv6 on a host with no IPv6 resolver, and runs. With an empty disk and no -cdrom, the firmware tries the disk, then >>Start PXE over IPv4., which is the sign that the UEFI images and KVM both work.

  3. After the install, drop the -cdrom line and boot again from the disk.

Every option is described in qemu-system-x86_64 -help and in QEMU’s own documentation. The recipe builds without QEMU’s documentation, so there is no qemu(1) page on the machine: man qemu answers No entry for qemu in the manual. qemu-system-x86_64 -display help lists the display back ends built: none, gtk, sdl, egl-headless, curses, spice-app and dbus.

Managing guests with Virtual Machine Manager

  1. Check that both daemons are running, and start them if they are not:

    service status virtlogd
    service status libvirtd
    sudo service start virtlogd
    sudo service start libvirtd
  2. Open Virtual Machine Manager from the application menu, or run virt-manager. On its first run it connects to qemu:///system, and the authentication dialog asks for an administrator’s password. A member of wheel types their own; any other account needs a wheel member to type theirs, unless it is in the libvirt group, which connects with no password. To avoid the system connection altogether, use the per-user qemu:///session (see Tips).

  3. Create a guest with File → New Virtual Machine. Its console opens in VNC unless you choose SPICE under the guest’s display settings.

The same guests from a prompt:

virsh -c qemu:///system list --all
virsh -c qemu:///system start <guest>
virsh -c qemu:///system shutdown <guest>

On a fresh machine virsh -c qemu:///system list --all answers with an empty table, once the administrator’s password has been given.

The default NAT network

  1. List the networks and see whether default is active:

    virsh -c qemu:///system net-list --all

    As shipped it is defined and not started, and there is no virbr0:

     Name      State      Autostart   Persistent
    ----------------------------------------------
     default   inactive   no          yes
  2. Start it, and mark it to start with the daemon if guests should find it up at every boot. virt-manager offers to start it when a new guest is set up on it. Once it is up, virbr0 holds 192.168.122.1/24; on an active network net-start answers Requested operation is not valid: network is already active:

    virsh -c qemu:///system net-start default
    virsh -c qemu:///system net-autostart default
  3. Check that the firewall fragment is loaded, which is what lets the guests out. The line it prints is iifname "virbr*" accept:

    sudo nft list chain inet filter forward | grep virbr

    The network’s own dnsmasq, two processes started with --conf-file=/var/lib/libvirt/dnsmasq/default.conf, runs beside NetworkManager’s.

A TPM for a guest

In the guest’s details, Add Hardware → TPM, with the Emulated type. libvirt starts one swtpm per guest, as the tss account, keeping its state under /var/lib/libvirt/swtpm. The swtpm package’s install script gives /var/lib/swtpm-localca to tss (owner tss, group root, mode 0750 on a booted image), which swtpm_setup needs to create the TPM’s certificates.

A shared folder over virtio-fs

  1. In the guest’s Memory settings, enable shared memory; virtio-fs needs it.

  2. Add Hardware → Filesystem, driver virtiofs, with the host directory as the source and a tag of your choosing as the target.

  3. In a Linux guest, mount it by its tag:

    sudo mount -t virtiofs <tag> /mnt

Running KDOS as a guest

A KDOS image runs under QEMU on any host with KVM. The build tree’s make run target is the command line KDOS is developed against; it is in the repository’s Makefile:

run: ## boot the ISO in QEMU (software graphics); creates a sparse 192G build/kdos.qcow2 if missing
	test -f build/iso-build/kdos.iso || { echo "ERROR: ISO not found at build/iso-build/kdos.iso — run 'make build' first"; exit 1; }
	test -r /usr/share/ovmf/OVMF.fd || { echo "ERROR: OVMF firmware not found at /usr/share/ovmf/OVMF.fd — install ovmf (debian: ovmf, arch: edk2-ovmf)"; exit 1; }
	test -c /dev/kvm 2>/dev/null || { echo "WARNING: /dev/kvm not found — QEMU will run without KVM (very slow)"; }
	test -f build/kdos.qcow2 || qemu-img create -f qcow2 build/kdos.qcow2 $(KDOS_DISK)
	qemu-system-x86_64 -enable-kvm -cpu host -smp $$(nproc) -m 4G -bios /usr/share/ovmf/OVMF.fd -cdrom build/iso-build/kdos.iso -serial stdio -drive file=build/kdos.qcow2,format=qcow2 -usb -device usb-tablet -vga none -device virtio-vga,xres=$(KDOS_XRES),yres=$(KDOS_YRES) -display gtk $$(testing/qemu-audio.sh) -netdev user,id=net0 -device virtio-net-pci,netdev=net0

Makefile, lines 249–254

That target runs on the build machine and expects its OVMF at /usr/share/ovmf/OVMF.fd; on a KDOS host, use the firmware paths from Running a guest with QEMU directly. What the guest does differently from real hardware:

context.properties.rules = [
    {   matches = [ { cpu.vm.name = !null } ]
        actions = {
            update-props = {
                default.clock.quantum     = 4096
                default.clock.min-quantum = 4096
                default.clock.max-quantum = 8192
            }
        }
    }
]

fs/etc/pipewire/pipewire.conf.d/99-kdos-vm.conf, lines 38–48

Why an emulated sound card needs it is in The quantum, and why a virtual machine gets a bigger one. - QEMU’s emulated USB tablet is handled as a plain mouse:

SUBSYSTEM=="input", ATTRS{name}=="QEMU QEMU USB Tablet", ENV{ID_INPUT}="1", ENV{ID_INPUT_TABLET}="", ENV{ID_INPUT_JOYSTICK}="", ENV{ID_INPUT_POINTER}="1", ENV{ID_INPUT_MOUSE}="1"

fs/etc/udev/rules.d/99-qemu-tablet.rules

A guest given too little memory stops right after the boot menu with the boot loader’s own panic, PANIC: High memory allocator: Out of memory or PANIC: linux: Failed to allocate memory for kernel, followed by a stack trace: QEMU’s default of 128 MiB is one of those, so pass -m 4G. A guest with enough to boot but well under the 4 GB minimum (under 2.75 GiB) shows a failed MEMORY stage on the boot splash naming its size, and boots on; its desktop may come up and close applications to stay up, or stall before its first frame.

Running KDOS on VirtualBox

The ISO boots on VirtualBox 7 with these settings, chosen by hand in the New VM wizard:

KDOS ships no VirtualBox guest utilities: the screen does not follow the window (Auto-resize Guest Display stays greyed out), and there is no shared clipboard, drag and drop or shared-folder automount. The resolution is set inside the guest, as for QXL above.

Tips

Troubleshooting

QEMU prints “Could not access KVM kernel module” or “failed to initialize kvm”. The module is not loaded, or the processor’s virtualisation is off in the firmware set-up. Work through Checking that KVM is available. A KDOS that is itself a guest needs nested virtualisation from its host.

Virtual Machine Manager says it cannot connect to libvirt. The daemon is down or refused you.

  1. service status libvirtd. If it is down, start it and read what it printed:

    sudo service start libvirtd
    sudo cat /run/kdos-svc.libvirtd.log

    The supervisor keeps the daemon’s output in that file, readable by root only, and in the system log; service start itself prints only the script’s own lines.

  2. If it is up, the connection was refused at the password: it needs the password of a member of wheel, or an account outside wheel in the libvirt group (id <name> lists an account’s groups). Cancelling the authentication dialog refuses the connection.

A guest has no network. Check that default is active (virsh -c qemu:///system net-list --all; without -c, virsh run as an ordinary account lists the per-user qemu:///session networks, of which there are none), that a dnsmasq is running for it (pgrep -a dnsmasq), and that the firewall loaded the libvirt fragment. When /etc/nftables.conf with its drop-ins does not load at boot, the nftables service loads it without /etc/nftables.d and reports [FAIL], and the libvirt fragment is then missing. Checking the file prints the error without changing what is loaded:

sudo nft -c -f /etc/nftables.conf

See Firewall.

A guest with an emulated TPM does not start. Check that /var/lib/swtpm-localca belongs to tss with mode 0750:

ls -ld /var/lib/swtpm-localca

If it does not, give it back, as the swtpm package’s install script does:

sudo chown -R tss:root /var/lib/swtpm-localca
sudo chmod 0750 /var/lib/swtpm-localca

A guest’s log. virtlogd keeps each guest’s console and QEMU output in /var/log/libvirt/qemu/<guest>.log. The directory is the package’s, and the image carries it empty, so before the first guest it holds nothing.

QEMU stops with “Could not find ROM image”. The machine type needs firmware the recipe does not build; see the first item under Known gaps.

-netdev bridge fails as an ordinary user. QEMU prints failed to parse default acl file '/etc/qemu/bridge.conf' and bridge helper failed: qemu-bridge-helper is installed without its setuid bit and no bridge.conf is shipped, so the helper serves only root. That is a known gap; use user-mode networking, or a libvirt network.

Known gaps

See also