summaryrefslogtreecommitdiffstats
path: root/scripts/mkdisk.sh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xscripts/mkdisk.sh91
1 files changed, 0 insertions, 91 deletions
diff --git a/scripts/mkdisk.sh b/scripts/mkdisk.sh
deleted file mode 100755
index 2c62f76..0000000
--- a/scripts/mkdisk.sh
+++ /dev/null
@@ -1,91 +0,0 @@
1#!/usr/bin/env bash
2#
3# scripts/mkdisk.sh — create (or re-create) the FAT32 data disk that the
4# kernel mounts at /disk.
5#
6# Usage:
7# ./scripts/mkdisk.sh # create /tmp/disk.img (64M) if missing
8# ./scripts/mkdisk.sh --fresh # re-format (wipes the image!)
9# ./scripts/mkdisk.sh --size 128M # different size (default 64M)
10# ./scripts/mkdisk.sh /path/img # custom image path
11# ./scripts/mkdisk.sh --no-seed # skip the seed/ directory
12# ./scripts/mkdisk.sh --label CRASHLOG # volume label (default RSDOS)
13#
14# The image is created with `mkfs.fat -C`, which is the option that
15# actually creates the file — plain `mkfs.fat` only writes into an
16# existing one. Files from seed/ (if present) are copied in with mtools.
17#
18set -euo pipefail
19
20SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
21PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
22
23IMG="/tmp/disk.img"
24SIZE="64M"
25FRESH=0
26SEED_DIR="$PROJECT_DIR/seed"
27LABEL="RSDOS"
28
29while [ $# -gt 0 ]; do
30 case "$1" in
31 --fresh) FRESH=1 ;;
32 --size)
33 shift
34 SIZE="$1"
35 ;;
36 --no-seed) SEED_DIR="" ;;
37 --label)
38 shift
39 LABEL="$1"
40 ;;
41 --help | -h)
42 head -20 "$0" | grep "^#" | sed 's/^# \?//'
43 exit 0
44 ;;
45 *)
46 IMG="$1"
47 ;;
48 esac
49 shift
50done
51
52if [ -f "$IMG" ] && [ "$FRESH" -eq 0 ]; then
53 echo "mkdisk: $IMG already exists (use --fresh to re-format)"
54 exit 0
55fi
56
57if ! command -v mkfs.fat >/dev/null 2>&1; then
58 echo "mkdisk: mkfs.fat not found — install dosfstools (sudo apt install dosfstools)" >&2
59 exit 1
60fi
61
62# mkfs.fat sizes are 1024-byte blocks; accept M/G/K suffixes too.
63case "$SIZE" in
64*G) SIZE_BLOCKS=$((${SIZE%G} * 1024 * 1024)) ;;
65*M) SIZE_BLOCKS=$((${SIZE%M} * 1024)) ;;
66*K) SIZE_BLOCKS=$((${SIZE%K})) ;;
67*) SIZE_BLOCKS="$SIZE" ;;
68esac
69if [ -z "$SIZE_BLOCKS" ] || [ "$SIZE_BLOCKS" -le 0 ] 2>/dev/null; then
70 echo "mkdisk: bad size '$SIZE' (use e.g. 64M or 65536)" >&2
71 exit 1
72fi
73
74echo "mkdisk: creating $IMG ($SIZE FAT32, label $LABEL)"
75rm -f "$IMG"
76mkfs.fat -C -F 32 -n "$LABEL" "$IMG" "$SIZE_BLOCKS"
77
78if [ -n "$SEED_DIR" ] && [ -d "$SEED_DIR" ]; then
79 if ! command -v mcopy >/dev/null 2>&1; then
80 echo "mkdisk: warning: mcopy not found — skipping seed files (install mtools)" >&2
81 else
82 echo "mkdisk: seeding from $SEED_DIR/"
83 for f in "$SEED_DIR"/*; do
84 [ -f "$f" ] || continue
85 mcopy -i "$IMG" "$f" "::/$(basename "$f")"
86 echo " -> $(basename "$f")"
87 done
88 fi
89fi
90
91echo "mkdisk: done — boot with: make run (or: ./scripts/boot.sh)"