From 50bf5fae680261d5c24f3411bd8dd2a3081adee2 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Tue, 3 Nov 2026 15:14:55 +0900 Subject: cmd/earlyinit: initial process option for debugging This optionally halts the boot process to run the specified program. Signed-off-by: Ophestra --- cmd/earlyinit/main.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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") + } + } -- cgit v1.3.1