aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmd/earlyinit
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-03-14 19:42:43 +0900
committerOphestra <cat@gensokyo.uk>2026-03-14 19:43:42 +0900
commit8905d653ba8ac5f2a70a6df654ebfa2a17206729 (patch)
tree094fbd8d18688f65dfe8275b5913e8323c730b1a /cmd/earlyinit
parent9c2fb6246f6a1781c469ac444da67dd4ae951ad2 (diff)
cmd/earlyinit: mount pseudo-filesystems
The proposal for merging both init programs was unanimously accepted, so this is set up here alongside devtmpfs. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'cmd/earlyinit')
-rw-r--r--cmd/earlyinit/main.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/cmd/earlyinit/main.go b/cmd/earlyinit/main.go
index 6dc08035..40883302 100644
--- a/cmd/earlyinit/main.go
+++ b/cmd/earlyinit/main.go
@@ -72,4 +72,40 @@ func main() {
}
}
+ // staying in rootfs, these are no longer used
+ must(os.Remove("/root"))
+ must(os.Remove("/init"))
+
+ must(os.Mkdir("/proc", 0))
+ mustSyscall("mount proc", Mount(
+ "proc",
+ "/proc",
+ "proc",
+ MS_NOSUID|MS_NOEXEC|MS_NODEV,
+ "hidepid=1",
+ ))
+
+ must(os.Mkdir("/sys", 0))
+ mustSyscall("mount sysfs", Mount(
+ "sysfs",
+ "/sys",
+ "sysfs",
+ 0,
+ "",
+ ))
+
+}
+
+// mustSyscall calls [log.Fatalln] if err is non-nil.
+func mustSyscall(action string, err error) {
+ if err != nil {
+ log.Fatalln("cannot "+action+":", err)
+ }
+}
+
+// must calls [log.Fatal] with err if it is non-nil.
+func must(err error) {
+ if err != nil {
+ log.Fatal(err)
+ }
}