initramfs#
Build initramfs cpio archives from file and directory entries.
High-level API for creating Linux initramfs images in cpio newc format.
Supports adding empty directories, files from disk (preserving permissions),
inline content with explicit permissions, and recursive directory trees. Built
on top of the cpio library.
Installation#
Install with opam:
$ opam install initramfs
If opam cannot find the package, it may not yet be released in the public
opam-repository. Add the overlay repository, then install it:
$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install initramfs
Usage#
(* Build a cpio newc archive suitable as a Linux initramfs. *)
let build_initramfs ~init_path ~rootfs =
Initramfs.build
[
Initramfs.Dir "/etc";
Initramfs.File { name = "/init"; path = init_path };
Initramfs.Content
{ name = "/etc/hostname"; data = "spaceos\n"; perm = 0o644 };
Initramfs.Tree rootfs;
]
API#
entry-- Describes an archive entry:Dir(empty directory),File(file from disk, renamed in the archive),Content(inline data with explicit permissions), orTree(recursive directory walk).build-- Takes a list of entries and produces a cpio newc archive as a string. Directories are created with 0o755 permissions; files from disk preserve their original permissions.