You may not want to require all of your bind mounts (in systemd)
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:
[Install] RequiredBy=local-fs.target
As the documentation for Requires
will sort of tell you, this is a pretty strong statement. A
RequiredBy
here is equivalent to local-fs.target 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 local-fs.target,
which is equivalent to local-fs.target having an After
of them,
which means that this takes effect. If you say your mount is
RequiredBy
local-fs.target and it fails to start for some reason,
local-fs.target itself is not considered to be started and systemd
goes to its rescue environment. A RequiredBy
of local-fs.target
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.
|
|