From 4ea992c71dd0cdcffe0f74216e748256bd700a31 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sat, 1 Aug 2026 01:56:12 +0200 Subject: scripts: automate the data-disk workflow (mkdisk / sendkeys / test-disk) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - scripts/mkdisk.sh: create the FAT32 disk with mkfs.fat -C (the flag that actually creates the file — plain mkfs.fat fails on a missing path), accept M/G/K sizes, seed seed/ files via mtools; --fresh re-formats, --no-seed skips seeding - scripts/sendkeys.py: type lines into the guest via the QEMU monitor (US layout). Punctuation must use QEMU's named keys (minus, slash, dot, ...) — bare '-', '.', '/' are not valid sendkey names, and '-' is the modifier separator, so they were silently dropped before - scripts/test-disk.sh: full automated round trip — build, deploy, ensure image, boot headless QEMU, drive the shell (ls /disk, mkdir, echo >, cat, poweroff), then verify with fsck.fat (must be clean) and mtype (file content must have survived poweroff) - Makefile: make disk / disk-fresh / inspect / test-disk; run, run-gui and debug now auto-create a missing DISK_IMG; fix the stale comment (mkfs.fat without -C) - scripts/boot.sh: auto-create a missing DISK_IMG via mkdisk.sh - seed/: motd.txt + lines.txt seeded onto fresh images - Verified end to end: ./scripts/test-disk.sh --fresh passes --- scripts/mkdisk.sh | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 scripts/mkdisk.sh (limited to 'scripts/mkdisk.sh') diff --git a/scripts/mkdisk.sh b/scripts/mkdisk.sh new file mode 100755 index 0000000..f9a8c09 --- /dev/null +++ b/scripts/mkdisk.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env bash +# +# scripts/mkdisk.sh — create (or re-create) the FAT32 data disk that the +# kernel mounts at /disk. +# +# Usage: +# ./scripts/mkdisk.sh # create /tmp/disk.img (64M) if missing +# ./scripts/mkdisk.sh --fresh # re-format (wipes the image!) +# ./scripts/mkdisk.sh --size 128M # different size (default 64M) +# ./scripts/mkdisk.sh /path/img # custom image path +# ./scripts/mkdisk.sh --no-seed # skip the seed/ directory +# +# The image is created with `mkfs.fat -C`, which is the option that +# actually creates the file — plain `mkfs.fat` only writes into an +# existing one. Files from seed/ (if present) are copied in with mtools. +# +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +PROJECT_DIR="$(dirname "$SCRIPT_DIR")" + +IMG="/tmp/disk.img" +SIZE="64M" +FRESH=0 +SEED_DIR="$PROJECT_DIR/seed" + +while [ $# -gt 0 ]; do + case "$1" in + --fresh) FRESH=1 ;; + --size) + shift + SIZE="$1" + ;; + --no-seed) SEED_DIR="" ;; + --help | -h) + head -20 "$0" | grep "^#" | sed 's/^# \?//' + exit 0 + ;; + *) + IMG="$1" + ;; + esac + shift +done + +if [ -f "$IMG" ] && [ "$FRESH" -eq 0 ]; then + echo "mkdisk: $IMG already exists (use --fresh to re-format)" + exit 0 +fi + +if ! command -v mkfs.fat >/dev/null 2>&1; then + echo "mkdisk: mkfs.fat not found — install dosfstools (sudo apt install dosfstools)" >&2 + exit 1 +fi + +# mkfs.fat sizes are 1024-byte blocks; accept M/G/K suffixes too. +case "$SIZE" in +*G) SIZE_BLOCKS=$(( ${SIZE%G} * 1024 * 1024 )) ;; +*M) SIZE_BLOCKS=$(( ${SIZE%M} * 1024 )) ;; +*K) SIZE_BLOCKS=$(( ${SIZE%K} )) ;; +*) SIZE_BLOCKS="$SIZE" ;; +esac +if [ -z "$SIZE_BLOCKS" ] || [ "$SIZE_BLOCKS" -le 0 ] 2>/dev/null; then + echo "mkdisk: bad size '$SIZE' (use e.g. 64M or 65536)" >&2 + exit 1 +fi + +echo "mkdisk: creating $IMG ($SIZE FAT32, label RSDOS)" +rm -f "$IMG" +mkfs.fat -C -F 32 -n RSDOS "$IMG" "$SIZE_BLOCKS" + +if [ -n "$SEED_DIR" ] && [ -d "$SEED_DIR" ]; then + if ! command -v mcopy >/dev/null 2>&1; then + echo "mkdisk: warning: mcopy not found — skipping seed files (install mtools)" >&2 + else + echo "mkdisk: seeding from $SEED_DIR/" + for f in "$SEED_DIR"/*; do + [ -f "$f" ] || continue + mcopy -i "$IMG" "$f" "::/$(basename "$f")" + echo " -> $(basename "$f")" + done + fi +fi + +echo "mkdisk: done — boot with: make run (or: ./scripts/boot.sh)" -- cgit v1.2.3