Skip to content

mkcomposefs: building from a directory silently loses hardlinks #444

Open

Description

@mike-sul

When building from a directory (mkcomposefs <dir> <out>), hardlinked files are emitted as independent inodes. It leads to two consequences:

  1. the image's fs-verity digest differs from what any hardlink-aware builder produces for the same tree (image identity depends on the toolchain);

  2. the mounted image misreports the mount dir/tree size (and nlink=1, distinct inodes).

This issue is reproducible on v1.0.8 and current main (on 07/28/2026).

The steps to reproduce it:

$ mkdir tree && dd if=/dev/zero of=tree/big bs=1M count=100 && ln tree/big tree/big-link
$ du -sh --apparent-size tree
100M	tree

$ mkcomposefs --digest-store=objects --min-version=1 --max-version=1 tree tree.cfs

$ composefs-info dump tree.cfs
/ 4096 40755 2 ...
/big 104857600 100644 1 ... 62/37f0e7... - 6237f0e7...
/big-link 104857600 100644 1 ... 62/37f0e7... - 6237f0e7...

$ fsverity digest tree.cfs
sha256:88d2ef4f83caccd657e6e6844144ffa67dc155a8fe3476e4b8859d5d05643f7c tree.cfs

$ mkdir mnt && mount -t composefs -o basedir=objects tree.cfs mnt

$ du -sh --apparent-size mnt/
200M	mnt/

The hardlink is gone: two full entries, nlink=1 each.

composefs-rs's cfsctl, reading the same directory into the same V1 format, disagrees:

$ cfsctl --no-repo --hash sha256 --erofs-version 1 compute-id --no-propagate-usr-to-root tree
18c06b7c0b8cc959d23f2e2a7e1fccb2f402f6cc6052e936be4ee41686127015

(The flags only remove unrelated differences: cfsctl otherwise defaults to SHA-512 and propagates "/usr" metadata to the root inode.)

Control: replace the ln with cp and both tools emit the identical digest, the writers agree byte-for-byte at baseline, so the hardlink is the only issue here. This breaks any digest-based cross-check between images built from a directory and by hardlink-aware tools like composefs-rs, or mkcomposefs --from-file).

Activity

  1. cgwalters commented on Jul 28, 2026

    @cgwalters
    Contributor

    Yes, this is a bug conceptually, but I don't think we can change the default because someone might be relying on it. In the composefs-rs reimplementation of this, it's opt-in via --hardlinks and I think we need to do the same thing here.

  2. mike-sul commented on Jul 29, 2026

    @mike-sul
    Author

    Yes, it makes sense: keeping the default and fixing via the --hardlinks.

    I'll check that the image built with --hardlinks now matches the cfsctl compute-id digest and report back.

  3. mike-sul commented on Jul 30, 2026

    @mike-sul
    Author

    I've checked fsverity digest of the cfs image generated with mkcomposefs --hardlinks (the fix in #446) and it matches the one produced by cfsctl --no-repo --hash sha256 --erofs-version 1 compute-id --no-propagate-usr-to-root.

  4. cgwalters commented on Aug 3, 2026

    @cgwalters
    Contributor

    --no-propagate-usr-to-root

    But how are you dealing with the problem of missing / metadata?

  5. mike-sul commented on Aug 4, 2026

    @mike-sul
    Author

    --no-propagate-usr-to-root

    But how are you dealing with the problem of missing / metadata?

    The / metadata isn't missing in this case, mkcomposefs <dir> <out> applies the dir's own metadata to /, and cfsctl compute-id --no-propagate-usr-to-root does the same.

    For classical OCI container images with tar layers, I generate a composefs-dump file following the canonical construction (/usr metadata applied to /) and call mkcomposefs --from-file, the resulting fsverity digest is identical to what cfsctl oci compute-id produces.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions