aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / docs / native / PREFLIGHT-AND-RECOVERY.md
| 1 | # Native AIENOS: preflight and recovery for an attended Spark boot |
| 2 | |
| 3 | Status: NOT A MASTER PLAN. A checklist and a procedure, nothing more. Nothing in |
| 4 | the change that adds this page runs on the physical Spark. Every PASS cited in |
| 5 | the repo for the C kernel is QEMU only, not physical (`native/kernel/GATES.md`). |
| 6 | |
| 7 | Related, read first: `docs/NATIVE_BOOT_ONE_TIME.md` (the one-time BootNext |
| 8 | procedure and its invariants), `docs/NATIVE_BOOT_ROLLBACK_CONTRACT.md` |
| 9 | (rollback rules), `docs/RECOVERY_MEDIA_MACHINE1.md` (the recovery stick), |
| 10 | `docs/BOOT_HANDOFF_CONTRACT.md` section 7 (why there are no A/B slots). |
| 11 | |
| 12 | ## 0. Which "slot": there is none |
| 13 | |
| 14 | The operator decision Q3 (ADR 0024) says the loader gets no A/B slots. The |
| 15 | "slot" is the firmware's one-time BootNext entry (the candidate) against the |
| 16 | unchanged BootOrder (Linux, Boot0001). A candidate gets one attempt. The next |
| 17 | boot is Linux again, whatever happened. Boot counters would need a loader that |
| 18 | reads and writes state, which Q3 freezes (see "Open decision" at the end). |
| 19 | |
| 20 | ## 1. Reproducible image build (host, no Spark involvement) |
| 21 | |
| 22 | Run on any aarch64 or cross-capable Linux host, from a clean checkout: |
| 23 | |
| 24 | git status --porcelain # must print nothing |
| 25 | commit=$(git rev-parse HEAD) |
| 26 | make -s -C native/kernel OUT=/tmp/ck-a AIENOS_COMMIT="$commit" full |
| 27 | make -s -C native/kernel OUT=/tmp/ck-b AIENOS_COMMIT="$commit" full |
| 28 | sha256sum /tmp/ck-a/BOOTAA64.EFI /tmp/ck-b/BOOTAA64.EFI |
| 29 | |
| 30 | `scripts/ck_repro_build.sh [full|core] [--keep DIR]` does exactly this: it |
| 31 | refuses a dirty tree, builds twice into two fresh temp folders and prints |
| 32 | `CK_REPRO_BUILD: PASS <kind> commit=<commit> sha256=<digest>` only when the |
| 33 | digests are equal. Checked on the Spark host (gcc 13.3.0, GNU ld 2.42) at |
| 34 | commit ecd12c6: `full` both builds |
| 35 | `fa48c92029957e0c468b068b4196dde254f80036565b05facc240433b6fd77aa`, `core` |
| 36 | both builds `7bf5d58ce24ddf57de24cdf0c3240f37f0971eac2689fa63935f7c4732a69038`. |
| 37 | Negative control: the same tree built with a different `AIENOS_COMMIT` gives |
| 38 | a different digest, so the comparison can fail. Same-host only: a build on |
| 39 | another machine or toolchain is UNVERIFIED. The digest changes with every commit because the commit hash is built |
| 40 | into the image, so no single digest can be written down in advance. The |
| 41 | digest of the image that is actually staged is printed by the kernel itself on |
| 42 | the recovery console (`recovery_console: identity build_sha256=<64 hex> |
| 43 | commit=<commit>`) and recorded by the stage script. Compare the two. |
| 44 | |
| 45 | The hardware staging image (the only one for the Spark) needs owner files and |
| 46 | refuses the TEST keys: |
| 47 | |
| 48 | make -C native/kernel full CK_HARDWARE_STAGING=1 \ |
| 49 | CK_OWNER_PUBKEYS=<owner public keys file> CK_MACHINE_ID=<machine id file> |
| 50 | |
| 51 | Normally use `scripts/stage_one_time_boot_ck_full.sh --dry-run`, which prints |
| 52 | every command it would run and touches nothing (for the B7b probe boot: |
| 53 | `scripts/stage_one_time_boot_ck_b7b.sh --dry-run`, same contract). |
| 54 | |
| 55 | ## 2. Preflight checklist before any attended boot |
| 56 | |
| 57 | All of these are read-only checks. Stop at the first one that fails. |
| 58 | |
| 59 | `scripts/native_boot_preflight.sh [--image EFI --expect-sha256 HEX]` runs |
| 60 | items 2, 3, 4, 5 and 8 below. It only reads (`efibootmgr` with no arguments, |
| 61 | the SecureBoot variable file, `findmnt`, `git status`, the image file, the |
| 62 | quiet flag), needs no sudo and never stages or reboots; its `--self-test` |
| 63 | also fails if the script ever gains a writing command. Last line: |
| 64 | `NATIVE_PREFLIGHT: READY` or `NOT_READY (<n> STOP)`. Items 1, 6 and 7 are |
| 65 | printed as ASK lines: they are Drake's, a script cannot see them. |
| 66 | |
| 67 | 1. Drake is at the machine, with a display and keyboard attached. (Drake's |
| 68 | physical presence and fresh go-ahead are required; see section 5.) |
| 69 | 2. The recovery stick `AIENOSRECOV` is plugged in and listed as `Boot0004` |
| 70 | (`efibootmgr` with no arguments). If it is absent, stop. |
| 71 | 3. Secure Boot state: record it. As of 2026-10-01 it is OFF for development by |
| 72 | owner decision, and it is recorded, not changed. A release candidate needs it |
| 73 | ON. Never flip it as part of this procedure: flipping changes the TPM |
| 74 | measurement and can lock the private storage volumes |
| 75 | (`docs/NATIVE_BOOT_ONE_TIME.md`, historical warning). |
| 76 | 4. `BootOrder` is the normal one (Linux first, `0001`) and `BootNext` is unset. |
| 77 | 5. The working tree is clean and its commit equals the commit the image was |
| 78 | built from; the image digest from section 1 is written down. |
| 79 | 6. Which "slot": the candidate will be the one-time BootNext entry. Linux stays |
| 80 | the permanent default. |
| 81 | 7. The pre-boot capture runs first (`scripts/verify_native_rollback.sh |
| 82 | --capture-pre`); the stage script does this itself. |
| 83 | 8. No other session holds the machine quiet for its own hardware test. |
| 84 | |
| 85 | ## 3. Getting back to Linux |
| 86 | |
| 87 | In plain words: the AIENOS test gets one try. Whatever it does (finishes, |
| 88 | crashes, freezes, or the computer refuses to start it), the next start of the |
| 89 | machine goes back to Linux by itself. If the screen stops changing for a full |
| 90 | minute, hold the power button until the machine turns off, wait ten seconds, |
| 91 | and press it again; Linux should come up. If Linux does not come up, use the |
| 92 | recovery stick (section 4). Each of these outcomes was rehearsed with the real |
| 93 | C image in QEMU (`scripts/qemu_ck_rollback_test.sh`, CK gate M0_ROLLBACK); |
| 94 | not yet on the Spark itself. |
| 95 | |
| 96 | Normal return: do nothing. Firmware deletes BootNext before it starts the |
| 97 | candidate, so any reset or power-cycle (hold the chassis power button, wait, |
| 98 | press again) boots the next BootOrder entry, which is Linux. If the candidate |
| 99 | hangs, wait 60 seconds, then power-cycle. |
| 100 | |
| 101 | ## 4. Recovery procedure if Linux does not come back |
| 102 | |
| 103 | 1. At power-on, press the firmware boot-menu key (F11 or the firmware's own |
| 104 | hotkey) and pick `AIENOSRECOV` (Boot0004). It runs entirely from RAM. |
| 105 | 2. Mount the internal root and the EFI partition read-only and run the |
| 106 | packaged collector exactly as in `docs/RECOVERY_MEDIA_MACHINE1.md` |
| 107 | ("Inspect internal storage read-only", "Capture the recovery evidence"). |
| 108 | 3. Only with a separate fresh authorization from Drake: repair, or remove the |
| 109 | staged files in `\EFI\AIENOS` on the EFI partition. Never edit BootOrder |
| 110 | from the stick without that authorization. |
| 111 | 4. After Linux is back: `sudo scripts/verify_native_rollback.sh --pre ... |
| 112 | --post ... --verify` (the ten invariants in `docs/NATIVE_BOOT_ONE_TIME.md`). |
| 113 | |
| 114 | ## 5. What needs Drake's physical action and fresh authorization |
| 115 | |
| 116 | Each of these needs Drake present and a new go-ahead for that boot. A past |
| 117 | approval does not carry over: |
| 118 | |
| 119 | - plugging in or removing the recovery stick or any USB stick; |
| 120 | - any firmware (BIOS) setting, including Secure Boot; |
| 121 | - any reboot or power-cycle of the Spark; |
| 122 | - running `--apply` of any stage script (it writes to the EFI partition and |
| 123 | sets BootNext); |
| 124 | - pressing keys at the recovery prompt, and any repair in section 4 step 3. |
| 125 | |
| 126 | An agent may do the host-side parts: build the image, run the dry-run, run QEMU |
| 127 | gates. Nothing in this change was run on the physical Spark. |
| 128 | |
| 129 | ## Open decision (not made here) |
| 130 | |
| 131 | A boot-count A/B scheme with automatic fallback after N failed boots is not |
| 132 | implemented and not specified here. The accepted spec forbids slots in this |
| 133 | loader (Q3, ADR 0024; `docs/BOOT_HANDOFF_CONTRACT.md` section 7: "the handoff |
| 134 | record carries no rollback state, and never will"). Doing it needs Drake to |
| 135 | reopen Q3 first. The existing one-time BootNext rollback is proven in QEMU |
| 136 | (M0_NATIVE_ROLLBACK_QEMU, Rust mock candidate), and with the C image as the |
| 137 | candidate in QEMU (CK gate M0_ROLLBACK, `scripts/qemu_ck_rollback_test.sh`, |
| 138 | rows 42-46 of `native/kernel/GATES.md`). Neither is a physical result. |