Uinit is a simple golang init process that is intended to be run from within u-root (but can run elsewhere too, say, as a light-weight container init).
Uinit is built to be scriptable with a simple YAML-format file. For an example script, see: cmds/uinit/uinit.script.
By default, uinit reads the script at the relative path ./uinit.script and writes tot he log file ./uinit.log. An alternative script can be specified on the commandline: ./uinit <path_to_script>
Uinit maintains a key/value store that allows for storing and recalling variables within the script. Variables can be accessed by placing strings of the format "{{.<key>}}" anywhere in the args section of a task. Technically, anything that can be processed by Go's text/template package can be placed here.
Uinit reads the script as a sequence of tasks. Each task calls a "module", and passes "args" to the module. Currently, we have the following modules:
- echo : Echo something to the log
- command : Execute a command. This can execute in foreground, background, or call Exec (which terminates uinit). Commands can be executed within a shell or directly.
- setvar : Sets a variable in the key/value store that can be later referenced.
- cmdline : Reads a file containing commandline arguments of the style:
uinit.<key>=<val>adn sets<key> = <val>in the key/value store. If formated asuinit.key, thenval="true"implicitly. This is intended primarily to read variables from/proc/cmdlinewhich is the default file to parse, allowing for uinit configuration by kernel parameters. The prefix, which defaults touinitcan be set to anything. - mount : Mount a filesystem.
- script : Run a subscript, either directly specified or in another script file.
More modules to come! (maybe?)
For more details on modules, see the example scripts, or look for README.md files in the modules/<module> directory.
go get -u github.com/kraken-hpc/uinit/cmds/uinitThis will builduinitand place it in$GOPATH/bin.- Write a script (see example
*.scriptfiles) - Run it, and either name the script
./uinit.script, or pass it as a commandline argument.
As of v0.2.0, uinit can also be used as a Go package. This package will let your application run uinit scripts natively.
As an example, to load and run a script from a file:
s, err := uinit.NewScriptFromFile("myscript.script", logger)
if err != nil {
log.Fatalf("failed to load script: %v", err)
}
if err = s.Run(); err != nil {
log.Fatalf("failed to run script: %v", err)
}For more details, see the package documentation at https://pkg.go.dev/github.com/kraken-hpc/uinit.
You can build uinit directly into u-root by adding the following commandline options to your u-root build:
-uinitcmd /bbin/uinit github.com/kraken-hpc/uinit/cmds/uinit
Then make sure that you have a uinit.script in the root of your base cpio.
If you intend to boot something with systemdout of this, you'll want to:
- have
uroot.systemdon your kernel commandline - put a built
uinitnamedinitoin the root of yourbase cpio