Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/scripts/qemu_verify_recovery_media.sh # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / scripts / qemu_verify_recovery_media.sh` 173 lines ยท 7067 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # SPDX-License-Identifier: Apache-2.0 3 # Copyright 2026 Drake Stapleton (AIEN / aien-dev) 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # qemu_verify_recovery_media.sh: Verify standalone recovery environment in QEMU AArch64 18 # Invariant: BOOTS WITH ZERO HARD DISKS ATTACHED. Internal NVMe must not be present. 19 # Proves 100% RAM disk self-containment under rdinit=/init. 20 # Zero Disk Secrets and Unslop compliant. 21 22 set -euo pipefail 23 24 REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" 25 cd "${REPO_ROOT}" 26 27 command -v qemu-system-aarch64 >/dev/null || { echo "qemu-system-aarch64 not installed"; exit 2; } 28 29 if [[ "$(uname -m)" != "aarch64" ]]; then 30 echo "SKIPPED: Host architecture is $(uname -m). AArch64 kernel recovery boot requires an AArch64 host or cross-built AArch64 kernel." 31 [[ "${AIENOS_STRICT:-0}" != "1" ]] || { echo "STRICT FAIL: recovery boot skipped under AIENOS_STRICT=1" >&2; exit 1; } 32 exit 0 33 fi 34 35 WORK_DIR=$(mktemp -d) 36 trap 'rm -rf "${WORK_DIR}"' EXIT 37 LOG="${WORK_DIR}/recovery_qemu.log" 38 39 PROD_VMLINUZ=$(sudo -n ls -1t /boot/vmlinuz-* 2>/dev/null | head -n 1 || ls -1t /boot/vmlinuz-* 2>/dev/null | head -n 1 || true) 40 if [[ -z "${PROD_VMLINUZ}" ]]; then 41 echo "Error: Signed production kernel not found in /boot" >&2 42 exit 1 43 fi 44 45 KERNEL_IMAGE="${WORK_DIR}/vmlinuz" 46 # /boot/vmlinuz-* is root 0600 on Ubuntu. The Spark judge runs gates as aien-run with no_new_privs, so sudo 47 # cannot copy it there; the operator keeps a read-only copy of the same kernel at $HOME/boot/vmlinuz (root 0644, 48 # HOME=/var/lib/aien-run), the way it provides $HOME/models. Use that copy only when the kernel cannot be read. 49 JUDGE_VMLINUZ="${HOME:-/nonexistent}/boot/vmlinuz" 50 if [[ -r "${PROD_VMLINUZ}" ]]; then 51 cp "${PROD_VMLINUZ}" "${KERNEL_IMAGE}" 52 elif sudo -n cp "${PROD_VMLINUZ}" "${KERNEL_IMAGE}" 2>/dev/null; then 53 sudo -n chown "$(id -u):$(id -g)" "${KERNEL_IMAGE}" 54 elif [[ -r "${JUDGE_VMLINUZ}" ]]; then 55 echo "NOTE ${PROD_VMLINUZ} is not readable and sudo is unavailable; using the read-only copy ${JUDGE_VMLINUZ}" 56 cp "${JUDGE_VMLINUZ}" "${KERNEL_IMAGE}" 57 else 58 echo "Error: cannot read ${PROD_VMLINUZ} (no sudo, no ${JUDGE_VMLINUZ})" >&2 59 exit 1 60 fi 61 62 INITRD_TMP="${WORK_DIR}/aienos-recovery-standalone-initrd.img" 63 # Repo checks run on hosts without gocryptfs (CI, laptops). Only there, and 64 # visibly, allow a test image without it. The real stick build 65 # (build_recovery_media.sh) never sets this. 66 if ! command -v gocryptfs >/dev/null 2>&1 && [[ ! -f /home/atlas/atlas-forgejo-setup-`20260904`/runtime/usr/bin/gocryptfs && -z "${AIENOS_GOCRYPTFS:-}" ]]; then 67 echo "SKIP gocryptfs not on this host; building a TEST-ONLY image without it" 68 export AIENOS_RECOVERY_ALLOW_NO_GOCRYPTFS=1 69 fi 70 71 echo "Building standalone recovery initrd..." 72 bash "${REPO_ROOT}/scripts/build_standalone_recovery_initrd.sh" "${INITRD_TMP}" 73 74 echo "Booting standalone recovery kernel in QEMU with ZERO hard disks attached..." 75 started=$(date +%s) 76 set +e 77 timeout 30 qemu-system-aarch64 \ 78 -M virt -cpu max -smp 2 -m 1024 \ 79 -kernel "${KERNEL_IMAGE}" \ 80 -initrd "${INITRD_TMP}" \ 81 -append "rdinit=/init aienos.test=1 console=ttyAMA0 panic=1 quiet" \ 82 -display none -nic none \ 83 -serial file:"${LOG}" -no-reboot 84 QEMU_STATUS=$? 85 set -e 86 elapsed=$(( $(date +%s) - started )) 87 88 tr -d '\r' <"${LOG}" >"${WORK_DIR}/recovery_qemu.txt" 89 [[ -z "${AIENOS_LOG_DIR:-}" ]] || cp "${WORK_DIR}/recovery_qemu.txt" "${AIENOS_LOG_DIR}/recovery_zero_disk_serial.log" 90 91 failed=0 92 check() { 93 if grep -q -- "$2" "${WORK_DIR}/recovery_qemu.txt"; then 94 echo "PASS $1" 95 else 96 echo "FAIL $1" 97 failed=1 98 fi 99 } 100 101 echo "qemu exit ${QEMU_STATUS} after ${elapsed} s" 102 check "Recovery banner displayed" "AIENOS Standalone Hardware Recovery Core" 103 check "100% RAM disk verified" "Root filesystem: 100% RAM disk" 104 check "Internal NVMe confirmed unmounted" "Internal NVMe status: UNMOUNTED" 105 check "Automated recovery test passed" "TEST MODE DETECTED: automated recovery verification complete" 106 107 if [[ "${failed}" != 0 ]]; then 108 echo "---- recovery console log ----" 109 cat "${WORK_DIR}/recovery_qemu.txt" 110 echo "RECOVERY_ZERO_DISK: FAIL" 111 exit 1 112 fi 113 114 echo "RECOVERY_ZERO_DISK: PASS (verified standalone RAM recovery with zero attached storage)" 115 116 # Second boot: the packaged drivers must find a USB stick, an NVMe drive and a 117 # USB keyboard. The disks are blank scratch images, never host storage. 118 DEV_LOG="${WORK_DIR}/recovery_devices.log" 119 truncate -s 64M "${WORK_DIR}/usb.img" "${WORK_DIR}/nvme.img" 120 ACCEL=(-cpu max) 121 DEV_TIMEOUT=120 122 if [[ -w /dev/kvm ]]; then 123 ACCEL=(-accel kvm -cpu host) 124 DEV_TIMEOUT=60 125 fi 126 127 echo "Booting recovery kernel with a scratch USB stick, NVMe drive and USB keyboard..." 128 set +e 129 timeout "${DEV_TIMEOUT}" qemu-system-aarch64 \ 130 -M virt "${ACCEL[@]}" -smp 2 -m 1024 \ 131 -kernel "${KERNEL_IMAGE}" \ 132 -initrd "${INITRD_TMP}" \ 133 -append "rdinit=/init aienos.test=1 console=ttyAMA0 panic=1" \ 134 -device qemu-xhci -device usb-kbd \ 135 -drive if=none,id=usbstick,format=raw,file="${WORK_DIR}/usb.img" -device usb-storage,drive=usbstick \ 136 -drive if=none,id=nvme0,format=raw,file="${WORK_DIR}/nvme.img" -device nvme,drive=nvme0,serial=aienos-test \ 137 -display none -nic none \ 138 -serial file:"${DEV_LOG}" -no-reboot 139 DEV_STATUS=$? 140 set -e 141 142 tr -d '\r' <"${DEV_LOG}" >"${WORK_DIR}/recovery_devices.txt" 143 [[ -z "${AIENOS_LOG_DIR:-}" ]] || cp "${WORK_DIR}/recovery_devices.txt" "${AIENOS_LOG_DIR}/recovery_devices_serial.log" 144 echo "qemu exit ${DEV_STATUS}" 145 146 failed=0 147 check_devices() { 148 if grep -qE -- "$2" "${WORK_DIR}/recovery_devices.txt"; then 149 echo "PASS $1" 150 else 151 echo "FAIL $1" 152 failed=1 153 fi 154 } 155 modules_line=$(grep -m1 'Kernel modules loaded:' "${WORK_DIR}/recovery_devices.txt" || true) 156 if [[ "${modules_line}" =~ loaded:\ ([0-9]+)/([0-9]+) ]] && [[ "${BASH_REMATCH[1]}" == "${BASH_REMATCH[2]}" ]] && [[ "${BASH_REMATCH[2]}" -gt 0 ]]; then 157 echo "PASS All packaged kernel modules loaded (${BASH_REMATCH[1]}/${BASH_REMATCH[2]})" 158 else 159 echo "FAIL All packaged kernel modules loaded (${modules_line:-no report})" 160 failed=1 161 fi 162 check_devices "USB keyboard detected" "Input devices: [1-9]" 163 check_devices "USB stick visible" "^sda" 164 check_devices "NVMe drive visible" "^nvme0n1" 165 166 if [[ "${failed}" != 0 ]]; then 167 echo "---- recovery device console log ----" 168 cat "${WORK_DIR}/recovery_devices.txt" 169 echo "RECOVERY_DEVICES: FAIL" 170 exit 1 171 fi 172 173 echo "RECOVERY_DEVICES: PASS (packaged drivers found USB keyboard, USB stick and NVMe)"