Files
RedBear-OS/local/scripts/qemu-ram.sh
T
vasilito ffbe098ef8 config: add tlc to redbear-mini and redbear-full; create recipe symlink
TLC (Twilight Commander) was missing from both ISO configs. Added
tlc = {} to [packages] in redbear-mini.toml and redbear-full.toml.
Created missing symlink: recipes/tui/tlc -> ../../local/recipes/tui/tlc.
2026-06-19 11:47:25 +03:00

55 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# qemu-ram.sh — Boot Red Bear OS from RAM-disk (tmpfs)
#
# Copies the disk image into tmpfs before launching QEMU, eliminating
# all host disk I/O during OS runtime.
#
# Usage: invoked by `make qemu-ram` — not intended for direct use.
#
# Arguments:
# $1 QEMU binary (e.g. qemu-system-x86_64)
# $2 Disk image path (harddrive.img or live ISO)
# $3 QEMU flags (space-separated)
# $4 RAM directory (tmpfs mount point)
set -euo pipefail
QEMU_BIN="${1:?Usage: qemu-ram.sh <qemu-bin> <disk> <flags> <ramdir>}"
DISK="${2:?disk image path required}"
QEMU_FLAGS="${3:?QEMU flags required}"
RAMDIR="${4:?RAM directory required}"
if [ ! -f "$DISK" ]; then
echo "ERROR: disk image not found: $DISK" >&2
exit 1
fi
cleanup() {
echo "Red Bear: cleaning up RAM-disk..."
if mountpoint -q "$RAMDIR" 2>/dev/null; then
umount "$RAMDIR" 2>/dev/null || true
fi
rmdir "$RAMDIR" 2>/dev/null || true
}
trap cleanup EXIT
# Size the tmpfs: image size + 512 MiB overhead, minimum 1 GiB
img_mb=$(du -m "$DISK" | cut -f1)
tmpfs_mb=$((img_mb + 512))
[ "$tmpfs_mb" -lt 1024 ] && tmpfs_mb=1024
echo "Red Bear: preparing RAM-disk boot..."
mkdir -p "$RAMDIR"
if ! mountpoint -q "$RAMDIR" 2>/dev/null; then
mount -t tmpfs -o "size=${tmpfs_mb}m" tmpfs "$RAMDIR"
fi
echo "Red Bear: copying $DISK to RAM ($(du -h "$DISK" | cut -f1))..."
cp "$DISK" "$RAMDIR/disk.img"
ram_flags="${QEMU_FLAGS//$DISK/$RAMDIR/disk.img}"
echo "Red Bear: booting from RAM-disk..."
exec "$QEMU_BIN" $ram_flags