tawasuyu

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 1411Shell 141Markdown 85Rust 842918 Definiciones

⎇ 2976f3e5fd75db194f0445d017cef6fd707bfcba scripts/iso-image.sh Shell · 127 líneas · 6.1 KB Historia crudo

E5 medio live: ISO El Torito booteable con xorriso de hammer (primer corte) 2976f3e5f · sergio ·

1#!/bin/sh
2# iso-image.sh — Etapa E5 (SDD 13): produce un MEDIO LIVE booteable como ISO 9660 / El Torito.
3#
4# A diferencia de install-image.sh (E1, disco GPT con / persistente en vda2), un medio live arranca
5# ENTERO desde RAM: GRUB (El Torito) carga kernel + initramfs desde el ISO 9660, el kernel desempaqueta
6# el initramfs (el rootfs del producto) a un tmpfs y corre /init — sin tocar disco. Es el medio para
7# correr el instalador (`hammer install /dev/sdX`) en hardware nuevo, o para probar el sistema sin
8# instalarlo.
9#
10# El ISO lo ARMA `xorriso` construido por hammer desde fuente (recipes/xorriso.toml) — el host no lo
11# trae. La cadena de boot BIOS reusa los módulos GRUB i386-pc de E1, pero con el core El Torito
12# (formato i386-pc-eltorito + iso9660) en vez del core de disco (ext2 + biosdisk).
13#
14# Cadena: SeaBIOS → El Torito boot catalog → eltorito.img (cdboot+core GRUB) → lee (cd0)/boot/grub/
15# grub.cfg → `linux /boot/bzImage rdinit=/init` + `initrd /boot/initramfs.cpio.gz` → kernel desempaqueta
16# → /init (marcador + exec del init real del rootfs).
17#
18# Uso:
19#   ./scripts/iso-image.sh                       # crea work/hammer-live.iso
20#   BOOT=1 KVM=1 ./scripts/iso-image.sh          # además lo arranca desde el CD (auto-boot)
21#
22# Variables:
23#   ROOTFS   dir rootfs a empaquetar como initramfs   (default work/builder-rootfs)
24#   KERNEL   bzImage a embeber                          (default store/*-linux/boot/bzImage)
25#   ISO      ISO de salida                              (default work/hammer-live.iso)
26#   XORRISO  binario xorriso                            (default el del store; si no, host)
27#   GRUB_LIB módulos GRUB i386-pc                       (default /usr/lib/grub/i386-pc)
28#   CMDLINE  cmdline del kernel             (default "console=ttyS0 rdinit=/init")
29#   BOOT/KVM/MEM  passthrough al arranque de prueba
30set -eu
31ROOT="$(cd "$(dirname "$0")/.." && pwd)"
32cd "$ROOT"
33
34ROOTFS="${ROOTFS:-work/builder-rootfs}"
35ISO="${ISO:-work/hammer-live.iso}"
36KERNEL="${KERNEL:-$(ls store/*-linux/boot/bzImage 2>/dev/null | head -1)}"
37GRUB_LIB="${GRUB_LIB:-/usr/lib/grub/i386-pc}"
38CMDLINE="${CMDLINE:-console=ttyS0 rdinit=/init}"
39# xorriso: preferimos el construido por hammer (dogfooding de recipes/xorriso.toml); fallback al host.
40XORRISO="${XORRISO:-$(ls store/*-xorriso/usr/bin/xorriso 2>/dev/null | head -1)}"
41[ -n "$XORRISO" ] && [ -x "$XORRISO" ] || XORRISO="$(command -v xorriso 2>/dev/null || true)"
42
43[ -d "$ROOTFS" ] || { echo "no existe ROOTFS: $ROOTFS" >&2; exit 1; }
44[ -e "$ROOTFS/sbin/init" ] || { echo "ROOTFS sin /sbin/init" >&2; exit 1; }
45[ -n "$KERNEL" ] && [ -r "$KERNEL" ] || { echo "no encuentro el kernel (set KERNEL=<bzImage>)" >&2; exit 1; }
46[ -n "$XORRISO" ] || { echo "no encuentro xorriso (build recipes/xorriso.toml)" >&2; exit 1; }
47[ -d "$GRUB_LIB" ] && [ -r "$GRUB_LIB/cdboot.img" ] || { echo "faltan módulos GRUB i386-pc en $GRUB_LIB" >&2; exit 1; }
48command -v grub-mkimage >/dev/null 2>&1 || { echo "falta grub-mkimage" >&2; exit 1; }
49command -v cpio >/dev/null 2>&1 || { echo "falta cpio" >&2; exit 1; }
50
51echo "==> xorriso: $XORRISO ($("$XORRISO" -version 2>&1 | grep -m1 'xorriso version' || echo '?'))"
52
53STAGE="work/.iso-stage"
54rm -rf "$STAGE"
55ISO_ROOT="$STAGE/iso"
56RFS="$STAGE/rfs"
57mkdir -p "$ISO_ROOT/boot/grub/i386-pc" "$RFS"
58
59# --- initramfs: rootfs (hardlinks) + /init marcador que arranca el init real ---
60echo "==> staging initramfs desde $ROOTFS (hardlinks) + /init marcador"
61cp -al "$ROOTFS" "$RFS/root"
62# El cpio se arma desde $RFS/root; inyectamos /init ahí (rdinit=/init lo busca en la raíz del initramfs).
63cat > "$RFS/root/init" <<'INIT'
64#!/bin/sh
65# /init del medio live (Etapa E5): monta lo básico, deja un marcador inequívoco y arranca el init real.
66/bin/busybox mount -t proc     proc /proc 2>/dev/null || true
67/bin/busybox mount -t sysfs    sys  /sys  2>/dev/null || true
68/bin/busybox mount -t devtmpfs dev  /dev  2>/dev/null || true
69echo "HAMMER-ISO-LIVE-OK: medio live arrancado desde El Torito"
70exec /sbin/init
71INIT
72chmod +x "$RFS/root/init"
73
74echo "==> empaquetando initramfs.cpio.gz"
75( cd "$RFS/root" && find . -print0 | cpio --null -o -H newc -R 0:0 2>/dev/null | gzip -1 ) > "$ISO_ROOT/boot/initramfs.cpio.gz"
76
77# --- kernel + módulos GRUB + grub.cfg en el árbol del ISO ---
78cp "$KERNEL" "$ISO_ROOT/boot/bzImage"; chmod 0644 "$ISO_ROOT/boot/bzImage"
79cp "$GRUB_LIB"/*.mod "$GRUB_LIB"/*.lst "$ISO_ROOT/boot/grub/i386-pc/" 2>/dev/null || true
80cat > "$ISO_ROOT/boot/grub/grub.cfg" <<CFG
81set timeout=2
82set default=0
83serial --unit=0 --speed=115200
84terminal_input serial console
85terminal_output serial console
86insmod iso9660
87insmod normal
88menuentry "hammer (live)" {
89    linux /boot/bzImage $CMDLINE
90    initrd /boot/initramfs.cpio.gz
91}
92CFG
93
94# --- core GRUB El Torito: igual que el de disco pero con iso9660+biosdisk en vez de ext2 ---
95echo "==> grub-mkimage El Torito (formato i386-pc-eltorito, módulos iso9660)"
96grub-mkimage -O i386-pc-eltorito -p '/boot/grub' -o "$ISO_ROOT/boot/grub/i386-pc/eltorito.img" \
97    biosdisk iso9660 part_gpt part_msdos normal configfile linux echo ls boot search
98
99# --- armar el ISO con xorriso (personalidad mkisofs), El Torito + isohybrid MBR ---
100echo "==> xorriso: armando $ISO (El Torito BIOS + isohybrid MBR)"
101rm -f "$ISO"
102MBR_ARGS=""
103[ -r "$GRUB_LIB/boot_hybrid.img" ] && MBR_ARGS="--grub2-mbr $GRUB_LIB/boot_hybrid.img"
104# shellcheck disable=SC2086
105"$XORRISO" -as mkisofs \
106    -volid HAMMER_LIVE \
107    -graft-points \
108    $MBR_ARGS \
109    -b boot/grub/i386-pc/eltorito.img \
110    -no-emul-boot -boot-load-size 4 -boot-info-table \
111    --grub2-boot-info \
112    -o "$ISO" \
113    "$ISO_ROOT" 2>&1 | grep -viE "^xorriso : NOTE|Drive current|Media current|Media status|Media summary|libisofs:|^xorriso : UPDATE" || true
114
115[ -s "$ISO" ] || { echo "FALLO: xorriso no produjo el ISO" >&2; exit 1; }
116rm -rf "$STAGE"
117echo "==> ISO live creado: $(du -h "$ISO" | cut -f1) — $ISO"
118echo "    auto-boot: qemu-system-x86_64 -cdrom $ISO -boot d -nographic"
119
120if [ "${BOOT:-0}" = 1 ]; then
121    echo "==> arranque de prueba (desde el CD El Torito)"
122    accel=""
123    [ "${KVM:-0}" = 1 ] && [ -w /dev/kvm ] && accel="-enable-kvm -cpu host"
124    # shellcheck disable=SC2086
125    exec qemu-system-x86_64 -m "${MEM:-4096}" -no-reboot -nographic $accel \
126        -cdrom "$ISO" -boot d
127fi