initramfs: drop to sulogin when switch_root fails past the ACK

A failed move of /dev, /proc, /sys or /run is logged at dbg() level
and ignored, so the new init boots without its virtual filesystems
and falls over much later in some unrelated way.  The steps after,
chdir/mount/chroot and the final execl(), do return -1 on failure,
but by then all services are dead and the API socket is gone, so
there is nobody left to report to: the system hangs with a live but
useless PID 1.

Make a failed move fatal, and try all four moves even if one fails,
so a bad /dev does not also skip /proc, /sys and /run.  A plain
directory is not an error though: /run stays a plain directory on a
tmpfs rootfs, so only a path on a different device than / is treated
as a mount point and moved.

Any failure past the point of no return now drops to sulogin(1) for
a maintenance shell that reboots on exit, same as a fatal fsck() at
boot.  Signals are unblocked before the moves so the shell does not
inherit finit's blocked signal mask.

Signed-off-by: Paweł Sobczak <github@fixeq.qzz.io>
This commit is contained in:
Paweł Sobczak authored and Joachim Wiberg committed 2026-08-16 23:17:57 +02:00
1 parent 7263641953
commit ad02b343f2
3 files changed
+70 -32

No files matched your search

+1
View File
@@ -73,6 +73,7 @@ void iterate_proc (int (*cb)(int, void *), void *data);
int switch_root_precheck(const char *newroot, const char *newinit,
char *errbuf, size_t errbuflen);
int switch_root (const char *newroot, const char *newinit);
int sulogin (int do_reboot);
#endif /* FINIT_PRIVATE_H_ */