gioser

sergio/takana

> Una distribución Linux construida con un laboratorio funcional y hermético en el > sótano, y una terminal mutable, clásica y anárquica en el piso de arriba — diseñada > desde el suelo para que una IA programadora entienda, modifique y co…

TOML 1373Shell 116Rust 74Markdown 641915 Definiciones

⎇ a95a1126c381de2a6244a868b3fd28897df56dd8 scripts/boot-builder-vm.sh Shell · 68 líneas · 2.8 KB Historia crudo

scripts: tarea selfhost-verify end-to-end (correr el 4/4 in-VM en KVM) 7025f93bc · Sergio ·

1#!/usr/bin/env bash
2# boot-builder-vm.sh — Bootea el builder rootfs (Stage 1 + toolchain) en QEMU para correr el
3# rebuild in-rootfs (auto-alojamiento, SDD 11 §7; runbook §8c).
4#
5# El builder se arma con `hammer bootstrap builder … --out work/builder-rootfs` y se empaqueta como
6# initramfs (cpio newc + gzip). Aquí lo booteamos con arje-zero como PID 1: levanta hammerd + una
7# getty en consola y deja una shell. Desde ahí se corre el driver embebido:
8#
9#     rebuild-stage1
10#
11# que reconstruye stage1' con el toolchain de adentro y compara su content-hash con la referencia
12# (REF_CONTENT en /etc/hammer/rebuild.env) → ✓ REPRODUCIBLE / ✗ DIVERGENTE.
13#
14# Variables (override por entorno):
15#   INITRAMFS  cpio.gz del builder         (default work/builder.cpio.gz)
16#   KERNEL     bzImage/vmlinuz a bootear   (default /boot/vmlinuz-linux)
17#   MEM        RAM de la VM en MiB         (default 6144; el rootfs vive en RAM + espacio de build)
18#   CPU        modelo de CPU de QEMU       (default Broadwell; AVX2 bajo TCG, sin -cpu host sin KVM)
19#   KVM        1 ⇒ usa -enable-kvm -cpu host si hay /dev/kvm (mucho más rápido)
20#
21# RAM: el initramfs se desempaqueta a un tmpfs (~1.2 GB) y el rebuild Rust (arje-zero vendorea un
22# monorepo) necesita varios GB más, TODO en RAM. Con un host de ~7 GB y sin KVM esto va justo y lento
23# (TCG). Si el rebuild muere por OOM, sube MEM (y/o monta un disco para /work en vez de tmpfs).
24#
25# Uso:
26#   ./scripts/boot-builder-vm.sh
27#   MEM=12288 KVM=1 ./scripts/boot-builder-vm.sh
28
29set -euo pipefail
30
31REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
32INITRAMFS="${INITRAMFS:-$REPO_ROOT/work/builder.cpio.gz}"
33KERNEL="${KERNEL:-/boot/vmlinuz-linux}"
34MEM="${MEM:-6144}"
35CPU="${CPU:-Broadwell}"
36KVM="${KVM:-0}"
37
38[[ -f "$INITRAMFS" ]] || { echo "no existe el initramfs: $INITRAMFS (arma el builder y empaquétalo)" >&2; exit 1; }
39[[ -r "$KERNEL" ]]    || { echo "no puedo leer el kernel: $KERNEL (set KERNEL=…)" >&2; exit 1; }
40
41accel=()
42if [[ "$KVM" == "1" && -w /dev/kvm ]]; then
43    accel=(-enable-kvm -cpu host)
44    echo "==> KVM activo (-cpu host)"
45else
46    accel=(-cpu "$CPU")
47    echo "==> TCG (sin KVM); -cpu $CPU por AVX2. Lento — el rebuild Rust puede tardar."
48fi
49
50echo "==> kernel    : $KERNEL"
51echo "==> initramfs : $INITRAMFS ($(du -h "$INITRAMFS" | cut -f1))"
52echo "==> mem       : ${MEM} MiB"
53echo "==> en la consola, tras el boot: corre  rebuild-stage1"
54echo
55
56# NIC e1000 (qemu user-mode 10.0.2.0/24): el rebuild Rust hace `cargo vendor` desde crates.io ⇒
57# necesita red. El builder la levanta (insmod e1000.ko + eth0 estática). NET=0 la desactiva.
58net=()
59[[ "${NET:-1}" == "1" ]] && net=(-netdev user,id=n0 -device e1000,netdev=n0)
60
61exec qemu-system-x86_64 \
62    -m "$MEM" \
63    -no-reboot -nographic \
64    "${accel[@]}" \
65    "${net[@]}" \
66    -kernel "$KERNEL" \
67    -initrd "$INITRAMFS" \
68    -append "console=ttyS0 rdinit=/sbin/init"