systemd: lock disks while running filesystem checks - #18653
Draft
Pawel Winogrodzki (PawelWMS) wants to merge 1 commit into
Draft
systemd: lock disks while running filesystem checks#18653Pawel Winogrodzki (PawelWMS) wants to merge 1 commit into
Pawel Winogrodzki (PawelWMS) wants to merge 1 commit into
Conversation
Acquire the exclusive whole-disk lock in systemd-fsck before launching its child fsck process, and retain it until that process exits. This is a systemd-owned alternative to native e2fsprogs locking. The two implementations must not be combined because nested locks would deadlock. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bb0e6716-4886-4e95-9efe-71dcde8687d6
Pawel Winogrodzki (PawelWMS)
force-pushed
the
pawelwi/systemd-fsck-whole-disk-lock
branch
from
August 29, 2026 00:05
8f32f47 to
bc45e8f
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.
Alternative implementation
Important
This change is a systemd-owned alternative to the proposed upstream
e2fsck: take flock(LOCK_EX) on whole-disk device during filesystem checkpatch.Do not ship both implementations.
systemd-fsckretains its exclusive lock while waiting for childe2fsck; native e2fsck locking would block acquiring a second independently-opened lock on the same disk, deadlocking boot.What
systemd-fsck.fsckchecks the filesystem.systemdandsystemd-boot-signedreleases synchronized at 255-35.Why
The root filesystem check can update ext4 metadata while
systemd-udevdprobes the same disk. If udev observes the primary superblock between its payload and checksum writes, libblkid can temporarily reject the filesystem, causing udev to remove its filesystem UUID link. The generated root mount then cannot resolve the device and boot stops in the initramfs.systemd-udevdalready takes a shared whole-disk lock while probing. Holding an exclusive lock across the filesystem check makes udev defer and retry its event after filesystem metadata is consistent.How it works
All systemd-managed filesystem checks converge in
systemd-fsck, after it has resolved the exact block device and verified an fsck implementation exists. Before forking childfsck, the patch:path_get_whole_disk().LOCK_EXBSD lock.fsckwhile the parent retains the lock descriptor.The lock wait is intentionally unbounded, matching the existing
TimeoutSec=infinityfsck units. Concurrent checks for partitions on one disk serialize rather than failing after an arbitrary timeout.Why this layer
This is simpler than the generator option in #18640:
/usrunit;/usr, and instantiated checks;systemd-fsckalready ships in the initramfs;It is also simpler than the drop-in option in #18639 because it needs no shell helper,
BindsTo=reverse resolution, or custom dracut file inclusion.Compared with e2fsprogs ownership, this implementation consistently protects every filesystem checker launched through
systemd-fsck. The e2fsprogs implementation instead owns the exact lifetime of e2fsck metadata writes and also applies outside systemd-managed boot. They are mutually exclusive alternatives, not cumulative protections.Scope
This affects every filesystem check launched through
systemd-fsck, not only initrd root and/usrunits. Checks for partitions on the same physical disk now serialize on one whole-disk lock.Risk
fsck -llock may not previously have serialized them.Verification
patch --dry-run -p1without fuzz or offsets.libsharedlinkage against v255.safe_fork(), childexecvp(), andwait_for_terminate_and_check().udevadm lockbehavior.git diff --checkand repository commit/push hooks.