[systemd-devel] mounts with "nofail" can be unmounted on shutdown before "After=*-fs.target" units

MichaIng micha at dietpi.com
Sat Jun 29 17:26:03 UTC 2024


Hey guys, I have question regarding a certain behaviour of the systemd 
mount generator.

Mounts do not have `Before=*-fs.target` if the `nofail` mount option is 
added to their `/etc/fstab` entry.

 From the man page I see that this is intended behaviour:
- 
https://www.freedesktop.org/software/systemd/man/latest/systemd.mount.html#Default%20Dependencies
- 
https://www.freedesktop.org/software/systemd/man/latest/systemd.mount.html#noauto

First of all, I see the reason why it seems to be not important for 
mounts to start before certain targets, if one explicitly declares that 
it is okay for them to fail. But I do not see a downside of adding 
`Before=*-fs.target` either. There are use cases where one still wants 
other services to wait for at least the attempt to have all network 
shares mounted, even when not wanting some of them to cause failure in 
the boot sequence.

The more problematic implication however is indeed, that those mounts 
can be attempted to be unmounted on shutdown, before services with 
`After=*-fs.target` are stopped. This can lead to hanging services and 
potential data loss. It has been observed with qBittorrent and a CIFS 
network share in particular, where the CIFS mount was tried to be 
unmounted first, failed, since it was accessed by qBittorrent, and for 
some reason was hanging the shutdown sequence, so that the system needed 
to be power cycled. Doing the unmount manually before shutdown, solves 
the issue. This was when I found the missing `Before=remote-fs.target` 
entry.

Is there a particular reason `nofail` mounts do not have 
`Before=*-fs.target` defined, respectively is there any downside when 
defining it as well with `nofail`? One thing I have in mind, is that 
hanging mount attempts delay `remote-fs.target` and hence 
`getty at .service` units, i.e. the local login prompt. However, if I want 
to avoid this, because I am expecting the share to be offline regularly, 
then I would would use `noauto`, in case with `x-systemd.automount`. But 
I did not expect the `nofail` option to be a "mount at any later time on 
boot" + "unmount at any earlier time on shutdown".

Best regards,

Micha


More information about the systemd-devel mailing list