kernel-from-source: ✓ REPRODUCIBLE con kernel hammer (switch_root wrapper)

CIERRA el frente kernel-from-source: el bzImage hammer-built (Linux 6.16.12,
recipes/linux.toml) bootea la VM del selfhost-verify y el rebuild in-VM reproduce
el of_tree bit a bit (✓ REPRODUCIBLE, DRIVER_RC=0, ~3min).

El muro era bwrap `pivot_root: Invalid argument`: con un kernel hammer el / del
initramfs es el rootfs absoluto del mount-namespace (sin mount padre movible), y
bwrap del sandbox no puede pivotar de ahí (el kernel host lo permitía — quirk
suyo; diagnosticado con un debug-loop de initramfs mínimo, boot ~10s).

Fix portable (HAMMER_KERNEL=1): un /init wrapper PID1 que copia el rootfs a un
tmpfs y hace switch_root, dejando / como mount tmpfs real (pivotable). bwrap
pivota en CUALQUIER kernel. Condicional ⇒ el camino del kernel host (rdinit=
/sbin/init directo) queda intacto. drive-rebuild.py: APPEND env override para
pasar rdinit=/init.

Uso: HAMMER_KERNEL=1 KERNEL=<bzImage> KVM=1 MEM=16384 PRESEED=hammerd \
  ./scripts/selfhost-verify.sh

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-19 11:21:35 -04:00
co-authored by Claude Opus 4.8
parent 3627894045
commit 10961ce47f
+26
View File
@@ -234,6 +234,32 @@ if [[ "$PRESEED" == "hammerd" ]]; then
done
fi
# 4c) HAMMER_KERNEL=1 — wrapper /init para escapar del rootfs (frente kernel-from-source).
# Con un kernel hammer-built (recipes/linux.toml) el `/` del initramfs es el rootfs ABSOLUTO del
# mount-namespace (su propio padre, no movible) y bwrap del sandbox falla en `pivot_root: Invalid
# argument` (el kernel host no lo exigía — quirk suyo). El fix portable (funciona en cualquier
# kernel): un /init PID1 que copia el rootfs a un tmpfs y hace `switch_root`, dejando `/` como un
# mount tmpfs real (pivotable). El kernel debe arrancar con rdinit=/init (ver APPEND abajo). Off por
# defecto ⇒ el camino del kernel host queda intacto (rdinit=/sbin/init directo).
if [[ "${HAMMER_KERNEL:-0}" == 1 ]]; then
say "HAMMER_KERNEL: inyectar /init wrapper (copy-to-tmpfs + switch_root, escapa del rootfs)"
cat > work/builder-rootfs/init <<'INIT'
#!/bin/sh
# PID1 wrapper: el rootfs del initramfs no es pivotable (bwrap pivot_root EINVAL); copiamos a un tmpfs
# y switch_root para que / sea un mount real. Luego exec del init real (arje-zero).
/bin/busybox mkdir -p /newroot
/bin/busybox mount -t tmpfs tmpfs /newroot
cd /
for e in /*; do
[ "$e" = /newroot ] && continue
/bin/busybox cp -a "$e" /newroot/
done
exec /bin/busybox switch_root /newroot /sbin/init
INIT
chmod +x work/builder-rootfs/init
export APPEND="console=ttyS0 rdinit=/init"
fi
# 5) Empaquetar como initramfs. --owner=root:root OBLIGATORIO: si los ficheros viajan con el uid del
# host, el userns de bwrap (mapea 0→0) no lo mapea y el copy-up de overlay falla con EACCES.
say "empaquetar initramfs (cpio newc, --owner=root:root)"