Build Linux initramfs cpio archives from OCaml
OCaml 79.8%
Dune 6.8%
Other 13.4%
5 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#

opam install initramfs

Usage#

let archive = Initramfs.build [
  Dir "/etc";
  File { name = "/init"; path = "./my-init" };
  Content { name = "/etc/hostname"; data = "spaceos\n"; perm = 0o644 };
  Tree "./rootfs";
]
(* archive is a cpio newc string, suitable for use as a Linux initramfs *)

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.