initramfs

package
v0.15.5 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package initramfs provides functions for building the initramfs for virtrun. The initramfs is a CPIO archive that is written into a temporary file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitProgFor added in v0.15.3

func InitProgFor(arch sys.Arch) (fs.File, error)

InitProgFor returns the pre-built init executable for the given architecture.

The init binary is supposed to set up the system and execute the file "/main".

func WriteToTempFile added in v0.15.3

func WriteToTempFile(fsys fs.FS, dir string, prefix string) (string, error)

WriteToTempFile writes the fs.FS as CPIO archive into a new temporary file with the given prefix and returns the absolute path to this file.

If the given dir name is not empty, the file is created in this directory. Otherwise the default tempdir is used. See os.CreateTemp.

Types

type FS added in v0.12.0

type FS = virtfs.FS

FS is a virtual file system tree that represents the initramfs.

func New

func New(ctx context.Context, cfg Spec) (*FS, error)

New creates a new initramfs CPIO archive file.

The archive consists of a main executable that is either executed directly or by the init program. All other files are added to the dataDir directory. Kernel modules are added to modulesDir directory. For all ELF files the dynamically linked shared objects are collected and added to the libsDir directory. The paths to the directories they have been found at are added as symlinks to the libsDir directory as well.

type Spec added in v0.15.3

type Spec struct {
	// Executable is the main binary that is either executed directly or by the
	// init program depending on the presence of [Initramfs.Init].
	Executable string

	// Files is a list of any additional files that should be added to the
	// dataDir directory. For ELF files the required dynamic libraries are
	// added the libsDir directory.
	Files []string

	// Modules is a list of kernel module files. They are added to the
	// modulesDir directory.
	Modules []string

	// Fsys is the file system all files should be copied from.
	Fsys fs.FS

	// Init provides the init program. If not set, the [Initramfs.Executable] is
	// used as init program itself and expected to handle system setup and clean
	// shutdown.
	Init fs.File
}

Spec specifies the input for initramfs archive creation.

Directories

Path Synopsis
init
cmd command
Simple init program that can be pre-compiled for multiple architectures and embedded into the main binary.
Simple init program that can be pre-compiled for multiple architectures and embedded into the main binary.

Jump to

Keyboard shortcuts

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