boot

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: BSD-3-Clause Imports: 16 Imported by: 209

Documentation

Overview

Package boot is the high-level interface for booting another operating system from Linux using kexec.

Index

Constants

This section is empty.

Variables

View Source
var Verbose = WithLogger(ulog.Log)

Verbose is a LoadOption that logs to log.Default().

Functions

func ApplyLinuxModifiers added in v0.13.1

func ApplyLinuxModifiers(images []OSImage, opts ...LinuxModifier)

ApplyLinuxModifiers applies opts to every LinuxImage in images.

func ApplyMultibootModifiers added in v0.13.1

func ApplyMultibootModifiers(images []OSImage, opts ...MultibootModifier)

ApplyMultibootModifiers applies opts to every MultibootImage in images.

func CatInitrds

func CatInitrds(initrds ...io.ReaderAt) io.ReaderAt

CatInitrds concatenates initrds on first ReadAt call from a list of io.ReaderAts, pads them to a 512 byte boundary.

func CatInitrdsWithFileCache added in v0.12.0

func CatInitrdsWithFileCache(initrds ...io.Reader) io.ReaderAt

CatInitrdsWithFileCache lazily reads up multiple initrds into single tmpfs file and return a os.File disguising as a io.ReaderAt. It starts processing after first ReadAt call is made.

func CopyToFileIfNotRegular added in v0.12.0

func CopyToFileIfNotRegular(r io.ReaderAt, verbose bool) (*os.File, error)

CopyToFileIfNotRegular copies given io.ReadAt to a tmpfs file when necessary. It skips copying when source file is a regular file under tmpfs or ramfs, and it is not opened for writing.

Copy is necessary for other cases, such as when the reader is an io.File but not sufficient for kexec, as os.File could be a socket, a pipe or some other strange thing. Also kexec_file_load will fail (similar to execve) if anything has the file opened for writing. That's unfortunately something we can't guarantee here - unless we make a copy of the file and dump it somewhere.

func CreateInitrd added in v0.9.0

func CreateInitrd(files ...string) (io.ReaderAt, error)

CreateInitrd creates an initrd with the collection of files passed in.

func Execute

func Execute() error

Execute executes a previously loaded OSImage.

This will only work if OSImage.Load was called on some OSImage.

Types

type LinuxImage

type LinuxImage struct {
	Name string

	Kernel      io.ReaderAt
	Initrd      io.ReaderAt
	Cmdline     string
	BootRank    int
	LoadSyscall bool
	DTB         io.ReaderAt

	// ReservedRanges are additional physical memory pieces that will be
	// avoided when allocating kexec segments. Only used for LoadSyscall.
	//
	// ReservedRanges will not be shared with the next kernel, which is
	// free to use this memory unless some other mechanism (such as
	// memmap=) reserves it.
	ReservedRanges kexec.Ranges
}

LinuxImage implements OSImage for a Linux kernel + initramfs.

func (*LinuxImage) Edit

func (li *LinuxImage) Edit(f func(cmdline string) string)

Edit the kernel command line.

func (*LinuxImage) Label

func (li *LinuxImage) Label() string

Label returns either the Name or a short description.

func (*LinuxImage) Load

func (li *LinuxImage) Load(opts ...LoadOption) error

Load implements OSImage.Load and kexec_load's the kernel with its initramfs.

func (*LinuxImage) Rank

func (li *LinuxImage) Rank() int

Rank for the boot menu order

func (*LinuxImage) String

func (li *LinuxImage) String() string

String prints a human-readable version of this linux image.

type LinuxModifier added in v0.13.1

type LinuxModifier func(img *LinuxImage)

LinuxModifier modifies a Linux image.

func AppendLinux added in v0.13.1

func AppendLinux(cmdline string) LinuxModifier

AppendLinux appends cmdline to any existing Linux cmdline.

func PrependLinux added in v0.13.1

func PrependLinux(cmdline string) LinuxModifier

PrependLinux prepends cmdline to any existing Linux cmdline.

type LoadOption added in v0.12.0

type LoadOption func(*loadOptions)

LoadOption is an optional parameter to Load.

func WithDryRun added in v0.12.0

func WithDryRun(dryRun bool) LoadOption

WithDryRun is a LoadOption that makes sure no kexec_load syscall is called during Load.

func WithLogger added in v0.12.0

func WithLogger(l ulog.Logger) LoadOption

WithLogger is a LoadOption that logs verbose debug output l.

func WithVerbose added in v0.12.0

func WithVerbose(verbose bool) LoadOption

WithVerbose enables verbose logging if verbose is set to true.

type MultibootImage

type MultibootImage struct {
	Name string

	Kernel   io.ReaderAt
	Cmdline  string
	Modules  []multiboot.Module
	IBFT     *ibft.IBFT
	BootRank int
}

