Skip to content

Remove lost+found from named volume EXT4 images#1731

Open
sylvaincombes wants to merge 2 commits into
apple:mainfrom
sylvaincombes:fix/remove-lost-found-from-named-volumes
Open

Remove lost+found from named volume EXT4 images#1731
sylvaincombes wants to merge 2 commits into
apple:mainfrom
sylvaincombes:fix/remove-lost-found-from-named-volumes

Conversation

@sylvaincombes

Copy link
Copy Markdown

What

Remove lost+found from freshly created named volume EXT4 images by calling
formatter.unlink(path: FilePath("/lost+found")) before formatter.close() in
VolumesService.createVolumeImage.

Why

The EXT4.Formatter in containerization correctly creates lost+found for
general-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:

initdb: error: directory "/var/lib/postgresql/data" exists but is not empty
initdb: detail: It contains a lost+found directory, perhaps due to it being a mount point.

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+found is not required for EXT4 to function. If e2fsck is ever run on a
volume, it recreates lost+found automatically when it finds it missing. No data
loss, no corruption risk. Only newly created volumes are affected; existing
volume images are unchanged.

The fix is at the right semantic layer: VolumesService is where the decision
that "this EXT4 image is for a container named volume" belongs. The
containerization library comment ("required for e2fsck to pass") remains
correct for its own scope.

Tests

Two new tests in Tests/ContainerResourceTests/VolumeImageTests.swift:

  • formatterCreatesLostAndFoundByDefault — baseline confirming the default
    formatter behaviour that this fix deliberately overrides
  • volumeImageHasNoLostAndFound — confirms the root directory is empty after
    the unlink, using EXT4.EXT4Reader.listDirectory

Fixes #1730

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.
@sylvaincombes sylvaincombes force-pushed the fix/remove-lost-found-from-named-volumes branch from d88d4ff to 900f1da Compare June 15, 2026 01:04
@jglogan jglogan self-requested a review June 15, 2026 16:44
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.

[Bug]: Named volumes contain lost+found, breaking database image initialization (Postgres, MySQL, etc.)

2 participants