Skip to content
emmanuel-delogetPublic

About

Build filesystem images in pure Go — ext4, squashfs, EROFS, FAT, exFAT, ISO9660, UDF, cpio, QCOW2 and more. No root, no cgo, no shelling out, zero dependencies, reproducible by construction.

Topics

Resources

Contributing

Security policy

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

109 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fsforge

CI Go Reference Release License: MIT

emmanueldeloget.com/fsforge — what it builds, in fewer words than this page.

Build filesystem images in pure Go — zero dependencies, no root, no cgo, no shelling out, and reproducible by construction.

fsforge turns a directory (or an OCI image, or another filesystem image) into a valid, mountable filesystem image, entirely in-process. It targets the case Go has long lacked: producing real filesystem images in unprivileged CI, on any host OS — OS/appliance images, container and embedded rootfs, VM disks, and reproducible build artifacts.

Memory does not follow image size

Memory held and bytes written while building a 4 GiB ext4 image: memory rises to 44 MiB while the tree is built, then stays flat as 3.4 GiB are written

Contents flow through tree.Source and are streamed at finalize, so what fsforge holds is the metadata tree and nothing else — roughly a kilobyte per file. The plateau above does not move while the bytes written triple.

Which is why the two figures below are both true and neither is the whole story:

Source Held
one 2 GiB file 400 KiB
50 000 files, 3.4 GiB 44 MiB

Memory tracks the number of files, not their volume. A single enormous file costs almost nothing; a kernel tree costs a kilobyte an entry whatever its size. TestStreamingKeepsMemoryBounded pins the first case and fails if streaming stops.

Draw it on your own machine, corpus and all:

go run ./internal/profile -svg doc/profile.svg

It generates the source tree the first time (a few minutes, kept for later runs), measures, and writes the chart.

Nothing in fsforge is parallel, and it does not need to be: the same build takes 3.8 s on one core and 4.1 s on twelve, the difference being scheduling noise. A one-core CI runner is not a handicap.

Speed

A 66 MiB tree of 2 000 files with a rootfs-like size distribution, on an i7-8850H, -benchtime 3x:

Engine Throughput Image / input Allocated
ISO 9660 588 MB/s 1.02× 105 MB
ext4 500 MB/s 1.99× 109 MB
cpio 491 MB/s 1.00× 135 MB
EROFS 467 MB/s 1.05× 13 MB
squashfs 49 MB/s 0.18× 360 MB

squashfs is an order of magnitude slower because it is the only one compressing — that is also why its output is a fifth of the input. Reproduce with go test -run '^$' -bench . -benchmem .

Supported formats

Every format is a write target (fsforge creates it; some it can also read back to convert or mutate).

Format Create Load / convert source Validated with
ext2 / ext3 / ext4 ✅ ✅ e2fsck
squashfs ✅ ✅ unsquashfs
EROFS ✅ ✅ fsck.erofs
cpio newc (initramfs) ✅ ✅ cpio
UDF 2.01 ✅ ✅ kernel mount, udfinfo, 7z
cramfs ✅ ✅ 7z
romfs ✅ ✅ genromfs
FAT12 / 16 / 32 ✅ — fsck.fat
exFAT ✅ ✅ fsck.exfat
ISO9660 + Rock Ridge ✅ ✅ xorriso
OCI image layout ✅ ✅ (flatten) podman
GPT / MBR disks ✅ — sfdisk + per-part fsck
QCOW2 container ✅ ✅ qemu-img

QCOW2 is a disk-image container, not a filesystem: it wraps any of the above. Give an output path ending in .qcow2 to mkfs, a convert sink, or fsforge disk and the result is a sparse QCOW2 (e.g. a bootable VM disk); QCOW2 inputs are decoded transparently.

Install

Library:

go get github.com/emmanuel-deloget/fsforge

CLI:

go install github.com/emmanuel-deloget/fsforge/cmd/fsforge@latest

fsforge has zero third-party dependencies: it imports only the Go standard library, so its go.mod carries no require block and there is no go.sum — nothing transitive to vendor, audit or keep up to date. The external tools in the table above are used only by the conformance tests, never by the library or CLI at runtime.

In a GitHub workflow

- uses: emmanuel-deloget/fsforge@v1
  with:
    type: ext4
    source: ./rootfs
    output: rootfs.img
    size: 256M
    spec: rootfs.mtree      # ownership and device nodes

No privileged container, no loop device, no sudo. The action outputs the image's path, size and sha256, so a later step can attest or publish it without rehashing.

From a registry, in one step

fsforge convert -from docker://alpine:3.20 -to ext4:rootfs.img -size 256M

The image is pulled straight from the registry — no docker pull, no daemon, no local layout to prepare — flattened, and written as a filesystem. Every blob is checked against the digest that named it before it is used.

ref,