#!/bin/sh # License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree. # devvm.sh -- the Makronix build VM: a kept installation of Makronix, with the # source sets on it, in which Makronix is built. # # usage: devvm.sh start [-n]|stop|status|ssh [command ...]|scp args ... # # The disk is build/vm/makronix-dev.qcow2, made by # MX_VMOPTS="-s 64G -m 10G -c 8" MX_HOST=makronix-dev \ # tools/install-simple.sh -S -d build/vm/makronix-dev.qcow2 # (the DVD with the sources, `make isosrc'). The VM is reached by sshd on # 127.0.0.1:2222 as `tester' with the key build/vm/id_vm. # # `stop' shuts the guest down with shutdown(8) and waits for qemu to exit. # Never end this VM with `vmsh.sh stop': that kills qemu, the file systems are # left dirty, and the next boot needs fsck by hand (measured 2026-11-07, the # first boot of this VM). # # Network: the guest has a user-mode network (it can reach the host's network, # nothing reaches it except the ssh port). `start -n' starts it with no network # card at all, for the offline proof (docs/OFFLINE-BUILD.md): then only the # serial console (`vmsh.sh send/wait/show') reaches it. set -u TOP=${TOP:-$(cd "$(dirname "$0")/.." && pwd)} V=$TOP/tools/vmsh.sh DISK=$TOP/build/vm/makronix-dev.qcow2 # its own session directory: the install tests use build/vmsession and start with # `vmsh.sh stop', which would kill this machine in the middle of a build VMDIR=${VMDIR:-$TOP/build/vmsession-dev} export VMDIR KEY=$TOP/build/vm/id_vm PORT=2222 SSHO="-i $KEY -p $PORT -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR" usage() { echo "usage: ${0##*/} start|stop|status|ssh [command ...]|scp args ..." >&2 exit 1 } up() { # shellcheck disable=SC2086 ssh $SSHO -o ConnectTimeout=3 ${DEVUSER:-tester}@127.0.0.1 true 2>/dev/null } [ $# -ge 1 ] || usage cmd=$1 shift case $cmd in start) [ -f "$DISK" ] || { echo "no $DISK: install it first (see the header)" >&2; exit 1; } net= [ "${1:-}" = -n ] && net=-N $V start -d "$DISK" -m 10G -c 8 -p $PORT -h "$TOP" $net || exit 1 # -n: no network card, so no ssh either: the serial console is the way in [ -n "$net" ] && { echo "devvm: up without a network (serial console only)"; exit 0; } i=0 while [ $i -lt 120 ]; do up && { echo "devvm: up"; exit 0; } sleep 5 i=$((i + 1)) done echo "devvm: sshd did not answer in 10 minutes" >&2 exit 1 ;; stop) # shellcheck disable=SC2086 ssh $SSHO ${DEVUSER:-tester}@127.0.0.1 '/sbin/shutdown -p now' >/dev/null 2>&1 # setuid, group operator i=0 while [ $i -lt 60 ]; do [ -f "$VMDIR/qemu.pid" ] && kill -0 "$(cat "$VMDIR/qemu.pid")" 2>/dev/null || { echo "devvm: stopped"; exit 0; } sleep 2 i=$((i + 1)) done echo "devvm: still running" >&2 exit 1 ;; status) if up; then echo "devvm: up"; else echo "devvm: not reachable"; exit 1; fi ;; ssh) # shellcheck disable=SC2086 exec ssh $SSHO ${DEVUSER:-tester}@127.0.0.1 "$@" ;; scp) # shellcheck disable=SC2086 exec scp $(echo "$SSHO" | sed 's/ -p / -P /') "$@" ;; *) usage ;; esac