Skip to content

image: Store filesystem snapshots in manifests - #406

Open
daandemeyer wants to merge 14 commits into
amutable:mainfrom
daandemeyer:manifest-image-storage
Open

daandemeyer wants to merge 14 commits into
amutable:mainfrom
daandemeyer:manifest-image-storage

Conversation

@daandemeyer

Copy link
Copy Markdown
Member

Buck directory artifacts lose inode metadata and cannot preserve every logical
filename. Let's capture complete UAPI.16 snapshots in image-producing actions
and store regular contents in immutable SHA-256 blobs. Derived images retain
parent stores as explicit inputs and add only newly introduced blobs. Metadata
changes affect cache keys without duplicating unchanged data. UAPI.16 records
use mTimeNSec and the required trailer.

Image roots first try explicit reflinks into temporary private files. Independent
files have separate inodes; declared hardlink groups share only their private
inode. Unsupported or denied reflinks discard the partial tree and select an
OverlayFS root with separate lower metadata and data-only blob layers. Writable
hardlink groups start as private upper files. Selection uses actual clone support,
so separate btrfs filesystems do not accidentally trigger full byte copies.
Read-only roots use either a read-only bind mount or a read-only overlay.

Unprivileged OverlayFS can report different inode numbers when a command adds a
hardlink to an inherited file. Capture uses the actual upper inode to preserve
that group in snapshots and exports. Repart and terminal readers that apply
tmpfiles use full private roots when their consumers need consistent raw inode
identity. Metadata restoration and later writes leave cached blobs unchanged.
Boxes retain their directory layers and direct startup path.

Archive writers consume manifests and blobs directly when possible. Terminal
listings describe the processed output, including package-database removal and
timestamp clamping. Directory outputs keep an authoritative manifest and provide
an exporter that restores metadata after Buck materialization.
Exports require a new destination under a parent owned by the caller or root,
with sticky protection when group or other write is allowed. Caller-owned
parents also work when Buck runs inside a user namespace.
Directory export needs read access to the kernel's UID overflow sysctl to
distinguish caller ownership from unmapped users.

On a same-filesystem btrfs input with 4,097 paths and 64 MiB of logical contents,
three-run median writable setup takes 162 ms with private reflinks and 139 ms
with a forced overlay. Chmod of 100 files takes 0.42 ms instead of 2.42 ms, and
100 partial writes take 13 ms instead of 20 ms. Read-only setup takes about
157 ms with either strategy. FIEMAP confirms shared extents for the private
files. Earlier non-reflinking tmpfs measurements cover memory copies rather
than ext4 disk I/O.

The native example digests change for the initrd, UKI, disk and three manifests.
The kernel, /usr filesystem, verity data, root hash and extension are unchanged.
Arm64 reference digests still require a native refresh. Device-node export
requires a filesystem and namespace that permit mknod; cpio retains whole-second
timestamps and cannot represent user extended attributes.

@martinpitt

martinpitt commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

I did a strategic human review, sorted out some questions with Daan. Summary: upstream buck2 rejected our patches for mtime and hardlink support, but we want to eventually build with upstream buck. We don't care much about file owners and access mode, but hardlinks/mtimes require the framework anyway, so we might just as well cover everything. AFAICS file normalization is still in place (no suid binaries), the code just moved.

At this size it needs bot support for reviewing. First round: pr-manifest-image-storage-review.md, and the referenced reproducer: repro2.py. Some findings we may just accept, e.g. discarding M4 seems reasonable to me; M9 is not that important either. I'd lift m1 to major, as the overlay whiteouts sound like an useful feature.

One thing to watch out for: The default (Fedora) x86_64 test took 24.5 minutes here, but 15 mins on most recent PR and even less on the one before. arch took about 6 minutes more, debian is about the same. Let's see how long the next push takes, it may just have been a busy time? But the review above also found some performance regressions, in particular M2.

Wrt. expected.json conflict: Feel free to break out "image: Write complete UAPI.16 sequences" into its own PR, that should be the only ones touching the digests, fairly independent, and quick to review.

@daandemeyer
daandemeyer force-pushed the manifest-image-storage branch 3 times, most recently from a5c51e5 to d2fdf39 Compare November 17, 2026 12:41
@martinpitt

