From 10961ce47f30c0ea348fb20d2900cc725377b49f Mon Sep 17 00:00:00 2001 From: sergio Date: Fri, 19 Jun 2026 11:21:35 -0400 Subject: [PATCH] =?UTF-8?q?kernel-from-source:=20=E2=9C=93=20REPRODUCIBLE?= =?UTF-8?q?=20con=20kernel=20hammer=20(switch=5Froot=20wrapper)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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= KVM=1 MEM=16384 PRESEED=hammerd \ ./scripts/selfhost-verify.sh Co-Authored-By: Claude Opus 4.8 (1M context) --- scripts/selfhost-verify.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/scripts/selfhost-verify.sh b/scripts/selfhost-verify.sh index d4d26b42..120e6d2f 100755 --- a/scripts/selfhost-verify.sh +++ b/scripts/selfhost-verify.sh @@ -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)"