Build Linux initramfs cpio archives from OCaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

OCaml 76.7%
Dune 7.3%
Other 16.0%
13 1 0

Clone this repository

https://tangled.org/gazagnaire.org/ocaml-initramfs https://tangled.org/did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-initramfs
git@git.recoil.org:gazagnaire.org/ocaml-initramfs git@git.recoil.org:did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-initramfs

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

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), or Tree (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.