fix(pxe-infra): split OVMF CODE+VARS so the firmware can chain
iPXE loaded boot.ipxe and tried to sanboot the Alpine raw image, but the firmware raised a #GP fault at RIP 0x7EC8B5FC with RAX=0xAF...AF. The AF pattern in RAX is a tell: it is the poisoned-memory value QEMU leaves in regions the firmware has not initialised. The combined OVMF.fd is read-only and carries no NVRAM region the firmware can write to, so ExitBootServices during the iPXE-to-image handoff cannot record its boot variables and the firmware crashes. Switch to the split CODE+VARS form that nixpkgs ships: mount OVMF_CODE.fd read-only, seed a writable copy of OVMF_VARS.fd at /var/lib/pxe-infra/ovmf-vars.bin on first run, and pass it as a second pflash drive. iPXE can then write the chain target into NVRAM and the firmware hands off cleanly. Refs: docs/ARCHITECTURE.md section L4.
This commit is contained in:
1 parent
a98732d142
commit
55505fa1c5
1 file changed
+19
-5
@@ -19,10 +19,16 @@
|
||||
# nixpkgs doesn't ship that wrapper as a NixOS module
|
||||
# for ad-hoc QEMU use. The tap+attach pattern is what
|
||||
# `qemu-vm.nix` does under the hood for NixOS test VMs.
|
||||
# - UEFI firmware via OVMF (UEFI only — B.6). The combined
|
||||
# `OVMF.fd` is mounted read-only, so the VM has no
|
||||
# persistent NVRAM; every restart is a fresh boot, which
|
||||
# is the property we want.
|
||||
# - UEFI firmware via OVMF (UEFI only — B.6), in split
|
||||
# CODE+VARS form: OVMF_CODE.fd is mounted read-only, and
|
||||
# a writable copy of OVMF_VARS.fd lives at
|
||||
# /var/lib/pxe-infra/ovmf-vars.bin. Without a writable
|
||||
# VARS the firmware raises #GP when iPXE tries to chain
|
||||
# to the next boot device (ExitBootServices needs to
|
||||
# record state in NVRAM, and a read-only VARS leaves
|
||||
# RAX = 0xAF…AF and RIP inside OVMF). The file is seeded
|
||||
# from the nixpkgs OVMF_VARS.fd on the first run and
|
||||
# persists across restarts; delete it for a fresh NVRAM.
|
||||
# - Boot order: network only (`-boot n`); no disk, no ISO.
|
||||
# - `Restart=always` — failed or interrupted runs are safe to
|
||||
# repeat without cleanup, per ARCHITECTURE.md §"Run
|
||||
@@ -75,13 +81,21 @@
|
||||
ip link set pxe0-tap master ${config.pxe-infra.bridge.name}
|
||||
ip link set pxe0-tap up
|
||||
|
||||
# Seed the OVMF VARS file on first run. See the top
|
||||
# comment for why a writable VARS is required.
|
||||
VARS=/var/lib/pxe-infra/ovmf-vars.bin
|
||||
if [ ! -f "$VARS" ]; then
|
||||
cp ${pkgs.OVMF.fd}/FV/OVMF_VARS.fd "$VARS"
|
||||
fi
|
||||
|
||||
exec qemu-system-x86_64 \
|
||||
-name pxe-infra-vm \
|
||||
-machine type=q35,accel=kvm:tcg \
|
||||
-cpu host \
|
||||
-smp ${toString config.pxe-infra.vm.cpus} \
|
||||
-m ${config.pxe-infra.vm.memory} \
|
||||
-drive if=pflash,format=raw,readonly=on,file=${pkgs.OVMF.fd}/FV/OVMF.fd \
|
||||
-drive if=pflash,format=raw,readonly=on,file=${pkgs.OVMF.fd}/FV/OVMF_CODE.fd \
|
||||
-drive if=pflash,format=raw,file=$VARS \
|
||||
-netdev tap,id=net0,ifname=pxe0-tap,script=no,downscript=no \
|
||||
-device virtio-net-pci,netdev=net0,mac=${config.pxe-infra.vm.mac} \
|
||||
-boot n \
|
||||
|
||||
Reference in new issue
Block a user