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 / window0-pre.sh

29 lines · 2691 bytes Raw Blame History
1#!/usr/bin/env bash
2# L332 rung 2 window 0, part 1 (before the reboot). Run ONLY inside the coordinator-scheduled window, after the GPU users
3# on the coordinator's list are stopped. Records the box, checks the module, writes a temporary "do not load NVIDIA"
4# file (removed by part 2 as its first action) and reboots. Usage: window0-pre.sh [--go] (without --go: checks only).
5set -u
6export PATH=$PATH:/usr/sbin:/sbin # modinfo, lsmod and friends live in sbin; a normal user shell may not list it
7here=$(cd "$(dirname "$0")" && pwd); repo=$(cd "$here/../../.." && pwd)
8log=$here/window0-$(date -u +%Y%m%dT%H%M%SZ).log; ln -sfn "$(basename "$log")" "$here/window0-current.log"
9ts() { echo "$(date -u +%FT%T.%NZ) $*" | tee -a "$log"; }
10fail() { ts "PRE FAIL: $*"; exit 1; }
11KO=$repo/native/linux/aien-gpu/aien_gpu.ko
12ts "pre start, commit $(git -C "$repo" rev-parse HEAD), kernel $(uname -r)"
13{ lsmod | grep -E '^nvidia'; nvidia-smi -L; cat /proc/cmdline; sha256sum "$KO"; } >> "$log" 2>&1
14[ -f "$KO" ] || fail "no $KO (make -C native/linux/aien-gpu)"
15[ "$(modinfo -F vermagic "$KO" | cut -d' ' -f1)" = "$(uname -r)" ] || fail "aien_gpu.ko vermagic does not match $(uname -r)"
16[ "$(mokutil --sb-state 2>/dev/null)" = "SecureBoot disabled" ] || fail "Secure Boot state changed: unsigned module would be refused"
17initrd=$(lsinitramfs "/boot/initrd.img-$(uname -r)") && [ -n "$initrd" ] || fail "cannot list the initramfs: the nvidia-in-initramfs check would pass silently"
18grep -qE '/nvidia(_uvm|_modeset|_drm)?\.ko' <<< "$initrd" && fail "nvidia modules in initramfs: the modprobe.d file would not hold them back"
19holders=$(sudo fuser /dev/nvidia* 2>/dev/null | tr -s ' ' '\n' | grep -E '^[0-9]+$' | sort -u)
20for p in $holders; do ts "holder pid $p $(ps -o user=,comm= -p "$p")"; done
21other=$(for p in $holders; do [ "$(ps -o comm= -p "$p")" = nvidia-persiste ] || echo "$p"; done)
22[ -z "$other" ] || { [ "${1:-}" = --go ] && fail "GPU still held by: $other (coordinator stops them first)"; ts "WARN still held by: $other"; }
23[ "${1:-}" = --go ] || { ts "checks only (no --go): PASS"; exit 0; }
24# Self-reverting hold-back (window-boot.sh): one-shot GRUB entry, /run/modprobe.d file, hardware watchdog, panic reboot,
25# 25-min lease. Every boot after the window boot is the default entry with NVIDIA's driver; nothing to delete by hand.
26"$here/window-boot.sh" check >> "$log" 2>&1 || fail "window-boot.sh check failed (see log); was 'window-boot.sh install --yes' run in prep?"
27"$here/window-boot.sh" arm --yes >> "$log" 2>&1 || fail "window-boot.sh arm failed: not rebooting"
28sync; ts "one-shot window entry armed; rebooting (part 2: window0-post.sh after ssh is back)"
29sudo systemctl reboot