Copy link
Copy Markdown
Member

round 2 bot review. I went through the majors and already rejected two, the others are at least worth a claude look. Some minors are noise, but most of them actually look like good findings, I'd at least keep m2, m5, m16.

@daandemeyer
daandemeyer force-pushed the manifest-image-storage branch from d2fdf39 to 7f26505 Compare November 19, 2026 19:14
@martinpitt

Copy link
Copy Markdown
Member

round 3 review. No blockers left, and at this point there's so much churn here that we'll never make this happy. I'd say, fix the conflict, rebase, and let's land it -- this feels like "follow-up fixes for the things that will actually bite us"?

Buck directory artifacts lose inode metadata and hardlink identity. Let's keep
UAPI.16 manifests with modes, user xattrs and hardlinks beside content blobs,
so that later commits can restore private roots from them. The listing and
the snapshot share one writer, so every [manifest] now lists user xattrs too.
A restored root is a reflinked copy where the filesystem supports reflinks.
Otherwise it's an overlay that reads the blobs as data-only lower layers.
Unprivileged overlays only accept data-only layers since Linux 6.16, so let's
raise the kernel floor to 6.16. We also make util.clone_file() keep the holes
of a sparse file when it has to copy bytes.

Signed-off-by: Daan De Meyer <daan@amutable.com>
Image layers lose package and operation metadata when Buck stores their
directory artifacts, and layer capture resets every mode to 0755 or 0644.
Let's capture snapshots in the producing action and restore them for image
commands, solvers and terminals. Images then keep the modes that packages and
operations set, and we can drop the tmpfiles attribute. git only stores the
executable bit of a file. image.ops.copy therefore gives a copied file 0755
or 0644, so that the image doesn't depend on the umask of the checkout.
Ownership is still always root, so a setgid tty binary would run with the
root group. Let's clear the set-id bits in capture to prevent that. Capture
checks every name against UAPI.16, so a layer that creates a name that isn't
UTF-8 or contains a control character now fails to build. A layer with a 0/0
character device fails too, because overlayfs reads one in a lower layer as a
whiteout.

Signed-off-by: Daan De Meyer <daan@amutable.com>
The cpio writer gives every path an inode of its own, so hardlinked files come
out as separate copies. A file named TRAILER!!! ends the archive early, and a
symlink target that isn't UTF-8 fails to pack and unpack. The reader also
splits a hardlink group of empty files into separate files. Let's pack a
hardlink group as one inode with the data on its last link, prefix a literal
TRAILER!!! name with ./, and keep symlink targets as bytes. We also truncate
mtimes from nanoseconds, so a time just below a second boundary doesn't round
up to the next second.

Signed-off-by: Daan De Meyer <daan@amutable.com>
Terminal archives and directory artifacts can lose metadata or mistake
shared contents for shared inodes. Let's write archives from snapshots and
make the [manifest] of an archive, initrd, extension, portable or disk list
what that output contains, instead of the logical image. We rename
image.directory and [directory] to image.snapshot and [snapshot], because
they store a snapshot. Running them exports a tree that keeps modes, times,
xattrs and hardlinks. Image cpios now contain fifos, sockets and device
nodes, and tar and cpio archives start with a . entry for the root. Tar
archives leave out sockets, which tar can't store, and an export checks the
digest of every blob.

Signed-off-by: Daan De Meyer <daan@amutable.com>
Box layers lose modes, hardlinks and xattrs when Buck stores them, so a
child box installs over a parent that differs from what the package manager
wrote. Let's capture box layers as snapshots and install a child box over
its restored parent snapshot. The sandbox keeps mounting one plain
directory per layer, which we write from the snapshot with only what Buck
stores, so action startup doesn't change. Buck used to drop fifos, sockets
and device nodes from a layer without a word, and writing that directory
now fails on them instead.

Signed-off-by: Daan De Meyer <daan@amutable.com>
Buildroots and their BuildRequires deltas are still overlay uppers with
whiteout and opaque markers encoded as files, while boxes and images use
snapshots. Let's capture every install as a snapshot and restore it for
plans and builds, and drop the marker translation from rootfs. Every lower
root of an install is now a restored snapshot, so the package installers
no longer need to know whether they install over lower layers.

