Gentoo Archives: gentoo-dev

From: Duncan <1i5t5.duncan@×××.net>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] Re: rfc: Does OpenRC really need mount-ro
Date: Thu, 18 Feb 2016 08:57:33
Message-Id: pan$f2376$6aaefcd$77e268fe$a787c401@cox.net
In Reply to: Re: [gentoo-dev] Re: rfc: Does OpenRC really need mount-ro by Rich Freeman
1 Rich Freeman posted on Wed, 17 Feb 2016 08:46:34 -0500 as excerpted:
2
3 > On Tue, Feb 16, 2016 at 9:20 PM, Duncan <1i5t5.duncan@×××.net> wrote:
4 >>
5 >> Initial shutdown is via two targets (as opposed to specific services),
6 >
7 > Since not everybody in this thread may be familiar with systemd, I'll
8 > just add a quick definition.
9
10 Thanks for this followup. =:^)
11
12 > When systemd says "target" - think "virtual service." The equivalent in
13 > openrc would be an init.d script that has dependencies but which doesn't
14 > actually launch any processes.
15 >
16 > Targets also take the place of runlevels in systemd.
17
18 The systemd official comparison of targets is to runlevels, except much
19 more flexible as it's actually possible for multiple targets to be in the
20 process of being reached at once, not services or "virtual services", and
21 indeed, my immediate internal reaction at seeing the "virtual services"
22 definition was "no, they're like runlevels", before I even reached the
23 next paragraph, where you add that.
24
25 Basically, I'd put the runlevel comparison first and primary, as systemd
26 documentation does, tho now that I've seen the usage, "virtual services"
27 /does/ add some richness to the definition, helping to accent the fact
28 that multiple targets can be processed at once. So it's a difference in
29 emphasis, while agreeing in general.
30
31 > Just as with runlevels in openrc they are used to synchronize milestones
32 > during bootup, but the design is much more generic. Presumably openrc
33 > hard-codes runlevels like sysinit, boot, and default. In systemd I
34 > believe it just looks at the config file and directly launches the
35 > desired target, and then the dependency chain for that pulls in all the
36 > targets that precede it. Targets can depend on other targets, and
37 > services can depend on previous targets.
38 >
39 > The other dimension is that unit files describe what target they are
40 > typically associated with if it isn't the default. So, you don't run
41 > into the sorts of situations you have with openrc that if you want to
42 > enable mdraid support you need to remember to add it to the boot
43 > runlevel. That might be a relatively-easy thing to add support for in
44 > openrc actually.
45 >
46 > Hopefully that makes Dunan's summary easier to read for anybody who
47 > doesn't speak systemdese.
48
49 Again, thanks. =:^)
50
51 > Another bit of background that might be helpful is that systemd also
52 > manages mounts directly.
53
54 After actually looking into how systemd processes mounts as I wrote the
55 earlier post, I believe it's safe to say this is a much bigger difference
56 than it might seem on the surface, and it was certainly one of the
57 biggest challenges I faced in attempting to explain systemd's mount
58 processing in sysvinit/openrc terms.
59
60 Even with a reasonable level of personal admin-level systemd familiarity,
61 I kept expecting and looking for systemd to hand off the unmounting to a
62 service, which I expected would simply call one of the separate from
63 systemd itself executables (for example journald, networkd, etc, I was
64 expecting a mount helper or mountd as well), only after seeing the
65 shutdown flowchart and looking into each individual component, I still
66 couldn't find it, which is why I ultimately had to go diving directly
67 into the systemd sources themselves, which is when I found what I was
68 looking for! =:^)
69
70 But in hindsight, while there are various non-systemd-binary executables
71 that ship with systemd, systemd itself directly processes all unit files,
72 including mount units, so I should have known that it'd handle umounting
73 directly. But I simply didn't make that connection, until it became
74 obvious after the fact, and indeed, it didn't actually solidify in my
75 mind until just now as I wrote about it, tho certainly, after writing the
76 earlier post, all the pieces were there to be assembled, and this simply
77 triggered it. =:^)
78
79 > It parses fstab and creates a network of mount
80 > units with appropriate dependencies. Whether you unmount /var/tmp using
81 > "umount /var/tmp" or "systemctl stop var-tmp.mount" systemd updates the
82 > status of the var-tmp.mount unit to a stopped status. I believe if you
83 > add a noauto line to fstab it will create a mount unit automatically and
84 > not start it, and if you made it mount on boot I think it would actually
85 > be mounted as soon as you save the file in your editor (systemd can
86 > monitor config files for changes - all of this is governed by
87 > scripts/software called generators).
88
89 I'm not sure of the last -- systemd does let you mount and umount at will
90 [1], and there are enough cases where an admin might setup the fstab
91 entry before he's actually prepared for the mount to go ahead, that I
92 don't believe it would be wise for systemd to try to jump the gun.
93
94 OTOH, it's possible to setup corresponding *.automount units as well,
95 with the purpose there being to trigger mounting (using the kernel's
96 automount services, which of course would have to be enabled -- they
97 aren't here) as soon as something tries to stat/open a path under that
98 mount point. If you setup both the fstab (triggering mount unit
99 generation) and automount units, and then referenced something under it,
100 /then/ systemd would do the automount. =:^)
101
102 Of course, if someone's sufficiently interested in the outcome, it should
103 be relatively easy to test, at least for those /running/ systemd. I
104 don't personally happen to be /that/ interested in the outcome, however,
105 so...
106
107 > So, systemd in general tries to stay aware of the state of mounts. I
108 > suspect that isn't just firing off a script to find/unmount anything
109 > that is mounted. From Dunan's email it sounds like you could create a
110 > mount unit and explicitly not set a conflict with the unmount target
111 > which would cause the filesystem to remain mounted at shutdown. I have
112 > no idea what that would do to unmounting the root.
113
114 You'd have to deliberately jump thru at least two hoops in ordered to
115 fail to have that Conflicts=umount.target applied, however, and thus it's
116 extremely unlikely that it'd happen by accident.
117
118 1) You'd have to manually create the mount unit and place it in the
119 appropriate override location, instead of using fstab and letting systemd-
120 fstab-generator create the mount unit dynamically at runtime, because the
121 generator-created versions will all be using default dependencies
122 (DefaultDependencies=yes being the default), which will add the
123 conflicts /implicitly/ as part of those default deps (see the quote from
124 the systemd.special (7) manpage in my previous post).
125
126 Note that while the conflicts line is not to be found in the dynamically
127 runtime created from fstab mount units and thus isn't explicit, the fact
128 that DefaultDependencies=no isn't explicitly set either, means those
129 default dependencies apply, and they /implicitly/ include the
130 conflicts=line.
131
132 So it's not explicit, but is never-the-less implicitly there and applies
133 to any mount units dynamically generated from fstab.
134
135 Thus, to avoid it, you'd have to manually create the mount units and use
136 them in place of fstab entries, and that's explicitly discouraged in the
137 documentation -- use of fstab is recommended.
138
139 (No, I'm not supplying an explicit documentation reference for this as
140 I'd have to look it up, but I do remember reading it while I was
141 researching my switch to systemd, and pausing to explicitly make mental
142 note of it, since it seemed such a contrast to the usual systemd pattern
143 of uprooting the traditional tools and config methods in favor of its
144 own, that would seem to be one of the big reasons so many people have
145 such a strongly negative reaction to systemd. Here, it was actually
146 doing the opposite, encouraging people to continue to use the traditional
147 fstab config, and discouraging use of the systemd-native config method,
148 mount unit files.)
149
150 2) In your manually created mount unit, you'd have to explicitly set
151 DefaultDependencies=no, because otherwise, it too would be subject to the
152 implicit Conflicts=umount.target
153
154 Of course, jumping thru both those hoops is effectively impossible to do
155 accidentally -- even if you decided without reading the documentation and
156 noting that fstab usage was still encouraged, or read it and just decided
157 to do native mount units anyway, the fact that none of the normal mount
158 units you'd likely be using as examples in creation of your own, don't
159 have an explicit DefaultDependiencies= line, means you'd have to learn
160 about it from the documentation, in ordered to even know it was there to
161 set to no. And then you'd be doing it deliberately.
162
163 And if you did it deliberately for root... or for any other non-virtual
164 filesystem, you would of course get to keep the pieces. =:^)
165
166 ---
167 [1] Mount/umount at will: In normal operating mode, anyway. It doesn't
168 always work that way early in the initr* or in other cases where systemd
169 is in control but udev hasn't yet been run, tho I suspect the problem is
170 limited to multi-device btrfs and any other multi-device filesystems that
171 may be around, generally because the target triggering udev hasn't been
172 run yet. The reason is that the device units that a particular mount
173 requires haven't been initiated yet, then.
174
175 The *extremely* puzzling to systemd newbies result being that attempting
176 to mount a filesystem manually can exit success, but you go to actually
177 use the mount and you'll find it not mounted, and it won't be listed in
178 /proc/mounts or the like either. What actually happens is that the mount
179 executable does indeed make the correct kernel calls to do the mount, and
180 the kernel does indeed do the mount, but systemd immediately umounts
181 again, because the prerequisite device units haven't been initialized. I
182 suspect systemd automatically initializes the device fed in either on the
183 mount commandline or from fstab, but isn't yet prepared to directly
184 handle multi-device filesystems yet, and thus doesn't automatically
185 activate the additional device units that it views as required by the
186 filesystem, so even tho the kernel knows about them (due to a manual run
187 of btrfs device scan) and can do the mount, systemd doesn't, and believes
188 the mount-unit requirements aren't met and thus does the immediate umount.
189
190 I actually saw one mention of this on the btrfs list before I had a clue
191 what was going on, I believe without anyone explaining the situation at
192 the time, and later had it happen to me. Only quite some time after
193 having experienced it myself, did I realize why systemd was immediately
194 umounting it -- because it hadn't seen the prerequisite devices yet. And
195 only now as I write this footnote, am I making the multi-device
196 connection, which would explain why the problem isn't more widely seen
197 among those using both systemd and btrfs, or on most other filesystems,
198 since I now very strongly suspect a multi-device filesystem is a
199 prerequisite to seeing the problem, as well.
200
201 --
202 Duncan - List replies preferred. No HTML msgs.
203 "Every nonfree program has a lord, a master --
204 and if you use the program, he is your master." Richard Stallman

Replies

Subject Author
Re: [gentoo-dev] Re: rfc: Does OpenRC really need mount-ro Rich Freeman <rich0@g.o>