Remove lost+found from named volume EXT4 images#1731
Open
sylvaincombes wants to merge 2 commits into
Open
Conversation
The EXT4 formatter creates a lost+found directory for e2fsck compatibility, but named container volumes are never checked with e2fsck. Many database images (Postgres, MySQL, Elasticsearch, Supabase, etc.) treat a non-empty volume root as an error and refuse to initialize, producing failures like: initdb: error: directory "/var/lib/postgresql/data" exists but is not empty This matches the behavior of Docker Desktop, Colima, and OrbStack, which all present fresh named volumes as empty directories. lost+found is not required for EXT4 to function; e2fsck recreates it automatically if a consistency check is ever run. Add two tests in VolumeImageTests to document and guard the behavior: one confirming the baseline (default formatter creates lost+found), and one confirming it is absent after the unlink call.
d88d4ff to
900f1da
Compare
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
Remove
lost+foundfrom freshly created named volume EXT4 images by callingformatter.unlink(path: FilePath("/lost+found"))beforeformatter.close()inVolumesService.createVolumeImage.Why
The
EXT4.Formatterincontainerizationcorrectly createslost+foundforgeneral-purpose e2fsck compatibility. Named container volumes, however, are never
checked with e2fsck — and many widely-used database images treat a non-empty
volume root as a fatal error at initialization time:
Affected images include Postgres, MySQL, Elasticsearch, MongoDB, and any image
whose entrypoint runs
initdb-style initialization against the raw volume mount point.Docker Desktop, Colima, and OrbStack all present fresh named volumes as empty
directories. This fix restores that parity and unblocks a broad class of
real-world use cases.
Safety
lost+foundis not required for EXT4 to function. If e2fsck is ever run on avolume, it recreates
lost+foundautomatically when it finds it missing. No dataloss, no corruption risk. Only newly created volumes are affected; existing
volume images are unchanged.
The fix is at the right semantic layer:
VolumesServiceis where the decisionthat "this EXT4 image is for a container named volume" belongs. The
containerizationlibrary comment ("required for e2fsck to pass") remainscorrect for its own scope.
Tests
Two new tests in
Tests/ContainerResourceTests/VolumeImageTests.swift:formatterCreatesLostAndFoundByDefault— baseline confirming the defaultformatter behaviour that this fix deliberately overrides
volumeImageHasNoLostAndFound— confirms the root directory is empty afterthe unlink, using
EXT4.EXT4Reader.listDirectoryFixes #1730