initramfs

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: MIT Imports: 9 Imported by: 0

README

initramfs

PkgGoDev

initramfs is a library for creating simple initramfs CPIO archives.

See Go package reference for full package documentation.

Documentation

Overview

Package initramfs provides a simple library for creating Linux initramfs archives.

A simple program creating an initramfs archive and writing it to stdout can be found in "cmd/mkinitramfs".

Only regular files are copied from the local file system. Mode is always set to 0755. For all added ELF file, the linked libraries can be resolved and added to the archive by calling Archive.ResolveLinkedLibs.

Index

Constants

View Source
const (
	// LibsDir is the archive's directory for all dynamically linked libraries.
	LibsDir = "lib"
	// AdditionalFilesDir is the archive's directory for all additional files
	// beside the init file.
	FilesDir = "files"
	// LibSearchPath defines the directories to lookup linked libraries.
	LibSearchPath = "/lib:/lib64:/usr/lib:/usr/lib64:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Archive

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

Archive represents a file tree that can be used as an initramfs for the Linux kernel.

Create a new instance using New. Additional files can be added with Archive.AddFiles. Dynamically linked ELF libraries can be resolved and added for all already added files by calling Archive.ResolveLinkedLibs. Once ready, write the Archive with Archive.WriteCPIO.

func New

func New(initFilePath string) *Archive

New creates a new Archive with the given file added as "/init". The file path must be absolute or relative to "/".

func (*Archive) AddFile

func (a *Archive) AddFile(name, path string) error

AddFile creates FilesDir and adds the given file to it. If name is empty the base name of the file is used. The file path must be absolute or relative to "/".

func (*Archive) AddFiles

func (a *Archive) AddFiles(paths ...string) error

AddFiles creates FilesDir and adds the given files to it. The file paths must be absolute or relative to "/".

func (*Archive) ResolveLinkedLibs

func (a *Archive) ResolveLinkedLibs(searchPath string) error

ResolveLinkedLibs recursively resolves the dynamically linked libraries of all regular files in the Archive.

If the given searchPath string is empty the default LibSearchPath is used. Resolved libraries are added to LibsDir. For each search path a symoblic link is added pointiong to LibsDir.

func (*Archive) WriteCPIO

func (a *Archive) WriteCPIO(writer io.Writer) error

WriteCPIO writes the Archive as CPIO archive to the given writer.

Directories

Path Synopsis
cmd
internal
files
Package files provides a simple file tree abstraction.
Package files provides a simple file tree abstraction.

Jump to

Keyboard shortcuts

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