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)"