fix(mkfs): lay out the devbox rootfs for cheap offline grows - #19
Merged
Conversation
The rootfs image is baked at one size and grown to the devbox's disk size by an offline resize2fs before first mount, on a layered block format where every block the grow writes becomes a new block. Drop sparse_super2. Its second backup superblock lives in the last block group; growing the filesystem relocates that backup and frees one block too many, leaving the group descriptor pointing at a block bitmap the allocator believes is free. The next workload to allocate that far writes user data over the bitmap. Use meta_bg instead of resize_inode. resize_inode reserves a contiguous GDT area that resize2fs rewrites in full on every grow, so a 64GiB image grown to 128GiB writes 1216 blocks; meta_bg reserves nothing and writes 89. Promote gdt_csum to metadata_csum. Both mark appended block groups uninitialized, so the grow never zeroes an inode table, but metadata_csum also checksums every metadata structure -- the only damage signal available on a filesystem carrying no journal. Its checksums seed from s_uuid, so the seed is re-derived once the real UUID is installed. Set 16 block groups per flex group. At the previous value of 1 each group kept its bitmaps and inode table at a fixed offset inside itself, which is what put them in the blast radius of the sparse_super2 relocation. Guard the resize inode creation behind its feature, matching mke2fs. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ext2fs_initialize leaves s_checksum_type at zero, which ext2fs_open rejects as an unknown checksum, so the image failed to reopen after mkfs. mke2fs sets the field explicitly once the feature is on; do the same. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Reworks the Photon
do_mkfspatch that formats the devbox rootfs base layer.Measured on a filesystem built by
do_mkfs's own call sequence, grown 64→128GiB with the statically-linked resize2fs the guest execs:e2fsck -fnBlock bitmap differences: +16745481Four changes:
sparse_super2. Its second backup superblock lives in the last block group. Growing the filesystem relocates that backup and frees one block too many, leaving the group descriptor pointing at a block bitmap the allocator believes is free — the next workload to allocate that far writes user data over the bitmap.meta_bginstead ofresize_inode.resize_inode's reserved GDT area gets rewritten in full on every grow, which is essentially the entire delta today.meta_bgreserves nothing.gdt_csum→metadata_csum. Measured identical grow cost (both keep appended inode tables uninitialized), and adds checksums on every metadata structure — the only damage signal on a filesystem with no journal and no fsck.flex_bga no-op — which is what put the bitmaps in the blast radius of thesparse_super2relocation).Plus two things
ext2fs_initializedoes not do for us andmke2fsdoes: sets_checksum_type, and guardext2fs_create_resize_inodebehind its feature.The baked size stays 64GiB — existing customer builds may depend on it.
Why it matters
The
sparse_super2bug is not theoretical. It fires on every grow — 64→65GiB corrupts as reliably as 64→256GiB — and the block numbers it produces match those seen in production byte for byte.Existing images already carry
sparse_super2permanently; this only fixes newly built ones.Verification
sparse_super2on/off ×flex_bg/has_journal/metadata_csum/64bit/resize_inode: clean separation,sparse_super2is the only variable that corruptsdo_mkfs's own call sequence against libext2fs: 7 target sizes to 1TiB and 4 sequential grows on one filesystem, all clean; plus, via equivalentmke2fsgeometry, 52 target sizes to 2TiB, 8 baked sizes each doubled, and a populated image grown then filled past the old end-of-filesystemv0.6.17and is idempotent under thePATCH_COMMANDreverse-checkdata-accelerator/e2fsprogs(1.47.0)The missing
s_checksum_typewas caught by the E2E job on the first push —ext2fs_openrejected the image withEXT2_ET_UNKNOWN_CSUM. That gap existed becausemke2fssets the field itself, so validating againstmke2fs-built images could not surface it; thedo_mkfsreplication above now covers it and reproduces the exact error code.Not covered
Everything above is offline
resize2fsand libext2fs. Mounted kernel behaviour on the new format has not been exercised — worth a read/write/fill pass on a real devbox before this reaches customer builds.🤖 Generated with Claude Code