uroot

package
v0.0.0-...-1cf9f48 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2018 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRamfs = []cpio.Record{
	cpio.Directory("tcz", 0755),
	cpio.Directory("etc", 0755),
	cpio.Directory("dev", 0755),
	cpio.Directory("ubin", 0755),
	cpio.Directory("usr", 0755),
	cpio.Directory("usr/lib", 0755),
	cpio.Directory("lib64", 0755),
	cpio.Directory("bin", 0755),
	cpio.CharDev("dev/console", 0600, 5, 1),
	cpio.CharDev("dev/tty", 0666, 5, 0),
	cpio.CharDev("dev/null", 0666, 1, 3),
	cpio.CharDev("dev/port", 0640, 1, 4),
	cpio.CharDev("dev/urandom", 0666, 1, 9),
	cpio.StaticFile("etc/resolv.conf", nameserver, 0644),
	cpio.StaticFile("etc/localtime", gmt0, 0644),
}

DefaultRamfs are files that are contained in all u-root initramfs archives by default.

Functions

func CreateInitramfs

func CreateInitramfs(opts Opts) error

CreateInitramfs creates an initramfs built to `opts`' specifications.

func DefaultPackageImports

func DefaultPackageImports(env golang.Environ) ([]string, error)

DefaultPackageImports returns a list of default u-root packages to include.

func WriteFile

func WriteFile(w ArchiveWriter, src, dest string) error

WriteFile takes the file at `src` on the host system and adds it to the archive `w` at path `dest`.

If `src` is a directory, its children will be added to the archive as well.

Types

type ArchiveFiles

type ArchiveFiles struct {
	// Files is a map of relative archive path -> absolute host file path.
	Files map[string]string

	// Records is a map of relative archive path -> Record to use.
	//
	// TODO: While the only archive mode is cpio, this will be a
	// cpio.Record. If or when there is another archival mode, we can add a
	// similar uroot.Record type.
	Records map[string]cpio.Record
}

ArchiveFiles are host files and records to add to the resulting initramfs.

func BBBuild

func BBBuild(opts BuildOpts) (ArchiveFiles, error)

BBBuild is an implementation of Build for the busybox-like u-root initramfs.

BBBuild rewrites the source files of the packages given to create one busybox-like binary containing all commands in `opts.Packages`.

func BinaryBuild

func BinaryBuild(opts BuildOpts) (ArchiveFiles, error)

BinaryBuild builds all given packages as separate binaries and includes them in the archive.

func NewArchiveFiles

func NewArchiveFiles() ArchiveFiles

NewArchiveFiles returns a new archive files map.

func SourceBuild

func SourceBuild(opts BuildOpts) (ArchiveFiles, error)

SourceBuild is an implementation of Build that compiles the Go toolchain (go, compile, link, asm) and an init process. It includes source files for packages listed in `opts.Packages` to build from scratch.

func (ArchiveFiles) AddFile

func (af ArchiveFiles) AddFile(src string, dest string) error

AddFile adds a host file at `src` into the archive at `dest`.

func (ArchiveFiles) AddRecord

func (af ArchiveFiles) AddRecord(r cpio.Record) error

AddRecord adds a cpio.Record into the archive at `r.Name`.

func (ArchiveFiles) Contains

func (af ArchiveFiles) Contains(dest string) bool

Contains returns whether path `dest` is already contained in the archive.

func (ArchiveFiles) Rename

func (af ArchiveFiles) Rename(name string, newname string)

Rename renames a file in the archive.

func (ArchiveFiles) SortedKeys

func (af ArchiveFiles) SortedKeys() []string

SortedKeys returns a list of sorted paths in the archive.

func (ArchiveFiles) WriteTo

func (af ArchiveFiles) WriteTo(w ArchiveWriter) error

WriteTo writes all records and files in `af` to `w`.

type ArchiveOpts

type ArchiveOpts struct {
	// ArchiveFiles are the files to be included.
	//
	// Files in ArchiveFiles generally have priority over files in
	// DefaultRecords or BaseArchive.
	ArchiveFiles

	// DefaultRecords is a set of files to be included in the initramfs.
	DefaultRecords []cpio.Record

	// OutputFile is the file to write to.
	OutputFile ArchiveWriter

	// BaseArchive is an existing archive to add files to.
	//
	// BaseArchive may be nil.
	BaseArchive ArchiveReader

	// UseExistingInit determines whether the init from BaseArchive is used
	// or not, if BaseArchive is specified.
	//
	// If this is false, the "init" file in BaseArchive will be renamed
	// "inito" in the output archive.
	UseExistingInit bool
}

