You may not want to require all of your bind mounts (in systemd)

October 15, 2021

Today, as part of my recent testing of bind mounts of ZFS filesystems, I discovered a new way to shoot my foot off with systemd. After yesterday's discoveries about fstab entries for bind mounts, I wanted to be sure that systemd wouldn't do anything peculiar with a .mount unit for a bind mount if the underlying filesystem was unavailable. So I arranged for the ZFS filesystem in question to not be mountable and rebooted my test system. On boot, it promptly stopped in single user rescue mode (asking for the root password as usual). It took me a little bit of time to work out what I'd done to myself.

My normal setup for my ZFS bind mounts includes the following standard bit at the end:


As the documentation for Requires will sort of tell you, this is a pretty strong statement. A RequiredBy here is equivalent to Requiring this bind mount, which means:

[...] If one of the other units fails to activate, and an ordering dependency After= on the failing unit is set, this unit will not be started. [...]

Mounts of all sorts generally have a Before of, which is equivalent to having an After of them, which means that this takes effect. If you say your mount is RequiredBy and it fails to start for some reason, itself is not considered to be started and systemd goes to its rescue environment. A RequiredBy of is implicitly declaring that this mount is essential for the system to boot at all.

In some situations this is what you really want, even for bind mounts. In other situations you're better off having your system boot up far enough to appear on the network so that you can log in remotely to try to fix things. In those situations what you want here is WantedBy, not that reflexive RequiredBy. I have various bind mounts on my office desktop; especially in these times, I'm probably better off making those 'WantedBy'.

(This may lead you to setting Requires= and After= on some service units that would otherwise malfunction without the bind mount. Or you can set appropriate RequiredBy and Before lists on your mount units, which may be easier to manage.)

PS: As covered in systemd.mount(5), you can get this for /etc/fstab lines with the 'nofail' mount pseudo-option.

Written on 15 October 2021.
« Systemd (v237) can do quite odd things with /etc/fstab bind mounts
My wish for a way to activate one systemd unit when another one started »

Page tools: View Source, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Fri Oct 15 23:08:07 2021
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.