From 4bfb952d92859ecbee1e2d2c16cabff9deba16a2 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Tue, 10 Nov 2026 03:34:34 +0900 Subject: cmd/earlyinit: work around pivot_root limitation The rootfs (initial ramfs) cannot be pivot_root()ed. This change works around that limitation by making / a bind mount of the rootfs. Signed-off-by: Ophestra --- cmd/earlyinit/main.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'cmd') diff --git a/cmd/earlyinit/main.go b/cmd/earlyinit/main.go index 2f1eebef..42a8a9ca 100644 --- a/cmd/earlyinit/main.go +++ b/cmd/earlyinit/main.go @@ -153,6 +153,24 @@ func main() { msg := message.New(log.Default()) msg.SwapVerbose(slices.Contains(flags, flagVerbose)) + mustSyscall("bind root", Mount( + "/", + "/dev", + "", + MS_BIND|MS_REC, + "", + )) + must(os.Chdir("/dev")) + mustSyscall("move root", Mount( + "/dev", + "/", + "", + MS_MOVE, + "", + )) + mustSyscall("change root", Chroot(".")) + must(os.Chdir("/")) + mustSyscall("mount devtmpfs", Mount( "devtmpfs", "/dev/", -- cgit v1.3.1