aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmd/earlyinit/mount.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-05-26 19:16:32 +0900
committerOphestra <cat@gensokyo.uk>2026-05-27 10:37:45 +0900
commit8c7109a2d58c40b86ad97ed520aff6b00bbf1667 (patch)
tree547f611b77e98f5df433ba513cbcbc9dc47e4b8e /cmd/earlyinit/mount.go
parentcaf3e0db4b92d859599ee199b32051fae8c99016 (diff)
cmd/earlyinit: mount system device
This currently relies on a trusted bootloader to determine the boot device. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'cmd/earlyinit/mount.go')
-rw-r--r--cmd/earlyinit/mount.go69
1 files changed, 69 insertions, 0 deletions
diff --git a/cmd/earlyinit/mount.go b/cmd/earlyinit/mount.go
new file mode 100644
index 00000000..6ac59a46
--- /dev/null
+++ b/cmd/earlyinit/mount.go
@@ -0,0 +1,69 @@
+package main
+
+import (
+ "context"
+ "errors"
+ "os"
+ "path/filepath"
+ "strconv"
+ "syscall"
+ "time"
+
+ "hakurei.app/check"
+ "hakurei.app/fhs"
+ "hakurei.app/internal/kobject"
+)
+
+// mustMountSystem waits for and mounts a system device matching pattern.
+func mustMountSystem(
+ ctx context.Context,
+ s *kobject.State,
+ pattern string,
+) {
+ c, stop := context.WithTimeout(ctx, 30*time.Second)
+ defer stop()
+
+ for {
+ var matchErr error
+ var systemPath *check.Absolute
+ s.Range(c, func(o *kobject.Object) bool {
+ if o.Subsystem != "block" ||
+ o.Env["DEVTYPE"] != "disk" {
+ return true
+ }
+
+ if ok, err := filepath.Match(pattern, o.DevPath); err != nil {
+ matchErr = err
+ return false
+ } else if !ok {
+ return true
+ }
+
+ name, ok := o.Env["DEVNAME"]
+ if !ok {
+ return true
+ }
+ systemPath = fhs.AbsDev.Append(name)
+ return false
+ })
+ if c.Err() != nil {
+ fatal("devpath", strconv.Quote(pattern), "never appeared")
+ }
+ if matchErr != nil {
+ fatal("cannot match system devpath:", matchErr)
+ }
+ err := syscall.Mount(
+ systemPath.String(),
+ "/system/",
+ "squashfs",
+ 0,
+ "threads=multi",
+ )
+ if err == nil {
+ break
+ }
+ if !errors.Is(err, os.ErrNotExist) {
+ fatal("cannot mount system:", err)
+ }
+ }
+}