From 0c6864b4bc7be61f90a58c0fcb7a60e20155b53e Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Wed, 28 Oct 2026 19:33:26 -0700 Subject: [PATCH] feat(e2e): add the W0 probe for a Windows 11 guest under QEMU An unattended install of the Windows 11 evaluation ISO under QEMU with nested KVM on WSL2, and a boot script that times the golden image to a desktop. Measured: install 21.6 min, desktop in 36 to 51 s, with other VMs running. W0.md records the numbers and what was found on the way: no SMM under nested SVM, so no secure-boot OVMF; the firmware needs TPM support for Setup to see the TPM; and the evaluation reads as expired unless the guest clock is set back. --- e2e/platforms/qemu_windows/W0.md | 53 ++++++++ e2e/platforms/qemu_windows/autounattend.xml | 136 ++++++++++++++++++++ e2e/platforms/qemu_windows/qmp-type.pl | 44 +++++++ e2e/platforms/qemu_windows/setup.ps1 | 29 +++++ e2e/platforms/qemu_windows/w0-boot.sh | 55 ++++++++ e2e/platforms/qemu_windows/w0-install.sh | 69 ++++++++++ 6 files changed, 386 insertions(+) create mode 100644 e2e/platforms/qemu_windows/W0.md create mode 100644 e2e/platforms/qemu_windows/autounattend.xml create mode 100755 e2e/platforms/qemu_windows/qmp-type.pl create mode 100644 e2e/platforms/qemu_windows/setup.ps1 create mode 100755 e2e/platforms/qemu_windows/w0-boot.sh create mode 100755 e2e/platforms/qemu_windows/w0-install.sh diff --git a/e2e/platforms/qemu_windows/W0.md b/e2e/platforms/qemu_windows/W0.md new file mode 100644 index 00000000..67d4f6e5 --- /dev/null +++ b/e2e/platforms/qemu_windows/W0.md @@ -0,0 +1,53 @@ +# W0: Windows 11 under QEMU and nested KVM on WSL2 + +Measured 2026-10-28 on the WSL2 machine (AMD Ryzen 9 5900X, 24 vCPU, 31 GB, +kernel 6.18.54.1-microsoft-standard-WSL2, `nestedVirtualization=true`), +QEMU 10.2.2, swtpm 0.10.1, OVMF 202602, Windows 11 Enterprise Evaluation +build 26100.1742 (the `go.microsoft.com/fwlink/?linkid=2289031` ISO, 5.4 GB). +Guest: 4 vCPU, 6 GB, NVMe disk, e1000e, VGA, `-cpu host`. + +**Other VMs were running on the machine during every number below** (the +kfde session's NixOS suites, about 5 cores busy), so these are pessimistic. + +| What | Result | +|---|---| +| Unattended install, ISO to shutdown | 1295 s (21.6 min) | +| Boot to a desktop, golden image on an overlay | wallpaper 36 s, taskbar 51 s | +| Run dialog after Win+R through QMP | on screen within 1.5 s | + +Verdict: usable. Nothing here says the Windows half must stop. + +## Findings that change the plan + +- **No SMM under nested SVM.** The secure-boot OVMF (`OVMF_CODE.ms.fd`, + `smm=on`) stops the guest at once: `KVM: entry failed, hardware error + 0xffffffff` with `SMM=1`. Run `smm=off` with an OVMF built without + secure boot. So the guest has no Secure Boot, and Setup is told so with + `LabConfig\BypassSecureBootCheck` from the answer file. This is what + `dockur/windows` does in its default mode too. +- **The firmware needs TPM support, not only the device.** With nixpkgs' + default `OVMF`, Setup reports `TpmVersion: 0` (a hard block) even though + swtpm and `tpm-crb` are wired: nothing starts the TPM. `OVMF.override { + tpmSupport = true; }` fixes it. `BypassTPMCheck` did not help. +- **The evaluation says "Windows License is expired"** on the first boot: the + ISO is a 2024 build and the guest clock is the host's. Starting the guest + with `-rtc base=2024-10-01T00:00:00` makes it say "Windows License valid + for 90 days" (checked once, by screenshot). Every run needs that flag, or a + newer ISO. +- **A second display head is not shown to work.** `-device secondary-vga` + gives QMP a second screendump target (`device=vga2`), but it only ever + showed the firmware text; whether Windows treats it as a monitor is + unknown, and needs the agent's `displays` verb. The virtio-gpu route + needs the virtio-win driver in the image. +- QMP `screendump` (png), `send-key` and the typing helper `qmp-type.pl` + work, including inside Windows Setup (Shift+F10 gives a console), which is + how the two blocks above were diagnosed. + +## Not verified + +- That `setup.ps1` ran (UAC, lock screen, Defender, Windows Update): the + guest has no agent yet, and the desktop screenshot cannot show it. +- Second boot from the golden image without the answer ISO attached: done, + but only on an overlay, once. +- Responsiveness under load other than the above, and any run with the + daemon in the guest. diff --git a/e2e/platforms/qemu_windows/autounattend.xml b/e2e/platforms/qemu_windows/autounattend.xml new file mode 100644 index 00000000..d195b2e6 --- /dev/null +++ b/e2e/platforms/qemu_windows/autounattend.xml @@ -0,0 +1,136 @@ + + + + + en-US + en-US + en-US + en-US + en-US + + + + OnError + + 0 + true + + + 1EFI260 + + + 2MSR16 + + + 3Primarytrue + + + + + 11 + FAT32 + + + 22 + + + 33 + NTFS + C + + + + + + + 03 + + + /IMAGE/INDEX1 + + + + + + + 1 + reg add HKLM\SYSTEM\Setup\LabConfig /v BypassSecureBootCheck /t REG_DWORD /d 1 /f + + + 2 + reg add HKLM\SYSTEM\Setup\LabConfig /v BypassTPMCheck /t REG_DWORD /d 1 /f + + + 3 + reg add HKLM\SYSTEM\Setup\LabConfig /v BypassCPUCheck /t REG_DWORD /d 1 /f + + + 4 + reg add HKLM\SYSTEM\Setup\LabConfig /v BypassRAMCheck /t REG_DWORD /d 1 /f + + + 5 + reg add HKLM\SYSTEM\Setup\LabConfig /v BypassStorageCheck /t REG_DWORD /d 1 /f + + + + true + + + + + + KOMOREBI-E2E + + + + + + true + true + true + true + true + 3 + true + true + + + + + komorebi + Administrators + komorebitrue</PlainText> + </Password> + </LocalAccount> + </LocalAccounts> + </UserAccounts> + <AutoLogon> + <Enabled>true</Enabled> + <LogonCount>999999</LogonCount> + <Username>komorebi</Username> + <Password><Value>komorebi</Value><PlainText>true</PlainText> + </Password> + </AutoLogon> + <FirstLogonCommands> + <SynchronousCommand wcm:action="add"> + <Order>1</Order> + <Description>golden image tweaks</Description> + <CommandLine>powershell -NoProfile -ExecutionPolicy Bypass -Command "foreach ($d in (Get-PSDrive -PSProvider FileSystem)) { $p = Join-Path $d.Root setup.ps1; if (Test-Path $p) { &amp; $p; break } }"</CommandLine> + </SynchronousCommand> + </FirstLogonCommands> + </component> + </settings> +</unattend> diff --git a/e2e/platforms/qemu_windows/qmp-type.pl b/e2e/platforms/qemu_windows/qmp-type.pl new file mode 100755 index 00000000..2067811b --- /dev/null +++ b/e2e/platforms/qemu_windows/qmp-type.pl @@ -0,0 +1,44 @@ +#!/usr/bin/env perl +# Type a string into a QEMU guest through QMP send-key, for the install +# probes before the agent exists. usage: qmp-type.pl SOCKET TEXT [enter] +use strict; +use warnings; +use IO::Socket::UNIX; + +my ($sock, $text, $enter) = @ARGV; +my %sym = ( + ' ' => 'spc', '\\' => 'backslash', '/' => 'slash', '.' => 'dot', + ',' => 'comma', '-' => 'minus', '=' => 'equal', ';' => 'semicolon', + "'" => 'apostrophe', '[' => 'bracket_left', ']' => 'bracket_right', + '`' => 'grave_accent', +); +my %shifted = ( + ':' => 'semicolon', '_' => 'minus', '+' => 'equal', '"' => 'apostrophe', + '|' => 'backslash', '<' => 'comma', '>' => 'dot', '?' => 'slash', + '{' => 'bracket_left', '}' => 'bracket_right', '~' => 'grave_accent', + '!' => '1', '@' => '2', '#' => '3', '$' => '4', '%' => '5', '^' => '6', + '&' => '7', '*' => '8', '(' => '9', ')' => '0', +); + +my $s = IO::Socket::UNIX->new(Peer => $sock) or die "connect $sock: $!"; +<$s>; +sub cmd { + my ($c) = @_; + print $s "$c\n"; + while (my $l = <$s>) { last if $l =~ /"return"|"error"/ } +} +cmd('{"execute":"qmp_capabilities"}'); + +sub keys_json { join ',', map { qq({"type":"qcode","data":"$_"}) } @_ } +for my $c (split //, $text) { + my @k; + if ($c =~ /[a-z0-9]/) { @k = ($c) } + elsif ($c =~ /[A-Z]/) { @k = ('shift', lc $c) } + elsif (exists $sym{$c}) { @k = ($sym{$c}) } + elsif (exists $shifted{$c}) { @k = ('shift', $shifted{$c}) } + else { die "no key for '$c'" } + cmd('{"execute":"send-key","arguments":{"keys":[' . keys_json(@k) . ']}}'); + select(undef, undef, undef, 0.05); +} +cmd('{"execute":"send-key","arguments":{"keys":[' . keys_json('ret') . ']}}') + if $enter; diff --git a/e2e/platforms/qemu_windows/setup.ps1 b/e2e/platforms/qemu_windows/setup.ps1 new file mode 100644 index 00000000..aaaafeb8 --- /dev/null +++ b/e2e/platforms/qemu_windows/setup.ps1 @@ -0,0 +1,29 @@ +# First-logon provisioning for the e2e golden image. Runs from the answer +# file ISO; finishes by shutting the guest down so the host sees it exit. +$ErrorActionPreference = 'Continue' +$log = 'C:\e2e-setup.log' +function Log($m) { "$(Get-Date -Format o) $m" | Add-Content $log } +Log 'setup start' + +# no UAC prompts, no lock screen, no screensaver, no display or sleep timeout +Set-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System' EnableLUA 0 +New-Item -Force 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\Personalization' | + New-ItemProperty -Name NoLockScreen -Value 1 -Force | Out-Null +New-Item -Force 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\System' | + New-ItemProperty -Name DisableLockWorkstation -Value 1 -Force | Out-Null +Set-ItemProperty 'HKCU:\Control Panel\Desktop' ScreenSaveActive 0 +powercfg /x -monitor-timeout-ac 0 +powercfg /x -standby-timeout-ac 0 +powercfg /h off + +# no Defender real-time scanning, no Windows Update +Set-MpPreference -DisableRealtimeMonitoring $true +New-Item -Force 'HKLM:\SOFTWARE\Policies\Microsoft\Windows Defender' | + New-ItemProperty -Name DisableAntiSpyware -Value 1 -Force | Out-Null +foreach ($s in 'wuauserv', 'UsoSvc', 'WaaSMedicSvc') { + Stop-Service $s -Force -ErrorAction SilentlyContinue + Set-Service $s -StartupType Disabled -ErrorAction SilentlyContinue +} + +Log 'setup done' +shutdown /s /t 5 diff --git a/e2e/platforms/qemu_windows/w0-boot.sh b/e2e/platforms/qemu_windows/w0-boot.sh new file mode 100755 index 00000000..37d18a78 --- /dev/null +++ b/e2e/platforms/qemu_windows/w0-boot.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +# W0: boot the golden image on a throwaway overlay and time it to a desktop. +# A screendump every 5 s goes to WORKDIR/boot/; a PNG of a desktop is much +# larger than one of a spinner on black, which is the (crude) signal. +# +# usage: w0-boot.sh WORKDIR [SECONDS] (WORKDIR has the golden disk.qcow2) +# needs on PATH: qemu-system-x86_64 qemu-img swtpm socat +# needs in env: OVMF_FD (an OVMF build with tpmSupport, without SMM) +set -euo pipefail + +work=$1 limit=${2:-300} +: "${OVMF_FD:?set OVMF_FD to an OVMF fd store path with TPM support}" +: "${VCPUS:=4}" "${MEM:=6G}" + +rm -rf "$work/boot" "$work/overlay.qcow2" "$work/qmp.sock" "$work/tpm.sock" +mkdir -p "$work/boot" +qemu-img create -q -f qcow2 -b "$work/disk.qcow2" -F qcow2 \ + "$work/overlay.qcow2" +cp "$work/vars.fd" "$work/vars-boot.fd" + +swtpm socket --tpm2 --tpmstate dir="$work/tpm" \ + --ctrl type=unixio,path="$work/tpm.sock" --daemon \ + --pid file="$work/swtpm.pid" + +start=$(date +%s) +echo "boot start: $(date -Is)" +qemu-system-x86_64 -name w0-boot -accel kvm -machine q35,smm=off \ + -cpu host -smp "$VCPUS" -m "$MEM" \ + -drive "if=pflash,format=raw,readonly=on,unit=0,file=$OVMF_FD/FV/OVMF_CODE.fd" \ + -drive "if=pflash,format=raw,unit=1,file=$work/vars-boot.fd" \ + -chardev "socket,id=chrtpm,path=$work/tpm.sock" \ + -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-crb,tpmdev=tpm0 \ + -drive "if=none,id=disk,file=$work/overlay.qcow2,format=qcow2" \ + -device nvme,drive=disk,serial=e2e0,bootindex=1 \ + -netdev user,id=net0,hostfwd=tcp:127.0.0.1:7878-:7878 \ + -device e1000e,netdev=net0 \ + -device qemu-xhci -device usb-tablet -device usb-kbd \ + -device VGA,vgamem_mb=64 \ + ${QEMU_EXTRA:-} \ + -display none -qmp "unix:$work/qmp.sock,server=on,wait=off" & +qpid=$! + +while kill -0 "$qpid" 2>/dev/null; do + t=$(($(date +%s) - start)) + [ "$t" -ge "$limit" ] && break + if [ -S "$work/qmp.sock" ]; then + f="$work/boot/$(printf '%04d' "$t").png" + printf '{"execute":"qmp_capabilities"}\n{"execute":"screendump","arguments":{"filename":"%s","format":"png"}}\n' "$f" | + socat - "UNIX-CONNECT:$work/qmp.sock" >/dev/null || true + [ -f "$f" ] && echo "t=$t png_bytes=$(stat -c %s "$f")" + fi + sleep 5 +done +echo "boot end: $(date -Is) (left running; stop the unit to end it)" +wait "$qpid" || true diff --git a/e2e/platforms/qemu_windows/w0-install.sh b/e2e/platforms/qemu_windows/w0-install.sh new file mode 100755 index 00000000..7af1370d --- /dev/null +++ b/e2e/platforms/qemu_windows/w0-install.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +# W0: unattended Windows 11 evaluation install under QEMU + nested KVM. +# Prints a dated PASTE block with the wall-clock time of the install. +# +# usage: w0-install.sh ISO ANSWER_ISO WORKDIR +# needs on PATH: qemu-system-x86_64 qemu-img swtpm socat +# needs in env: OVMF_FD (the OVMFFull.fd output of nixpkgs) +set -euo pipefail + +iso=$1 answer=$2 work=$3 +: "${OVMF_FD:?set OVMF_FD to the OVMFFull.fd store path}" +: "${VCPUS:=4}" "${MEM:=6G}" "${DISK:=60G}" + +rm -rf "$work/tpm" +mkdir -p "$work/tpm" +rm -f "$work/disk.qcow2" "$work/vars.fd" "$work/qmp.sock" "$work/tpm.sock" +qemu-img create -q -f qcow2 "$work/disk.qcow2" "$DISK" +cp "$OVMF_FD/FV/OVMF_VARS.fd" "$work/vars.fd" +chmod u+w "$work/vars.fd" + +swtpm socket --tpm2 --tpmstate dir="$work/tpm" \ + --ctrl type=unixio,path="$work/tpm.sock" --daemon \ + --pid file="$work/swtpm.pid" + +qmp() { # one command, no capabilities dance beyond the greeting + printf '{"execute":"qmp_capabilities"}\n%s\n' "$1" | + socat - "UNIX-CONNECT:$work/qmp.sock" >/dev/null +} +press() { # key tap through QMP + qmp "{\"execute\":\"send-key\",\"arguments\":{\"keys\":[{\"type\":\"qcode\",\"data\":\"$1\"}]}}" +} + +start=$(date +%s) +echo "install start: $(date -Is)" + +qemu-system-x86_64 -name w0-install -accel kvm -machine q35,smm=off \ + -cpu host \ + -smp "$VCPUS" -m "$MEM" \ + -drive "if=pflash,format=raw,readonly=on,unit=0,file=$OVMF_FD/FV/OVMF_CODE.fd" \ + -drive "if=pflash,format=raw,unit=1,file=$work/vars.fd" \ + -chardev "socket,id=chrtpm,path=$work/tpm.sock" \ + -tpmdev emulator,id=tpm0,chardev=chrtpm \ + -device tpm-crb,tpmdev=tpm0 \ + -drive "if=none,id=disk,file=$work/disk.qcow2,format=qcow2,discard=unmap" \ + -device nvme,drive=disk,serial=e2e0,bootindex=2 \ + -drive "if=none,id=cd,file=$iso,media=cdrom,readonly=on" \ + -device ide-cd,drive=cd,bus=ide.0,bootindex=1 \ + -drive "if=none,id=ans,file=$answer,media=cdrom,readonly=on" \ + -device ide-cd,drive=ans,bus=ide.1 \ + -netdev user,id=net0 -device e1000e,netdev=net0 \ + -device qemu-xhci -device usb-tablet -device usb-kbd \ + -device VGA,vgamem_mb=64 \ + -display none -qmp "unix:$work/qmp.sock,server=on,wait=off" \ + & +qpid=$! + +# "Press any key to boot from CD or DVD": tap space for the first minute. +# Later reboots must reach the disk, so stop after that. +for _ in $(seq 1 60); do + sleep 1 + kill -0 "$qpid" 2>/dev/null || break + [ -S "$work/qmp.sock" ] && press spc || true +done + +wait "$qpid" || true +end=$(date +%s) +kill "$(cat "$work/swtpm.pid")" 2>/dev/null || true +echo "install end: $(date -Is)" +echo "PASTE install_seconds=$((end - start)) vcpus=$VCPUS mem=$MEM"