MultibootImage is a multiboot-formated OSImage, such as ESXi, Xen, Akaros, tboot.

func (*MultibootImage) Edit

func (mi *MultibootImage) Edit(f func(cmdline string) string)

Edit the kernel command line.

func (*MultibootImage) Label

func (mi *MultibootImage) Label() string

Label returns either Name or a short description.

func (*MultibootImage) Load

func (mi *MultibootImage) Load(opts ...LoadOption) error

Load implements OSImage.Load.

func (*MultibootImage) Rank

func (mi *MultibootImage) Rank() int

Rank for the boot menu order

func (*MultibootImage) String

func (mi *MultibootImage) String() string

String implements fmt.Stringer.

type MultibootModifier added in v0.13.1

type MultibootModifier func(img *MultibootImage)

MultibootModifier modifies a multiboot image.

type OSImage

type OSImage interface {
	fmt.Stringer

	// Label is a name or short description for this OSImage.
	//
	// Label is intended for boot menus.
	Label() string

	// Rank the priority of the images for boot menus.
	//
	// The larger the number, the prior the image shows in the menu.
	Rank() int

	// Edit the kernel command line if possible. Must be called before
	// Load.
	Edit(func(cmdline string) string)

	// Load loads the OS image into kernel memory, ready for execution.
	//
	// After Load is called, call boot.Execute() to stop Linux and boot the
	// loaded OSImage.
	Load(opts ...LoadOption) error
}

OSImage represents a bootable OS package.

Directories

Path Synopsis
Package bls parses systemd Boot Loader Spec config files.
Package bls parses systemd Boot Loader Spec config files.
Package bootcmd handles common cleanup functions and flags that all boot commands should support.
Package bootcmd handles common cleanup functions and flags that all boot commands should support.
Package boottest contains methods for comparing boot.OSImages to each other and to JSON representations of themselves for use in tests.
Package boottest contains methods for comparing boot.OSImages to each other and to JSON representations of themselves for use in tests.
Package bzimage implements decoding for bzImage files.
Package bzimage implements decoding for bzImage files.
Package ebda looks for the Extended Bios Data Area (EBDA) pointer in /dev/mem, and provides access to the EBDA.
Package ebda looks for the Extended Bios Data Area (EBDA) pointer in /dev/mem, and provides access to the EBDA.
Package esxi contains an ESXi boot config parser for disks and CDROMs.
Package esxi contains an ESXi boot config parser for disks and CDROMs.
Package fit provides tools to read and verify FIT kernel images See https://doc.coreboot.org/lib/payloads/fit.html
Package fit provides tools to read and verify FIT kernel images See https://doc.coreboot.org/lib/payloads/fit.html
Package grub implements a grub config file parser.
Package grub implements a grub config file parser.
Package ibft defines the iSCSI Boot Firmware Table.
Package ibft defines the iSCSI Boot Firmware Table.
Package image contains a parser for Arm64 Linux Image format.
Package image contains a parser for Arm64 Linux Image format.
Package kexec implements kexec load and file load syscall API.
Package kexec implements kexec load and file load syscall API.
The linux package loads bzImage-based Linux kernels using the kexec_load system call.
The linux package loads bzImage-based Linux kernels using the kexec_load system call.
Package localboot contains helper functions for booting off local disks.
Package localboot contains helper functions for booting off local disks.
Package menu displays a Terminal UI based text menu to choose boot options from.
Package menu displays a Terminal UI based text menu to choose boot options from.
Package multiboot implements bootloading multiboot kernels as defined by https://www.gnu.org/software/grub/manual/multiboot/multiboot.html.
Package multiboot implements bootloading multiboot kernels as defined by https://www.gnu.org/software/grub/manual/multiboot/multiboot.html.
internal/trampoline
Package trampoline sets machine to a specific state defined by multiboot v1 spec and jumps to the intended kernel.
Package trampoline sets machine to a specific state defined by multiboot v1 spec and jumps to the intended kernel.
Package netboot provides a one-stop shop for netboot parsing needs.
Package netboot provides a one-stop shop for netboot parsing needs.
ipxe
Package ipxe implements a trivial IPXE config file parser.
Package ipxe implements a trivial IPXE config file parser.
pxe
Package pxe implements the PXE config file parsing.
Package pxe implements the PXE config file parsing.
Package purgatory provides several purgatories for use with kexec_load system call.
Package purgatory provides several purgatories for use with kexec_load system call.
Package syslinux implements a syslinux config file parser.
Package syslinux implements a syslinux config file parser.
Package zbi contains a parser for the Zircon boot image format.
Package zbi contains a parser for the Zircon boot image format.
Package zimage contains a Parser for the arm zImage Linux format.
Package zimage contains a Parser for the arm zImage Linux format.

Jump to

Keyboard shortcuts

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