Gentoo Archives: gentoo-user

From: Rich Freeman <rich0@g.o>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] systemd mount - what on earth is it doing ...
Date: Sat, 25 Sep 2021 11:29:30
Message-Id: CAGfcS_nghiKyP_1TMZmuUk=Mmm88gLYA-fwA=4WpExqhV5dneg@mail.gmail.com
In Reply to: Re: [gentoo-user] systemd mount - what on earth is it doing ... by antlists
1 On Sat, Sep 25, 2021 at 6:49 AM antlists <antlists@××××××××××××.uk> wrote:
2 >
3 > On 24/09/2021 21:30, Canek Peláez Valdés wrote:
4 >
5 > There's a lot of info about how to write a service file, but if you need
6 > to run before or after system service files, it's nowhere near so easy
7 > to find out Before=WHAT or After=WHAT :-)
8
9 So, I have a similar challenge because I use lizardfs and it can take
10 a while to initialize, and it isn't something systemd understands out
11 of the box. (Plus it depends on a container running on the same host,
12 and those tend to run late, and other containers depend on the mount.)
13
14 I solved my issues with drop-ins and dependencies.
15
16 I did not create a mount unit for the mount. I'm using fstab and its
17 generator to manage that. However, I did use a drop-in so that the
18 automatically-created unit obtains the additional dependencies and
19 loads in the right order. This requires using the right unit name as
20 created by the generator.
21
22 I set up dependencies for the mount unit so that it would run after
23 things that it needed. I also set dependencies on services that use
24 the mount, so that they load later. This wasn't something like home,
25 so I didn't apply those dependencies to a target. However, if you
26 want to tie this into a standard target I suggest checking man
27 systemd.special or ask around.
28
29 > >
30 > > So I created a systemd mount unit for /home, which only runs after
31 > > dm-integrity. Great - I enabled it and it appeared to work!
32 > >
33 > >
34 > > You removed the /home entry from fstab, right?
35 > >
36 > mad it noauto, yes ...
37
38 That won't prevent the system from creating a unit for it - it just
39 won't be a dependency of local-fs.target.
40
41 I would suggest using only ONE of the following two approaches:1.
42 Entry in fstab plus a drop-in to modify its behavior with the same
43 name.
44 2. Custom mount unit with no entry in fstab at all (commented out is
45 fine, noauto is not).
46
47 It is possible you have more than one unit for the same mountpoint.
48 I'm not sure how exactly that behaves. I'd just run "systemctl | grep
49 mount" and see what comes up - see if you have two apparent entries
50 for home. If so one is probably from fstab and the other is probably
51 from your custom unit. Unless they have the exact same name your unit
52 won't override the system one, and I'm actually not quite sure how
53 generators interact with unit overrides. They seem to work fine with
54 drop-ins which is why I used this approach.
55
56 > > That should be home.mount. What does systemctl status home.mount says?
57 > >
58 > anthony@thewolery ~ $ systemctl status home.mount
59 > ● home.mount - Mount Home
60 > Loaded: loaded (/etc/systemd/system/home.mount; disabled; vendor
61 > preset: disabled)
62 >
63 > > So what on earth is going on, and more importantly, what am I
64 > > misunderstanding or doing wrong. I would very much like to know why
65 > > it's
66 > > working, when I think it shouldn't be!
67 > >
68 > So fstab says noauto, home.mount is disabled, and /home is mounted on
69 > boot...
70 >
71
72 Using noauto only prevents it from being a dep for local-fs.target.
73 It doesn't prevent it from being mounted for some other reason.
74
75 I'd look at:
76 systemctl list-dependencies --reverse home.mount
77
78 Another command you might find useful is systemd-analyze dot. The
79 direct output is actually readable, though intended to be converted
80 into a chart with graphviz using the hinted command it outputs.
81
82 If anything explicitly wants home.mount then it is going to get
83 mounted even if set to noauto.
84
85 Systemd is one of those things that is really capable, but you have to
86 grok a lot of concepts to make it dance for you, otherwise you'll feel
87 like you're the one being made to dance. The internet is full of
88 one-liners now that it is so popular, but these often obfuscate how it
89 actually works. It operates using a series of basic rules and once
90 you get how they're being strung together to make things work then it
91 is a lot easier to make it do what you expect. Lennart's original
92 blog posts about systemd are very useful for this - maybe there are
93 some other good resources out there these days.
94
95 --
96 Rich