#43695·systemd

systemd-fsck can race with udev probing during journal replay

Author: PawelWMSCreated Sep 8, 2026Updated Sep 29, 2026
Labelsneeds-reporter-feedback ❓fsck

systemd version the issue has been seen with

Reproduced with systemd 255 but I also found no whole-device lock in systemd-fsck in v261.2 or current main (3b2900f0508b4875a53e412bd02fd12b80eaf215).

Used distribution

Azure Linux 3.0

Linux kernel version used

6.6.143.1

CPU architectures issue was seen on

x86_64

Component

systemd-fsck, systemd-udevd

Expected behaviour you didn't see

udev should not probe a block device while a filesystem checker is updating filesystem metadata.

Unexpected behaviour you saw

During journal replay in the initrd, systemd-fsck updated filesystem metadata while udev concurrently probed the same disk. We have seen filesystem identification temporarily disappear, causing udev to remove the /dev/disk/by-uuid/<root-uuid> link and transition its corresponding dev-disk-by\x2duuid-<escaped-root-uuid>.device unit from plugged to dead. The physical partition device and its PARTUUID aliases remained present.

That UUID-backed device unit was part of the generated root transaction. Its loss stopped or cancelled systemd-fsck-root.service, sysroot.mount, initrd-root-fs.target, and initrd-parse-etc.service. The UUID link and device unit returned shortly afterward, but the cancelled start jobs were not recreated. /sysroot therefore remained unmounted and the boot stayed in the initrd.

Steps to reproduce the problem

The repro requires an ext4 journal replay by e2fsck on the root partition to overlap a synthetic block-subsystem change uevent for that same partition. When e2fsck closes a writable descriptor for the block device, the kernel reports the close through the inotify event IN_CLOSE_WRITE. systemd-udevd watches block-device nodes for that event and responds by triggering SD_DEVICE_CHANGE; the resulting uevent is exposed to udev rules as ACTION=change. This path is implemented by the IN_CLOSE_WRITE handler and the SD_DEVICE_CHANGE trigger. The race is timing dependent. In the observed sequence:

  1. systemd-fsck starts fsck, and e2fsck reports that it is recovering the ext4 journal on the root partition.
  2. During the check, e2fsck closes a writable descriptor for the root partition, producing IN_CLOSE_WRITE on that device node.
  3. systemd-udevd receives IN_CLOSE_WRITE and synthesizes an SD_DEVICE_CHANGE uevent for the root partition. In the captured event environment this is ACTION=change, DEVNAME=/dev/<root-partition>, and DEVTYPE=partition; systemd-udevd starts processing it before the fsck.ext4 process exits.
  4. The persistent-storage rules run blkid against the partition while journal replay is still completing.
  5. For that specific synthetic ACTION=change processing pass, blkid returns no ID_FS_UUID. Comparing those new properties with the existing device database, udev concludes that the old filesystem UUID link no longer belongs to the partition and removes /dev/disk/by-uuid/<root-uuid>.
  6. The corresponding UUID-backed device unit changes from plugged to dead, cancelling the generated root mount transaction.

Additional program output to the terminal or log subsystem illustrating the issue

Sanitized excerpt from one reproduced boot. The udev change starts while fsck.ext4 is still running, the UUID link is removed, and the root mount then fails:

[    2.036215] systemd-fsck[431]: /dev/<root-partition>: recovering journal
[    2.788153] systemd-udevd[380]: <root-partition>: processing device (ACTION=change)
[    2.801198] systemd-udevd[380]: <root-partition>: Removing/updating old device symlink '/dev/disk/by-uuid/<root-uuid>', which is no longer belonging to this device.
[    2.801732] systemd-udevd[380]: <root-partition>: No reference left for '/dev/disk/by-uuid/<root-uuid>', removing
[    2.805147] fsck.ext4[431]: sched_process_exit
[    2.833393] mount[435]: mount: /sysroot: fsconfig system call failed: /dev/disk/by-uuid/<root-uuid>: Can't lookup blockdev.

A separate reproduced boot captured the udev change environment without ID_FS_UUID; its DEVLINKS retained the partition UUID and label but not the filesystem UUID. The root mount failed against the missing UUID link:

ACTION=change
DEVNAME=/dev/<root-partition>
DEVTYPE=partition
DEVLINKS=/dev/disk/by-partuuid/<root-partuuid> /dev/disk/by-partlabel/rootfs ...
[    5.762142] mount[456]: mount: /sysroot: fsconfig system call failed: /dev/disk/by-uuid/<root-uuid>: Can't lookup blockdev.

Another debug reproduction recorded the resulting unit transition and cancellation cascade. The UUID-backed device unit returned, but the cancelled root transaction did not:

[    5.929688] dev-disk-by\x2duuid-<escaped-root-uuid>.device: Changed plugged -> dead
initrd-parse-etc.service: Job initrd-parse-etc.service/start finished, result=canceled
initrd-root-fs.target: Job initrd-root-fs.target/start finished, result=canceled
systemd-fsck-root.service: Job systemd-fsck-root.service/start finished, result=canceled
sysroot.mount: Job sysroot.mount/start finished, result=canceled
[    6.086570] dev-disk-by\x2duuid-<escaped-root-uuid>.device: Changed dead -> plugged

Historical context

  1. fsck -l originally locked the whole device. udev skipped events for locked devices, which could leave device links stale: freedesktop.org #79576.
  2. util-linux changed fsck -l to lock /run/fsck/<disk>.lock, limiting synchronization to fsck instances: util-linux 3bbdae633f4a.
  3. systemd later changed udev to requeue events when another process holds the whole-device lock: systemd 5d354e525a5.
  4. The current block-device locking protocol recommends LOCK_EX for tools such as fsck, while udev takes LOCK_SH|LOCK_NB.
  5. A whole-device lock in e2fsck is currently under review in the e2fsprogs thread. There's an ask in ddstreet's summary whether locking shouldn't belong in fsck or systemd-fsck instead.

Change proposal in systemd-fsck

Draft implementation: https://github.com/systemd/systemd/pull/43696

The draft PR uses systemd's existing whole-disk lock helper, takes a blocking exclusive lock before starting a repair-capable checker, and releases it after the child exits.

Applying the protocol at that layer covers all filesystem-specific checkers invoked through the fsck dispatcher and keeps the systemd/udev coordination in one place. I have validated this proposal locally, but do not want to preempt the ongoing e2fsprogs work or assume that this is the preferred ownership model.

Guidance requested:

  • What is your opinion about systemd-fsck owning this lock centrally?
  • Should lock acquisition use the fsck units' infinite timeout or a separate bounded timeout?