Files
LithosAnanke/demo/qemu-args.sh
T
rajamesandClaude Opus 5.5 9e711563b4 demo: StarshipOS in a browser -- a throwaway machine per visitor, as Zuse (#111-#115)
Captain Bob, 2026-11-06: a terminal with QEMU amd64 for people to play
with; "Mint Zuse for demo console" (#111); "Make the most recent of
builds that's green the demo"; a Try-it XWiki page with the console
embedded.

demo/ -- see its README:
  mint-zuse.sh       a Zuse of the demo's own, as a stick: blank pair,
                     system=v3 genesis, a second boot to confirm, make
                     zusestick. Never anyone's real Zuse
  build-iso.sh       the amd64 ISO, packed as make qemu packs it
  make-snapshot.sh   boot once to [zuse@Hera] ok>, save the machine
  start-session.sh   one visitor: the saved machine resumed, ended on
                     hang-up, close or time-out
  console.py         joins the visitor's terminal only once the machine
                     runs; keys typed while it loads are discarded
  qemu-args.sh       the machine, shared by save and resume
  starshipos-demo.service, apache-demo.conf, xwiki-try-it.xwiki

Every session is a copy: no network, read-only image, the Zuse stick's
writes discarded, QEMU's seccomp sandbox, an unprivileged user, a
fenced systemd unit, 30 minutes at most.

Tested here, from the sources master accepted (run 153): the Zuse
minted (logs/20261106-192626, -192739); the saved machine at POST
538/538 and [zuse@Hera] ok>; a session through ttyd's websocket ready
in 0.2 s, 3 4 + . -> 7 ok, 7 SQUARE . -> 49 ok; QEMU gone at once on
hang-up, close and time-out. Found and fixed on the way: a machine
saved stopped resumes stopped; a prompt matched as a regex; QEMU left
behind by a hang-up; keys lost while the machine loads. Not tested
here: Apache, several sessions at once (#116).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GE3SDvQn5EoxdGufk84zz2
2026-11-06 19:41:22 +00:00

38 lines
1.7 KiB
Bash

# qemu-args.sh -- the demo machine, sourced by make-snapshot.sh and start-session.sh.
#
# A session resumes a machine saved by make-snapshot.sh, and QEMU can resume a saved machine only
# into the same machine: the same board, CPU, memory, firmware and devices. Both scripts build the
# command line here, so they cannot drift apart. It is the machine `make -f kernel/Makefile
# ARCH=amd64 qemu` boots (q35, TCG, 1 GiB, OVMF, the ISO as a CD), less what a visitor must not
# have: no network device, no Artemis disk, no display, and QEMU's seccomp sandbox on.
#
# demo_qemu_args <state-dir> <vars.fd> -> fills the array QEMU_ARGS
#
# <state-dir>/StarshipOS.iso is the image; <state-dir>/identity.img, if there, is the identity
# drive every session gets (issue #111), attached with its writes discarded.
OVMF_CODE=${OVMF_CODE:-/usr/share/OVMF/OVMF_CODE_4M.fd}
demo_qemu_args() {
local dir=$1 vars=$2
QEMU_ARGS=(
-machine q35,accel=tcg
-cpu qemu64,+rdrand
-m 1024
-smp 1
-drive "if=pflash,format=raw,readonly=on,file=$OVMF_CODE"
-drive "if=pflash,format=raw,file=$vars"
-drive "if=none,id=cd,media=cdrom,readonly=on,file=$dir/StarshipOS.iso"
-device ide-cd,drive=cd,bootindex=0
-device qemu-xhci,id=xhci0,p2=16,p3=16 # kernel/Makefile XHCI_PORTS
-nic none
-display none
-no-reboot
-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny
)
if [ -f "$dir/identity.img" ]; then
QEMU_ARGS+=(-drive "if=none,id=ident,format=raw,snapshot=on,file=$dir/identity.img"
-device usb-storage,bus=xhci0.0,port=1,drive=ident)
fi
}