initbuild

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package initbuild produces the initramfs cpio.gz consumed by the LinuxBootLoader path.

The artefact is a "newc"-format cpio archive (the format the Linux kernel's initrd loader expects), gzipped. The kernel unpacks it into the initial rootfs (tmpfs) and runs /init as PID 1. For mono-container that init is `weft-microvm-init`; for pod mode it's `weft-init`, and the same archive also carries the helper binaries the guest execs (crun, cfs-client, the in-VM agent) at their own paths — no go:embed, no extraction copy, the kernel places them directly.

Cross-compilation is deliberately NOT done here: the operator produces the Linux binaries (`GOOS=linux GOARCH=<arch> go build …`) and passes their paths. Keeps this package small and reusable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pack

func Pack(initBinary string, out io.Writer) error

Pack writes a single-entry initramfs (/init = initBinary). Thin back-compat wrapper over PackFiles for the mono-binary case.

func PackFiles

func PackFiles(files []File, out io.Writer) error

PackFiles writes a gzipped newc cpio archive to out containing each File at its Path (with parent directory entries emitted first), all owned by root:root. This is how a pod-mode initramfs carries /init plus the helper binaries (bin/crun, bin/cfs-client, bin/weft-microvm-agent) the guest execs from $PATH.

Both the cpio trailer and the gzip footer are flushed explicitly; a close failure surfaces as the function's error rather than silently producing a truncated archive a kernel cannot unpack.

func PackFilesToFile

func PackFilesToFile(files []File, dst string) (rerr error)

PackFilesToFile is the convenience wrapper that opens dst (0644) and hands it to PackFiles. Close errors surface as the return value, so a short write at flush time (disk full, quota) doesn't leave a truncated initramfs on disk under the guise of success.

func PackToFile

func PackToFile(initBinary, dst string) (rerr error)

PackToFile is the convenience wrapper that opens dst (0644) and hands it to Pack. Close errors surface as the return value so a short write at flush time doesn't leave a truncated initramfs.

func PodInitrd

func PodInitrd(dst, initBin, crunBin, cfsBin, agentBin string) error

PodInitrd packs a pod-mode initramfs at dst: /init (weft-init) plus the guest helper binaries at bin/<name> (crun, cfs-client, the in-VM agent). Empty helper paths are skipped, so a build can ship only what it needs. The guest resolves them from $PATH (/bin) — no go:embed, no extraction.

Types

type File

type File struct {
	// Path is the in-initramfs path with no leading slash, e.g. "init"
	// or "bin/crun". Parent directories are created automatically.
	Path string
	// Source is the host path to read the bytes from.
	Source string
	// Mode is the unix permission bits; 0 defaults to 0755.
	Mode uint32
}

File is one regular-file entry to place in the initramfs.

Jump to

Keyboard shortcuts

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