Why doesn't mount wait for systemd.fsck to finish running?

Whenever systemd.fsck actually has to do a repair* at boot time, automatic mounting of my partition fails because the mount command doesn't wait until [email protected] is done.

How do I ensure that mount waits until the file system check service finishes instead of failing immediately because the file system check was started?

The relevant line in fstab looks like this:

LABEL=cfdata   /data   ext4  defaults,nofail,x-systemd.device-timeout=60     0 0

(the label cfdata is on /dev/sda1)

The relevant systemd logs look like this when there's a failed mount at boot:

Jun 23 06:24:45 dev-machine-1 kernel:  sda: sda1
Jun 23 06:24:45 dev-machine-1 kernel: sd 0:0:0:0: [sda] Attached SCSI disk
Jun 23 06:24:47 dev-machine-1 systemd[1]: Starting File System Check on /dev/sda1...
Jun 23 06:24:47 dev-machine-1 mount[5563]: mount: /data: /dev/sda1 already mounted or mount point busy.
Jun 23 06:24:47 dev-machine-1 systemd-fsck[5483]: cfdata: recovering journal
Jun 23 06:24:49 dev-machine-1 systemd-fsck[5483]: cfdata: Clearing orphaned inode 13 (uid=0, gid=0, mode=0100644, size=39685)
Jun 23 06:24:49 dev-machine-1 systemd-fsck[5483]: cfdata: clean, 2767944/29310976 files, 75558004/117212630 blocks
Jun 23 06:24:49 dev-machine-1 systemd[1]: Started File System Check on /dev/sda1.
Jun 23 06:24:49 dev-machine-1 kernel: EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: (null)

When this happens, the drive gets mounted to /media/<uuid> instead of my mount point in fstab.

Note: When [email protected] has to do a repair, output in the journal will be something like: Clearing orphaned inode 13 (uid=0, gid=0, mode=0100644, size=39685). The mount problem only happens when fsck is actually doing something like this and holds up the device.


Solution 1:

Tell your system to include it in the file system check list:

The sixth field (fs_passno).

This field is used by fsck(8) to determine the order in which filesystem checks are done at boot time. The root filesystemshould be specified with a fs_passno of 1. Other filesystems should have a fs_passno of 2. Filesystems within a drive will be checked sequentially, but filesystems on different drives will be checked at the same time to utilize parallelism available in the hardware. Defaults to zero (don't fsck) if not present.

(From man fstab)

Make the line read

LABEL=cfdata   /data   ext4  defaults,nofail,x-systemd.device-timeout=60     0 2

And it should be handled automatically.