interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / evidence / own-gpu-driver / rung2 / window-boot.sh

103 lines · 6919 bytes Raw Blame History
1#!/usr/bin/env bash
2# window-boot.sh: the self-reverting boot path for L332 GPU windows (NoNvDriver review, 2026-10-26).
3#
4# Replaces "write /etc/modprobe.d/zz-aien-gpu-window*.conf and reboot". That file persists: if part 2 never runs, every
5# later boot (watchdog reset, power cycle) comes up WITHOUT NVIDIA's driver until a person deletes it. Here instead:
6# - GRUB default stays entry 0 (NVIDIA's driver). GRUB_DEFAULT is not touched; grub.cfg is not regenerated.
7# - /boot/grub/custom.cfg (sourced by /etc/grub.d/41_custom) adds ONE extra entry 'aien-gpu-window'. 'arm' selects it
8# for the next boot only, via grub-reboot (grubenv next_entry; 00_header honours it with GRUB_DEFAULT=0 and clears
9# it on use).
10# - That entry adds: aien.gpuwindow=1 (activates the two inert units), systemd.watchdog_sec=30 (PID 1 arms the SBSA
11# hardware watchdog for this boot: a hard hang resets the box into the default entry), panic=10 oops=panic
12# (a kernel panic or oops reboots after 10 s into the default entry).
13# - aien-gpu-window-hold.service writes the "do not load NVIDIA" file to /run/modprobe.d (tmpfs: this boot only).
14# - aien-gpu-window-lease.service reboots 25 min after boot (L405 lease 20 min + 5 min restore margin).
15# Any reboot after the window boot, wanted or not, lands on NVIDIA's driver with nothing to clean up.
16#
17# Usage:
18# window-boot.sh check (default) read-only: builds the entry and units into a temp dir, runs grub-script-check
19# and systemd-analyze verify, shows what install would change. Writes nothing outside /tmp.
20# window-boot.sh install --yes copies custom.cfg and the two units (inert on normal boots). Coordinator + Drake approval.
21# window-boot.sh arm --yes next boot only = 'aien-gpu-window' (grub-reboot). Inside the window only.
22# window-boot.sh status what is installed / armed now.
23# window-boot.sh uninstall --yes removes custom.cfg and the units.
24set -euo pipefail
25export PATH=$PATH:/usr/sbin:/sbin
26HERE=$(cd "$(dirname "$0")" && pwd)
27ENTRY=aien-gpu-window
28UNITS="aien-gpu-window-hold.service aien-gpu-window-lease.service"
29KVER=$(uname -r)
30CUSTOM=/boot/grub/custom.cfg
31die() { echo "WINDOW_BOOT: FAIL ($*)" >&2; exit 1; }
32
33# The entry repeats the running kernel's command line (minus GRUB's BOOT_IMAGE) and adds the window flags.
34build_entry() {
35 local uuid cmd
36 uuid=$(sed -n 's/.*root=UUID=\([0-9a-fA-F-]\{36\}\).*/\1/p' /proc/cmdline)
37 [[ -n $uuid ]] || die "no root=UUID= in /proc/cmdline"
38 [[ $(findmnt -no UUID -T /boot) == "$uuid" ]] || die "/boot is not on the root filesystem $uuid; entry paths would be wrong"
39 [[ -f /boot/vmlinuz-$KVER && -f /boot/initrd.img-$KVER ]] || die "kernel or initrd for $KVER missing in /boot"
40 cmd=$(sed 's/^BOOT_IMAGE=[^ ]* //' /proc/cmdline)
41 case " $cmd " in *" aien.gpuwindow="*|*" module_blacklist="*|*" modprobe.blacklist="*) die "running cmdline already carries window flags";; esac
42 cat <<EOF
43# AIEN GPU window entry (L332 / NoNvDriver). Never the default: selected for one boot by 'window-boot.sh arm'.
44menuentry '$ENTRY' --id $ENTRY {
45 insmod gzio
46 insmod part_gpt
47 insmod ext2
48 search --no-floppy --fs-uuid --set=root $uuid
49 linux /boot/vmlinuz-$KVER $cmd aien.gpuwindow=1 systemd.watchdog_sec=30 panic=10 oops=panic
50 initrd /boot/initrd.img-$KVER
51}
52EOF
53}
54
55check() {
56 local t; t=$(mktemp -d /tmp/window-boot.XXXXXX)
57 build_entry > "$t/custom.cfg"
58 grub-script-check "$t/custom.cfg" || die "grub-script-check refused $t/custom.cfg"
59 echo "entry: grub-script-check PASS ($t/custom.cfg)"
60 grep -q 'custom.cfg' /etc/grub.d/41_custom || die "/etc/grub.d/41_custom does not source custom.cfg"
61 grep -q 'next_entry' /etc/grub.d/00_header || die "/etc/grub.d/00_header has no next_entry (grub-reboot would not work)"
62 echo "grub: 41_custom sources custom.cfg; 00_header honours next_entry; GRUB_DEFAULT=$(sed -n 's/^GRUB_DEFAULT=//p' /etc/default/grub) unchanged"
63 [[ -e /sys/class/watchdog/watchdog0 ]] && echo "watchdog: $(cat /sys/class/watchdog/watchdog0/identity) present ($(cat /sys/class/watchdog/watchdog0/state))" \
64 || echo "watchdog: NONE (systemd.watchdog_sec has no device; hangs need a power cycle)"
65 for u in $UNITS; do cp "$HERE/window-boot/$u" "$t/$u"; done
66 (cd "$t" && systemd-analyze verify --man=no $UNITS) || die "systemd-analyze verify refused the units"
67 echo "units: systemd-analyze verify PASS"
68 local initrd; initrd=$(lsinitramfs "/boot/initrd.img-$KVER") && [[ -n $initrd ]] || die "cannot list /boot/initrd.img-$KVER: initramfs check would pass silently"
69 grep -qE '/nvidia(_uvm|_modeset|_drm)?\.ko' <<< "$initrd" && die "nvidia modules in initramfs: /run/modprobe.d would come too late"
70 echo "initramfs: no nvidia modules"
71 if [[ -e $CUSTOM ]]; then diff -u "$CUSTOM" "$t/custom.cfg" && echo "custom.cfg: installed copy identical" || echo "custom.cfg: install would REPLACE the file above"; else echo "custom.cfg: not installed (install would create it)"; fi
72 echo "WINDOW_BOOT CHECK: PASS (nothing written outside $t)"
73}
74
75need_yes() { [[ ${1:-} == --yes ]] || die "$2 needs --yes"; }
76
77case ${1:-check} in
78 check) check ;;
79 install) need_yes "${2:-}" install; check
80 t=$(mktemp -d /tmp/window-boot.XXXXXX); build_entry > "$t/custom.cfg"
81 [[ ! -e $CUSTOM ]] || cmp -s "$CUSTOM" "$t/custom.cfg" || die "$CUSTOM exists with other content; refusing to overwrite"
82 sudo install -m 0644 "$t/custom.cfg" "$CUSTOM"
83 for u in $UNITS; do sudo install -m 0644 "$HERE/window-boot/$u" "/etc/systemd/system/$u"; done
84 sudo systemctl daemon-reload; sudo systemctl enable $UNITS
85 echo "WINDOW_BOOT INSTALL: PASS (inert until 'arm')" ;;
86 arm) need_yes "${2:-}" arm
87 [[ -f $CUSTOM ]] && grep -qF -- "--id $ENTRY" "$CUSTOM" || die "entry not installed"
88 for u in $UNITS; do systemctl is-enabled -q "$u" || die "$u not enabled"; done
89 sudo grub-reboot "$ENTRY"
90 [[ $(grub-editenv /boot/grub/grubenv list | sed -n 's/^next_entry=//p') == "$ENTRY" ]] || die "grubenv next_entry not set"
91 echo "WINDOW_BOOT ARM: PASS (next boot only: $ENTRY; every later boot: default entry with NVIDIA)" ;;
92 status)
93 echo "default: GRUB_DEFAULT=$(sed -n 's/^GRUB_DEFAULT=//p' /etc/default/grub); grubenv: $(grub-editenv /boot/grub/grubenv list | tr '\n' ' ')"
94 [[ -f $CUSTOM ]] && echo "custom.cfg: installed" || echo "custom.cfg: absent"
95 for u in $UNITS; do echo "$u: $(systemctl is-enabled "$u" 2>/dev/null || true) $(systemctl is-active "$u" 2>/dev/null || true)"; done
96 grep -q 'aien.gpuwindow=1' /proc/cmdline && echo "this boot: WINDOW BOOT" || echo "this boot: normal" ;;
97 uninstall) need_yes "${2:-}" uninstall
98 sudo systemctl disable $UNITS || true
99 for u in $UNITS; do sudo rm -f "/etc/systemd/system/$u"; done
100 sudo rm -f "$CUSTOM"; sudo systemctl daemon-reload
101 echo "WINDOW_BOOT UNINSTALL: PASS" ;;
102 *) die "unknown command ${1}" ;;
103esac