libinit

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: 17 Imported by: 0

Documentation

Overview

Package libinit creates the environment and root file system for u-root.

Index

Constants

This section is empty.

Variables

View Source
var (
	// These have to be created / mounted first, so that the logging works correctly.
	PreNamespace = []Creator{
		Dir{Name: "/dev", Mode: 0o777},

		Mount{Source: "devtmpfs", Target: "/dev", FSType: "devtmpfs"},
	}
	Namespace = []Creator{
		Dir{Name: "/buildbin", Mode: 0o777},
		Dir{Name: "/ubin", Mode: 0o777},
		Dir{Name: "/tmp", Mode: 0o777},
		Dir{Name: "/env", Mode: 0o777},
		Dir{Name: "/tcz", Mode: 0o777},
		Dir{Name: "/lib", Mode: 0o777},
		Dir{Name: "/usr/lib", Mode: 0o777},
		Dir{Name: "/var/log", Mode: 0o777},
		Dir{Name: "/go/pkg/linux_amd64", Mode: 0o777},

		Dir{Name: "/etc", Mode: 0o777},

		Dir{Name: "/proc", Mode: 0o555},
		Mount{Source: "proc", Target: "/proc", FSType: "proc"},
		Mount{Source: "tmpfs", Target: "/tmp", FSType: "tmpfs"},

		Dev{Name: "/dev/tty", Mode: unix.S_IFCHR | 0o666, Dev: 0x0500},
		Dev{Name: "/dev/urandom", Mode: unix.S_IFCHR | 0o444, Dev: 0x0109},
		Dev{Name: "/dev/port", Mode: unix.S_IFCHR | 0o640, Dev: 0x0104},
		Dev{Name: "/dev/ttyhvc0", Mode: unix.S_IFCHR | 0o666, Dev: 0xe500},

		Dir{Name: "/dev/pts", Mode: 0o777},
		Mount{Source: "devpts", Target: "/dev/pts", FSType: "devpts", Opts: "newinstance,ptmxmode=666,gid=5,mode=620"},

		Symlink{NewPath: "/dev/ptmx", Target: "/dev/pts/ptmx"},

		Dir{Name: "/dev/shm", Mode: 0o777},
		Mount{Source: "tmpfs", Target: "/dev/shm", FSType: "tmpfs"},

		Dir{Name: "/sys", Mode: 0o555},
		Mount{Source: "sysfs", Target: "/sys", FSType: "sysfs"},
		Mount{Source: "securityfs", Target: "/sys/kernel/security", FSType: "securityfs"},
		Mount{Source: "efivarfs", Target: "/sys/firmware/efi/efivars", FSType: "efivarfs"},
		Mount{Source: "debugfs", Target: "/sys/kernel/debug", FSType: "debugfs"},

		CpDir{Source: "/etc", Target: "/tmp/etc"},
		Mount{Source: "/tmp/etc", Target: "/etc", FSType: "tmpfs", Flags: unix.MS_BIND},
	}

	// cgroups are optional for most u-root users, especially
	// LinuxBoot/NERF. Some users use u-root for container stuff.
	CgroupsNamespace = []Creator{
		Mount{Source: "cgroup", Target: "/sys/fs/cgroup", FSType: "tmpfs"},
		Dir{Name: "/sys/fs/cgroup/memory", Mode: 0o555},
		Dir{Name: "/sys/fs/cgroup/freezer", Mode: 0o555},
		Dir{Name: "/sys/fs/cgroup/devices", Mode: 0o555},
		Dir{Name: "/sys/fs/cgroup/cpu,cpuacct", Mode: 0o555},
		Dir{Name: "/sys/fs/cgroup/blkio", Mode: 0o555},
		Dir{Name: "/sys/fs/cgroup/cpuset", Mode: 0o555},
		Dir{Name: "/sys/fs/cgroup/pids", Mode: 0o555},
		Dir{Name: "/sys/fs/cgroup/net_cls,net_prio", Mode: 0o555},
		Dir{Name: "/sys/fs/cgroup/hugetlb", Mode: 0o555},
		Dir{Name: "/sys/fs/cgroup/perf_event", Mode: 0o555},
		Symlink{NewPath: "/sys/fs/cgroup/cpu", Target: "/sys/fs/cgroup/cpu,cpuacct"},
		Symlink{NewPath: "/sys/fs/cgroup/cpuacct", Target: "/sys/fs/cgroup/cpu,cpuacct"},
		Symlink{NewPath: "/sys/fs/cgroup/net_cls", Target: "/sys/fs/cgroup/net_cls,net_prio"},
		Symlink{NewPath: "/sys/fs/cgroup/net_prio", Target: "/sys/fs/cgroup/net_cls,net_prio"},
		Mount{Source: "cgroup", Target: "/sys/fs/cgroup/memory", FSType: "cgroup", Opts: "memory"},
		Mount{Source: "cgroup", Target: "/sys/fs/cgroup/freezer", FSType: "cgroup", Opts: "freezer"},
		Mount{Source: "cgroup", Target: "/sys/fs/cgroup/devices", FSType: "cgroup", Opts: "devices"},
		Mount{Source: "cgroup", Target: "/sys/fs/cgroup/cpu,cpuacct", FSType: "cgroup", Opts: "cpu,cpuacct"},
		Mount{Source: "cgroup", Target: "/sys/fs/cgroup/blkio", FSType: "cgroup", Opts: "blkio"},
		Mount{Source: "cgroup", Target: "/sys/fs/cgroup/cpuset", FSType: "cgroup", Opts: "cpuset"},
		Mount{Source: "cgroup", Target: "/sys/fs/cgroup/pids", FSType: "cgroup", Opts: "pids"},
		Mount{Source: "cgroup", Target: "/sys/fs/cgroup/net_cls,net_prio", FSType: "cgroup", Opts: "net_cls,net_prio"},
		Mount{Source: "cgroup", Target: "/sys/fs/cgroup/hugetlb", FSType: "cgroup", Opts: "hugetlb"},
		Mount{Source: "cgroup", Target: "/sys/fs/cgroup/perf_event", FSType: "cgroup", Opts: "perf_event"},
	}
)
View Source
var ErrNoModulesFound = fmt.Errorf("no modules found")