Signed-off-by: Daan De Meyer <daan@amutable.com>
DDIs remove the package database, stripped paths and an extension's
os-release from a writable copy of the root, and write the extension-release
files there too. That needs a full private copy for every disk, and a second
pass that hashes every file again for the partition listings. Archives drop
the database from their manifest instead, with a second implementation of the
same removal. Snapshots are ordinary layers, so let's make these changes in a
layer on top of the image and let terminal drivers only read. The layer
removes paths like image.ops.remove does, so a parent directory that the
removal empties stays. The partition listings then come from the snapshot,
and the system partitions leave out what the ESP copies through repart's
ExcludeFiles=. repart gets the tree through --copy-source instead of --root,
so imported partitions no longer need to be bound into the tree. repart then
expands specifiers in a label from the build box, so a partition label with
a % now fails. The seed of an extension now hashes its extension-release
files as written, so the partition UUIDs of every extension DDI change once.

Signed-off-by: Daan De Meyer <daan@amutable.com>
rootfs.capture() makes every directory of a stored or scratch tree
writable, because Buck couldn't remove a tree through a read-only
directory. Since buck2 commit 6480183ead, Buck adds the permission itself
when it removes such a tree, so let's only escape the names that Buck can't
store, and only in the persistent build directory of a dev build. stage1 is
a box layer like any other, so let's write it from a snapshot with the same
writer as the other box layers, which escapes its names too. A deb or pacman
stage1 with a fifo then fails to build, where Buck used to drop the fifo.

Signed-off-by: Daan De Meyer <daan@amutable.com>
@daandemeyer
daandemeyer force-pushed the manifest-image-storage branch from 7f26505 to 86ca5c4 Compare November 23, 2026 09:44
Our manifests contain mTimeNSec and user extended attributes, but no root
object lists features. A manifest without features only records the default
features of UAPI.16, which don't include either field, so a reader can refuse
the manifest. Let's list every feature we write on the root object, and
refuse to read a manifest that doesn't list all of them. We also refuse an
object that lacks a field that restore() reads, instead of failing with a
KeyError on a store we didn't write.

Signed-off-by: Daan De Meyer <daan@amutable.com>
The uapi16 package is meant to read and write the format, but storage.py
also mounts overlays, restores and captures roots, and applies the image
policy of root ownership and cleared set-id bits. Every user of a snapshot
store, such as the manifest driver, links the mount code through it. Let's
keep reading and writing stores in uapi16.py and move restore, capture and
root mounting to rootfs, next to the other mount code.

Signed-off-by: Daan De Meyer <daan@amutable.com>
Capture lists a tree with its own loop over inodes, and the uapi16 tests
repeat that loop in a helper. Renumbering, the comparison of hardlink
groups in delta() and both archive packers each group objects by their
inodeToken in their own way. Let's add tree_objects() and
hardlink_groups() to uapi16.py and use them everywhere, so the tests
check the listing that capture writes.

Signed-off-by: Daan De Meyer <daan@amutable.com>
tar and cpio each have a packer for a tree and one for a snapshot. They
normalize ownership, clamp times and group hardlinks separately, and the
tar tree packer also copies xattrs of every namespace, which a snapshot
never records. Let's list a tree with tree_objects() and pack the listing
with the snapshot packer, so both kinds of input give the same archive.

Signed-off-by: Daan De Meyer <daan@amutable.com>
Image layers, package installs, package builds and terminal drivers each
restore a snapshot, bind it at /buildroot and capture it again in their
own code. The deb and pacman solvers also create an empty root by hand
when there's no lower snapshot, although restoring the empty snapshot
gives the same root. Let's add snapshot_root() to rootfs and use it in
all of them, and let the solvers always restore their lower snapshots.

Signed-off-by: Daan De Meyer <daan@amutable.com>
The system partitions of a bootable disk leave out the contents of the
directories that the ESP copies. We tell repart with ExcludeFiles=, and
the partition listings repeat the same rule on their own. Let's remove
those contents from the snapshot that repart copies and that the
listings describe, so the rule exists once.

Signed-off-by: Daan De Meyer <daan@amutable.com>
@daandemeyer
daandemeyer force-pushed the manifest-image-storage branch from 86ca5c4 to 7530fa5 Compare November 23, 2026 12:38

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants