- usb_haiku.cpp: lists /dev/disk/usb/* drives (never the boot volume), formats MBR + FAT32 at 1 MiB through BDiskDevice/BPartition, mounts, unmounts and ejects; modifications are cancelled on failure - third_party/doctest (MIT single header) used when no system package exists (HaikuPorts has none) - tools/haiku-vm.sh: sync command, dedicated SSH key; tools/qmp.py: typefile command and slower key pacing - builds on Haiku R1/beta6 x86_64; usb-list sees the virtual stick. Known issue: some unit tests still fail on Haiku (to investigate). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WDASLCiN764v685boRVYar
89 lines
3.4 KiB
Bash
89 lines
3.4 KiB
Bash
#!/bin/sh
|
|
# SPDX-License-Identifier: MIT
|
|
# Haiku R1/beta6 x86_64 development VM under QEMU (Linux / WSL2, KVM when available).
|
|
#
|
|
# tools/haiku-vm.sh fetch download + verify the official anyboot image
|
|
# tools/haiku-vm.sh install boot the image with an empty 20 GB disk (run the Installer, see docs)
|
|
# tools/haiku-vm.sh start boot the installed system (headless, VNC on 127.0.0.1:5901)
|
|
# tools/haiku-vm.sh stop ACPI power-off (hard kill after 60 s)
|
|
# tools/haiku-vm.sh ssh [cmd] ssh into the VM (port 2222, user "user")
|
|
# tools/haiku-vm.sh status
|
|
#
|
|
# A 16 GB sparse raw image is attached as a USB mass-storage device ("the stick"), so the
|
|
# Haiku USB backend can be tested end to end; inspect it from Linux with mtools.
|
|
# The VM is driven with tools/qmp.py (screenshots, clicks, typing) through $VM_DIR/qmp.sock.
|
|
set -eu
|
|
|
|
VM_DIR=${OPENPU_VM_DIR:-$HOME/openpu-vm}
|
|
RELEASE=r1beta6
|
|
ISO=$VM_DIR/haiku-$RELEASE-x86_64-anyboot.iso
|
|
ISO_SHA256=bb7743474fd175aea511be1799764ba054465285bbdf54c4722ca61d1fb4f5c9
|
|
ISO_URL=https://mirrors.rit.edu/haiku/$RELEASE/haiku-$RELEASE-x86_64-anyboot.iso
|
|
DISK=$VM_DIR/haiku.qcow2
|
|
STICK=$VM_DIR/haiku-usb.img
|
|
QMP=$VM_DIR/qmp.sock
|
|
PIDFILE=$VM_DIR/qemu.pid
|
|
SSH_PORT=${OPENPU_VM_SSH_PORT:-2222}
|
|
|
|
mkdir -p "$VM_DIR"
|
|
|
|
running() { [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null; }
|
|
|
|
qemu() {
|
|
accel="-accel tcg"
|
|
[ -w /dev/kvm ] && accel="-accel kvm -cpu host"
|
|
[ -f "$STICK" ] || truncate -s 16G "$STICK"
|
|
# shellcheck disable=SC2086
|
|
qemu-system-x86_64 $accel -machine q35 -smp 4 -m 4096 \
|
|
-drive file="$DISK",format=qcow2,if=none,id=hd0 -device ide-hd,drive=hd0,bus=ide.0 \
|
|
-nic user,model=e1000,hostfwd=tcp:127.0.0.1:"$SSH_PORT"-:22 \
|
|
-device qemu-xhci,id=xhci -device usb-tablet,bus=xhci.0 \
|
|
-drive file="$STICK",format=raw,if=none,id=stick \
|
|
-device usb-storage,bus=xhci.0,drive=stick,removable=on \
|
|
-display none -vnc 127.0.0.1:1 \
|
|
-qmp unix:"$QMP",server=on,wait=off \
|
|
-daemonize -pidfile "$PIDFILE" "$@"
|
|
}
|
|
|
|
case "${1:-}" in
|
|
fetch)
|
|
[ -f "$ISO" ] || curl -fL -o "$ISO.part" "$ISO_URL" && { [ -f "$ISO" ] || mv "$ISO.part" "$ISO"; }
|
|
echo "$ISO_SHA256 $ISO" | sha256sum -c -
|
|
;;
|
|
install)
|
|
running && { echo "VM already running" >&2; exit 1; }
|
|
[ -f "$DISK" ] || qemu-img create -f qcow2 "$DISK" 20G
|
|
qemu -drive file="$ISO",media=cdrom,if=none,id=cd -device ide-cd,drive=cd,bus=ide.1 -boot d
|
|
echo "installer booted (VNC 127.0.0.1:5901, QMP $QMP)"
|
|
;;
|
|
start)
|
|
running && { echo "VM already running"; exit 0; }
|
|
qemu -boot c
|
|
echo "VM started (VNC 127.0.0.1:5901, ssh -p $SSH_PORT user@127.0.0.1)"
|
|
;;
|
|
stop)
|
|
running || { echo "VM not running"; exit 0; }
|
|
python3 "$(dirname "$0")/qmp.py" --socket "$QMP" powerdown || true
|
|
for _ in $(seq 60); do running || { echo "stopped"; exit 0; }; sleep 1; done
|
|
kill "$(cat "$PIDFILE")"; echo "killed"
|
|
;;
|
|
ssh)
|
|
shift
|
|
exec ssh -p "$SSH_PORT" -i "$VM_DIR/id_ed25519" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR \
|
|
user@127.0.0.1 "$@"
|
|
;;
|
|
sync)
|
|
# Copy the working tree (without .git) to ~/openpu in the VM.
|
|
SRC=$(cd "$(dirname "$0")/.." && pwd)
|
|
tar -C "$SRC" --exclude=.git -cf - . | "$0" ssh "mkdir -p openpu && tar -xf - -C openpu"
|
|
echo "synced $SRC -> VM:~/openpu"
|
|
;;
|
|
status)
|
|
running && echo "running (pid $(cat "$PIDFILE"))" || echo "stopped"
|
|
;;
|
|
*)
|
|
sed -n '3,12p' "$0" >&2
|
|
exit 2
|
|
;;
|
|
esac
|