I'm trying to add Qemu to my continuous integration pipeline to test various initrd artifacts. I've already discovered that I can run Qemu like this:
qemu-system-x86_64 \
-machine q35 \
-drive if=pflash,format=raw,file=OVMF_CODE.fd,readonly \
-drive if=pflash,format=raw,file=OVMF_VARS.fd \
-kernel vmlinuz-4.4.0-121-generic \
-initrd my-initramfs.cpio.xz \
-nographic
...and cause qemu-system-x86_64 to exit with status 0 if I do this in my init script:
# poweroff -f
This is works because the init script doesn't exit -- it invokes poweroff -f and sleeps "forever" or until Qemu does a "Power Down":
ACPI: Preparing to enter system sleep state S5
reboot: Power down
I would like to be able to detect problems in the init script by forcing an exit on error via set -eu. Exiting the init script (correctly) causes a kernel panic but the qemu-system-x86_64 process hangs forever.
How can I keep it from hanging forever? How do I get the Qemu host to detect a kernel panic in the Qemu guest?
Further clarification:
The nature of my application is security-sensitive; i.e., configuring/compiling the linux kernel is "allowed", but passing kernel parameters is not. To put a fine point on it, CMDLINE_OVERRIDE is enabled.