ArchiveOpts are the options for building the initramfs archive.

func (*ArchiveOpts) Write

func (opts *ArchiveOpts) Write() error

Write uses the given options to determine which files need to be written to the output file using the archive format `a` and writes them.

type ArchiveReader

type ArchiveReader interface {
	// ReadRecord reads a file record.
	ReadRecord() (cpio.Record, error)
}

ArchiveReader is an object that files can be read from.

type ArchiveWriter

type ArchiveWriter interface {
	// WriteRecord writes the given file record.
	WriteRecord(cpio.Record) error

	// Finish finishes the archive.
	Finish() error
}

ArchiveWriter is an object that files can be written to.

type Archiver

type Archiver interface {
	// OpenWriter opens an archive writer at `path`.
	//
	// If `path` is unspecified, implementations may choose an arbitrary
	// default location, potentially based on `goos` and `goarch`.
	OpenWriter(path, goos, goarch string) (ArchiveWriter, error)

	// Reader returns an ArchiveReader wrapper using the given io.Reader.
	Reader(io.ReaderAt) ArchiveReader
}

Archiver is an archive format that builds an archive using a given set of files.

func GetArchiver

func GetArchiver(name string) (Archiver, error)

GetArchiver returns the archive mode for the named archive.

type Build

type Build func(BuildOpts) (ArchiveFiles, error)

Build uses the given options to build Go packages and returns a list of files to be included in an initramfs archive.

func GetBuilder

func GetBuilder(name string) (Build, error)

GetBuilder returns the Build function for the named build mode.

type BuildOpts

type BuildOpts struct {
	// Env is the Go environment to use to compile and link packages.
	Env golang.Environ

	// Packages are the Go package import paths to compile.
	//
	// Builders need not support resolving packages by path.
	//
	// E.g. cmd/go or github.com/u-root/u-root/cmds/ls.
	Packages []string

	// TempDir is a temporary directory where the compilation mode compiled
	// binaries can be placed.
	//
	// TempDir should contain no files.
	TempDir string
}

BuildOpts are arguments to the Build function.

type CPIOArchiver

type CPIOArchiver struct {
	// Format is the name of the cpio format to use.
	Format string
}

CPIOArchiver is an implementation of Archiver for the cpio format.

func (CPIOArchiver) OpenWriter

func (ca CPIOArchiver) OpenWriter(path, goos, goarch string) (ArchiveWriter, error)

OpenWriter opens `path` as the correct file type and returns an ArchiveWriter pointing to `path`.

If `path` is empty, a default path of /tmp/initramfs.GOOS_GOARCH.cpio is used.

func (CPIOArchiver) Reader

func (ca CPIOArchiver) Reader(r io.ReaderAt) ArchiveReader

Reader implements Archiver.Reader.

type CommandTemplate

type CommandTemplate struct {
	Gopath  string
	CmdName string
	Init    string
}

type DirArchiver

type DirArchiver struct{}

DirArchiver implements Archiver for a directory.

func (DirArchiver) OpenWriter

func (da DirArchiver) OpenWriter(path, goos, goarch string) (ArchiveWriter, error)

OpenWriter implements Archiver.OpenWriter.

func (DirArchiver) Reader

func (da DirArchiver) Reader(io.ReaderAt) ArchiveReader

Reader implements Archiver.Reader.

Currently unsupported for directories.

type Opts

type Opts struct {
	// Env is the build environment (OS, arch, etc).
	Env golang.Environ

	// Builder is the build format.
	//
	// This can currently be "source" or "bb".
	Builder Build

	// Archiver is the initramfs archival format.
	//
	// Only "cpio" is currently supported.
	Archiver Archiver

	// Packages are the Go packages to add to the archive.
	//
	// Currently allowed formats:
	//   Go package imports; e.g. github.com/u-root/u-root/cmds/ls
	//   Paths to Go package directories; e.g. $GOPATH/src/github.com/u-root/u-root/cmds/ls
	//   Globs of paths to Go package directories; e.g. ./cmds/*
	Packages []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.
	ExtraFiles []string

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

	// OutputFile is the archive output file.
	OutputFile ArchiveWriter

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

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

Opts are the arguments to CreateInitramfs.

type Package

type Package struct {
	// contains filtered or unexported fields
}

func (*Package) CommandTemplate

func (p *Package) CommandTemplate() CommandTemplate

Directories

Path Synopsis
Package util contains various u-root utility functions.
Package util contains various u-root utility functions.

Jump to

Keyboard shortcuts

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