aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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")
+ }
+
}