ErrNoModulesFound is the error returned when InstallModulesFromDir does not find any valid modules in the path.

Functions

func Command

func Command(bin string, m ...CommandModifier) *exec.Cmd

Command constructs an *exec.Cmd object.

func Create

func Create(namespace []Creator, optional bool)

func CreateRootfs

func CreateRootfs()

CreateRootfs creates the default u-root file system.

func GetModulesFromCmdline

func GetModulesFromCmdline(m *InitModuleLoader) ([]string, error)

GetModulesFromCmdline finds kernel modules from the modules_load kernel parameter

func GetModulesFromConf

func GetModulesFromConf(pattern string) ([]string, error)

GetModulesFromConf finds kernel modules from .conf files in /lib/modules-load.d/

func InstallAllModules

func InstallAllModules() error

InstallAllModules installs kernel modules form the following locations in order: - .ko files from /lib/modules - modules found in .conf files from /lib/modules-load.d/ - modules found in the cmdline argument modules_load= separated by , Useful for modules that need to be loaded for boot (ie a network driver needed for netboot). It skips over blacklisted modules in excludedMods.

func InstallModules

func InstallModules(m *InitModuleLoader, modules []string)

InstallModules installs the passed modules using the InitModuleLoader

func InstallModulesFromDir

func InstallModulesFromDir(pattern string, loader *InitModuleLoader) error

InstallModulesFromDir installs kernel modules (.ko files) from /lib/modules that match the given pattern, skipping those in the exclude list.

func NetInit

func NetInit()

NetInit is u-root network initialization.

func RunCommands

func RunCommands(debug func(string, ...interface{}), commands ...*exec.Cmd) int

FIX ME: make it not linux-specific RunCommands runs commands in sequence.

RunCommands returns how many commands existed and were attempted to run.

commands must refer to absolute paths at the moment.

func SetEnv

func SetEnv()

SetEnv sets the default u-root environment.

func WaitOrphans

func WaitOrphans() uint

WaitOrphans waits for all remaining processes on the system to exit.

Types

type CommandModifier

type CommandModifier func(c *exec.Cmd)

CommandModifier makes *exec.Cmd construction modular.

func WithArguments

func WithArguments(arg ...string) CommandModifier

WithArguments adds command-line arguments to a command.

func WithCloneFlags

func WithCloneFlags(flags uintptr) CommandModifier

WithCloneFlags adds clone(2) flags to the *exec.Cmd.

func WithTTYControl

func WithTTYControl(ctty bool) CommandModifier

WithTTYControl turns on controlling the TTY on this command.

type CpDir

type CpDir struct {
	Source string
	Target string
}

func (CpDir) Create

func (c CpDir) Create() error

func (CpDir) String

func (c CpDir) String() string

type Creator

type Creator interface {
	Create() error
	fmt.Stringer
}

type Dev

type Dev struct {
	Name string
	Mode uint32
	Dev  int
}

func (Dev) Create

func (d Dev) Create() error

func (Dev) String

func (d Dev) String() string

type Dir

type Dir struct {
	Name string
	Mode os.FileMode
}

func (Dir) Create

func (d Dir) Create() error

func (Dir) String

func (d Dir) String() string

type InitModuleLoader

type InitModuleLoader struct {
	Cmdline      *cmdline.CmdLine
	Prober       func(name string, modParameters string) error
	ExcludedMods map[string]bool
}

InitModuleLoader wraps the resources we need for early module loading

func NewInitModuleLoader

func NewInitModuleLoader() *InitModuleLoader

func (*InitModuleLoader) IsExcluded

func (i *InitModuleLoader) IsExcluded(mod string) bool

func (*InitModuleLoader) LoadModule

func (i *InitModuleLoader) LoadModule(mod string) error

type Mount

type Mount struct {
	Source string
	Target string
	FSType string
	Flags  uintptr
	Opts   string
}

func (Mount) Create

func (m Mount) Create() error

func (Mount) String

func (m Mount) String() string
type Symlink struct {
	Target  string
	NewPath string
}

func (Symlink) Create

func (s Symlink) Create() error

func (Symlink) String

func (s Symlink) String() string

Jump to

Keyboard shortcuts

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