uroot

package
v3.0.0-...-66753ca Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2023 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package uroot creates root file systems from Go programs.

uroot will appropriately compile the Go programs, create symlinks for their names, and assemble an initramfs with additional files as specified.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateInitramfs

func CreateInitramfs(logger ulog.Logger, opts Opts) error

CreateInitramfs creates an initramfs built to opts' specifications.

func DefaultRamfs

func DefaultRamfs() *cpio.Archive

DefaultRamRamfs returns a cpio.Archive for the target OS. If an OS is not known it will return a reasonable u-root specific default.

func ParseExtraFiles

func ParseExtraFiles(logger ulog.Logger, archive *initramfs.Files, extraFiles []string, lddDeps bool) error

ParseExtraFiles adds files from the extraFiles list to the archive.

The following formats are allowed in the extraFiles list:

  • "/home/chrisko/foo:root/bar" adds the file from absolute path /home/chrisko/foo on the host at the relative root/bar in the archive.
  • "/home/foo" is equivalent to "/home/foo:home/foo".

ParseExtraFiles will also add ldd-listed dependencies if lddDeps is true.

Types

type Commands

type Commands struct {
	// Builder is the Go compiler mode.
	Builder builder.Builder

	// Packages are the Go commands to include (compiled or otherwise) and
	// add to the archive.
	//
	// Currently allowed formats:
	//
	//   - package imports; e.g. github.com/u-root/u-root/cmds/ls
	//   - globs of package imports; e.g. github.com/u-root/u-root/cmds/*
	//   - paths to package directories; e.g. $GOPATH/src/github.com/u-root/u-root/cmds/ls
	//   - globs of paths to package directories; e.g. ./cmds/*
	//
	// Directories may be relative or absolute, with or without globs.
	// Globs are resolved using filepath.Glob.
	Packages []string

	// BinaryDir is the directory in which the resulting binaries are
	// placed inside the initramfs.
	//
	// BinaryDir may be empty, in which case Builder.DefaultBinaryDir()
	// will be used.
	BinaryDir string
}

Commands specifies a list of Golang packages to build with a builder, e.g. in busybox mode, source mode, or binary mode.

See Builder for an explanation of build modes.

func BinaryCmds

func BinaryCmds(cmds ...string) []Commands

BinaryCmds returns a list of Commands with cmds built as a busybox.

func BusyBoxCmds

func BusyBoxCmds(cmds ...string) []Commands

BusyBoxCmds returns a list of Commands with cmds built as a busybox.

func (Commands) TargetDir

func (c Commands) TargetDir() string

TargetDir returns the initramfs binary directory for these Commands.

type Opts

type Opts struct {
	// Env is the Golang build environment (GOOS, GOARCH, etc).
	//
	// If nil, gbbgolang.Default is used.
	Env *gbbgolang.Environ

	// Commands specify packages to build using a specific builder.
	//
	// E.g. the following will build 'ls' and 'ip' in busybox mode, but
	// 'cd' and 'cat' as separate binaries. 'cd', 'cat', 'bb', and symlinks
	// from 'ls' and 'ip' will be added to the final initramfs.
	//
	//   []Commands{
	//     Commands{
	//       Builder: builder.BusyBox,
	//       Packages: []string{
	//         "github.com/u-root/u-root/cmds/ls",
	//         "github.com/u-root/u-root/cmds/ip",
	//       },
	//     },
	//     Commands{
	//       Builder: builder.Binary,
	//       Packages: []string{
	//         "github.com/u-root/u-root/cmds/cd",
	//         "github.com/u-root/u-root/cmds/cat",
	//       },
	//     },
	//   }
	Commands []Commands

	// UrootSource is the filesystem path to the locally checked out
	// u-root source tree. This is needed to resolve templates or
	// import paths of u-root commands.
	UrootSource string

	// TempDir is a temporary directory for builders to store files in.
	TempDir string

	// ExtraFiles are files to add to the archive in addition to the Go
	// packages.
	//
	// Shared library dependencies will automatically also be added to the
	// archive using ldd, unless SkipLDD (below) is true.
	//
	// The following formats are allowed in the list:
	//
	//   - "/home/chrisko/foo:root/bar" adds the file from absolute path
	//     /home/chrisko/foo on the host at the relative root/bar in the
	//     archive.
	//   - "/home/foo" is equivalent to "/home/foo:home/foo".
	ExtraFiles []string

	// If true, do not use ldd to pick up dependencies from local machine for
	// ExtraFiles. Useful if you have all deps revision controlled and wish to
	// ensure builds are repeatable, and/or if the local machine's binaries use
	// instructions unavailable on the emulated cpu.
	//
	// If you turn this on but do not manually list all deps, affected binaries
	// will misbehave.
	SkipLDD bool

	// OutputFile is the archive output file.
	OutputFile initramfs.Writer

	// BaseArchive is an existing initramfs to include in the resulting
	// initramfs.
	BaseArchive initramfs.Reader

	// UseExistingInit determines whether the existing init from
	// BaseArchive should be used.
	//
	// If this is false, the "init" from BaseArchive will be renamed to
	// "inito" (init-original).
	UseExistingInit bool

	// InitCmd is the name of a command to link /init to.
	//
	// This can be an absolute path or the name of a command included in
	// Commands.
	//
	// If this is empty, no init symlink will be created, but a user may
	// still specify a command called init or include an /init file.
	InitCmd string

	// UinitCmd is the name of a command to link /bin/uinit to.
	//
	// This can be an absolute path or the name of a command included in
	// Commands.
	//
	// The u-root init will always attempt to fork/exec a uinit program,
	// and append arguments from both the kernel command-line
	// (uroot.uinitargs) as well as specified in UinitArgs.
	//
	// If this is empty, no uinit symlink will be created, but a user may
	// still specify a command called uinit or include a /bin/uinit file.
	UinitCmd string

	// UinitArgs are the arguments passed to /bin/uinit.
	UinitArgs []string

	// DefaultShell is the default shell to start after init.
	//
	// This can be an absolute path or the name of a command included in
	// Commands.
	//
	// This must be specified to have a default shell.
	DefaultShell string

	// Build options for building go binaries. Ultimate this holds all the
	// args that end up being passed to `go build`.
	BuildOpts *gbbgolang.BuildOpts
}

Opts are the arguments to CreateInitramfs.

Opts contains everything that influences initramfs creation such as the Go build environment.

func (*Opts) AddBusyBoxCommands

func (o *Opts) AddBusyBoxCommands(pkgs ...string)

func (*Opts) AddCommands

func (o *Opts) AddCommands(c ...Commands)

AddCommands adds commands to the build.

Directories

Path Synopsis
test
bar
foo

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL