aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmd/earlyinit
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-11-03 15:14:55 +0900
committerOphestra <cat@gensokyo.uk>2026-11-03 15:14:55 +0900
commit50bf5fae680261d5c24f3411bd8dd2a3081adee2 (patch)
tree605a0ab786619e8aa2cec73ffa7f8b991518fe70 /cmd/earlyinit
parentc94a4be92f4d9ba0d78b163f4350616738184cef (diff)
cmd/earlyinit: initial process option for debugging
This optionally halts the boot process to run the specified program. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'cmd/earlyinit')
-rw-r--r--cmd/earlyinit/main.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/cmd/earlyinit/main.go b/cmd/earlyinit/main.go
index 987faeab..cbbd6648 100644
--- a/cmd/earlyinit/main.go
+++ b/cmd/earlyinit/main.go
@@ -10,6 +10,7 @@ import (
"io"
"log"
"os"
+ "os/exec"
"os/signal"
"runtime"
"runtime/pprof"
@@ -81,6 +82,11 @@ func must1[T any](v T, err error) T {
const (
// optionSystem specifies devpath of the system device.
optionSystem = "system"
+ // optionInitial specifies an initial process that the earlyinit runs
+ // instead of the standard boot process after mounting filesystems. The
+ // system powers off on termination of the initial process with exit code
+ // 0, or panics on a non-zero exit code.
+ optionInitial = "initial"
// flagVerbose increases output verbosity.
flagVerbose = "verbose"
@@ -263,4 +269,19 @@ func main() {
))
go dispatchModprobe(ctx, s)
+ // debug option to halt the boot process and start a program
+ if name, ok := option[optionInitial]; ok {
+ cmd := exec.Command(name)
+ cmd.Env = []string{
+ "TERM=linux",
+ "PATH=/system/bin:/system/sbin",
+ }
+ cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
+ if err := cmd.Run(); err != nil {
+ log.Fatalln(err)
+ }
+ mustSyscall("power off", Reboot(LINUX_REBOOT_CMD_POWER_OFF))
+ panic("not reached")
+ }
+
}