Skip to content

Force filesystem sync when unpacking container image layers - #4994

Merged
agners merged 1 commit into
devfrom
containerd-diff-sync-fs
Sep 2, 2026
Merged

agners merged 1 commit into
devfrom
containerd-diff-sync-fs

Conversation

@agners

@agners agners commented Sep 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Enable the containerd diff-service sync_fs option so the daemon issues one syncfs(2) after each unpacked image layer. containerd fsyncs its metadata database when committing a snapshot, but never syncs the unpacked layer data itself β€” after an unclean shutdown shortly after an image pull this leaves layers with zero-byte files (correct names/modes/mtimes, no data) while the snapshot stays durably recorded as valid. Because committed snapshots are never re-verified or re-unpacked, the corruption even survives deleting and re-pulling the image (moby/moby#49784, containerd/containerd#8973), and with shared base layers it is only recoverable by wiping the Docker storage.

This is the failure signature behind a growing number of corruption reports, e.g. the 0-byte coredns in home-assistant/plugin-dns#207, home-assistant/supervisor#6476, home-assistant/supervisor#6835, #4913. Upstream background: containerd/containerd#8895, fixed opt-in via containerd/containerd#10284 (containerd >= 2.0). The daemon-side option applies to all clients of the daemon, including dockerd with the containerd image store (the default since HAOS 17). Installs still on the overlay2 graphdriver unpack inside dockerd and are unaffected either way.

Verification (QEMU, HAOS 18.3.dev, Docker 29.6.2 / containerd 2.2.6)

  • Stock settings, power cut <1s after docker pull of the DNS plugin image: corrupts 2/2 runs β€” one run zeroed /usr/bin/coredns entirely, the other zeroed the s6 scripts and left coredns truncated (20021248 of 25919650 bytes), matching the two damage profiles reported in plugin-dns#207.
  • Deterministic A/B with kernel background writeback suppressed (survival can then only come from the stack syncing explicitly): baseline ends with 1215 zero-byte files and exec format error; with sync_fs the image survives the identical power cut intact (152 kB dirty at the cut vs 76 MB).
  • strace on containerd: 0 syncfs calls per image load before, exactly one per layer after β€” also confirming dockerd pulls route through the daemon's diff service where this option takes effect.
  • Cost (load+unpack of the 2 GB Core image): 41.6s β†’ 42.2s on a fast disk; 226s β†’ 230s (+1.9%) on a 30 MB/s / 250 IOPS throttled disk. QEMU throttling does not model SD-card sync latency, so the slowest cards may pay somewhat more, but the cost is bounded at one syncfs per layer rather than per file.

Given HAOS commonly runs on SD cards without a UPS, trading a slightly slower pull for image data that is actually on disk when the pull completes seems like the right default.

Related: home-assistant/supervisor#6555 (Docker storage reset, the recovery path for already-corrupted installs).

πŸ€– Generated with Claude Code

Summary by CodeRabbit

  • Reliability
    • Improved data durability when applying container image layers.
    • Reduced the risk of losing unpacked image data after unexpected power loss.

containerd fsyncs its metadata database when committing a snapshot, but
never syncs the unpacked layer data itself. On an unclean shutdown
within the writeback window after an image pull this leaves layers with
zero-byte files (correct names/modes/mtimes, no data) while the
snapshot stays durably recorded as valid. Because existing snapshots
are never re-verified or re-unpacked, such corruption even survives
deleting and re-pulling the image, and with shared base layers it can
only be recovered by wiping the Docker storage entirely.

This is the failure signature behind a growing number of reports of
broken plugins/add-ons/Core after power loss (e.g. 0-byte coredns in
home-assistant/plugin-dns#207, supervisor#6476/#6835, #4913).

Enable the containerd diff-service sync_fs option (containerd >= 2.0,
containerd/containerd#10284): the daemon then issues one syncfs(2) per
applied layer, making unpacked data as durable as the metadata that
references it. It applies to all clients of the daemon, including
dockerd with the containerd image store.

Verified in QEMU on haos 18.3.dev (Docker 29.6.2, containerd 2.2.6):

* With completely stock settings, a power cut <1s after `docker pull`
  of the DNS plugin image corrupts the image 2 out of 2 runs: one run
  zeroed /usr/bin/coredns entirely, the other zeroed the s6 scripts
  and left coredns truncated (20021248 of 25919650 bytes) - matching
  the two damage profiles reported in plugin-dns#207.
* Deterministic A/B with kernel background writeback suppressed, so
  survival can only come from the stack syncing explicitly: without
  this option 1215 zero-byte files including a 0-byte coredns failing
  with "exec format error"; with sync_fs the image survives intact
  (152 kB dirty at the power cut vs 76 MB).
* strace on containerd confirms 0 syncfs calls per image load before,
  one per layer after - which also confirms dockerd pulls route
  through the containerd daemon's diff service where this option
  takes effect.
* Cost of loading+unpacking the 2 GB Core image: 41.6s -> 42.2s on a
  fast disk, 226s -> 230s (+1.9%) on a 30 MB/s / 250 IOPS throttled
  disk. Note QEMU throttling does not model SD-card sync latency, so
  the real-world cost on the slowest cards may be somewhat higher, but
  it stays bounded at one syncfs per layer.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. πŸŽ‰

ℹ️ Recent review info
βš™οΈ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: cbdd6c75-5a48-4992-abe2-e9e0f9c3c292

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 832af7e and 18caba8.

πŸ“’ Files selected for processing (1)
  • buildroot-external/rootfs-overlay/etc/containerd/config.toml

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


πŸ“ Walkthrough

Walkthrough

The containerd diff service now enables sync_fs, which calls syncfs(2) after each applied image layer. This makes unpacked layer data durable with its metadata.

Changes

Containerd durability

Layer / File(s) Summary
Synchronize applied image layers
buildroot-external/rootfs-overlay/etc/containerd/config.toml
The diff service configuration sets sync_fs = true after image layer application.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: βšͺ Minimal Β· up to 18cab

This localized configuration change enables filesystem synchronization for unpacked image layers, with no actionable merge-blocking risk remaining after normal checks and review.

Poem

A rabbit checks each layer’s ride
syncfs(2) keeps bits beside
The metadata rests secure
Through power loss, the data stays sure
Containerd hops with durable pride

πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The title clearly and concisely describes the main change: enabling filesystem synchronization during container image layer unpacking.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check βœ… Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check βœ… Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch containerd-diff-sync-fs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands.

@agners
agners requested a balanced review from Copilot September 1, 2026 10:52
@agners agners added the run-dev-build Execute development build on a PR label Sep 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables durable container image layer unpacking to reduce corruption after abrupt power loss.

Changes:

  • Enables containerd diff-service sync_fs.
  • Documents the corruption scenario and durability rationale.

πŸ’‘ Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@agners

agners commented Sep 2, 2026

Copy link
Copy Markdown
Member Author

docker load times (image tar on the data partition, per-cycle wiped store)

Small image β€” DNS plugin, 5 layers, ~65 MB (isolates fixed per-layer sync cost):

  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚    Platform     β”‚   baseline    β”‚    sync_fs    β”‚     delta     β”‚
  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
  β”‚ RPi4 (SD)       β”‚ 5.29 / 5.26 s β”‚ 7.83 / 8.55 s β”‚ +2.9 s (+55%) β”‚
  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
  β”‚ RPi3 (SD)       β”‚ 11.30 s       β”‚ 15.06 s       β”‚ +3.8 s (+33%) β”‚
  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
  β”‚ OVA (fast disk) β”‚ 1.04 / 0.95 s β”‚ 1.26 / 1.14 s β”‚ +0.2 s (+20%) β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Big image β€” Core, ~10 layers, ~2 GB (throughput-dominated):

  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚    Platform     β”‚           baseline           β”‚           sync_fs            β”‚            delta             β”‚
  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
  β”‚ RPi4 (SD)       β”‚ 196.0 / 209.4 s (mean 202.7) β”‚ 208.0 / 232.8 s (mean 220.4) β”‚ +17.7 s (+8.7%)              β”‚
  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
  β”‚ RPi3 (SD)       β”‚ 417.9 s                      β”‚ 423.6 s                      β”‚ +5.6 s (+1.3%)               β”‚
  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
  β”‚ OVA (fast disk) β”‚ 30.1 / 30.6 s                β”‚ 31.7 / 37.0 s                β”‚ +4.0 s (+13%, high variance) β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

The measurements appear to have quite some variance. While I've stopped all containers and removed the complete storage, page cache or other circumstances might have played a role.

It is interesting that DNS has this higher increase. It could be just due to its small size. or it could be related to CoreDNS binary which is rather large and in the second to last layer (and rather often corrupts in real world).

In general, the cost appears acceptable to me.

@sairon sairon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tests, it doesn't look that bad, and if it helps with the corruptions we're seeing, the minor performance hit is acceptable for me - still better than nuking the whole Docker storage, which is the only other option we have.

@agners
agners merged commit 4b71253 into dev Sep 2, 2026
39 of 40 checks passed
@agners
agners deleted the containerd-diff-sync-fs branch September 2, 2026 15:17
@sairon sairon added the os label Sep 3, 2026
@sairon sairon mentioned this pull request Sep 9, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed os run-dev-build Execute development build on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants