]> pere.pagekite.me Git - homepage.git/blob - mypapers/200802-bootsequence/200802-bootsequence.html
Correct link.
[homepage.git] / mypapers / 200802-bootsequence / 200802-bootsequence.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <link rel="stylesheet" href="../mrtg-td/slides.css" type="text/css">
5 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
6 <meta name="Language" content="en">
7 <meta name="Author" content="Petter Reinholdtsen">
8 </head>
9 <body>
10
11 <a href="../200706-bootseq/200706-bootseq.html">last related talk</a>
12
13 <h1><A href="http://www.fosdem.org/2008/schedule/events/debian_boot">Reordering the Debian boot sequence for correctness and speed</a></h1>
14
15 <p>There are subtle bugs in the Debian boot and shutdown sequence.
16 They are hard to find, as they normally only affect rare combination
17 of packages, and harder to fix, as they normally require the combined
18 work of several maintainers and changes in several packages. This
19 talk is about how we can solve them, and gain a few advantages on the
20 way.</p>
21
22 <div class="presenter">Petter Reinholdtsen - one of the sysvinit maintainers
23 <br>pere@hungry.com
24 <br>FOSDEM 2008, 2008-02-26</div>
25
26 <!--
27
28 There are subtle bugs in the debian boot and shutdown sequence. They
29 are hard to find, as they normally only affect rare combination of
30 packages, and harder to fix, as they normally require the combined
31 work of several maintainers and changes in several packages.
32
33 One way to find these bugs is to document the dependencies of all
34 init.d scripts, and use this information to check that the ordering is
35 correct. When such information is available, it is also possible to
36 reorder the boot and shutdown sequence to make sure all dependencies
37 are fulfilled.
38
39 It is also possible to run scripts in parallel, to speed up the boot,
40 when the order they need to run in is known.
41
42 This talk is about how all of this can be done with Debian.
43 -->
44
45 <h2>Summary</h2>
46
47 <!--
48
49 - how do sysvinit boot work
50 - runlevels
51 - inittab
52 - rc*.d/
53 - ordering problem
54 - how does it work in debian
55 - effect on the boot
56 - insserv
57 - speed change?
58 - concurrency
59
60 - how to write lsb headers
61 - provides
62 - deps
63 - runlevel list
64
65 - status in debian
66 - need better doc
67 - fix insserv bugs
68
69 - what is needed to convert
70 - add LSB header to packages and get the change into testing
71 - update policy
72 - more users to test headers and detect errors
73 - install and activate insserv by default
74
75 -->
76
77 <h2>SysV init in Debian - Booting</h2>
78
79 <p>Note, this is the stuff going on after the initrd part is done.
80 The very early boot is done before hard drive partitions is mounted.</p>
81
82 <ol>
83
84 <li>/sbin/init start, which look at /etc/inittab and decides what to
85 do.</li>
86
87 <li>The scripts in /etc/rcS.d/ is executed in sequence by
88 /etc/init.d/rc, with <tt>start</tt> as the argument.</li>
89
90 <li>Depending on the runlevel, the scripts for the given runlevel is
91 executed (normally the ones in /etc/rc2.d/) are executed in
92 sequence, first the stop scripts with <tt>stop</tt> as their
93 argument, next the start scripts with <tt>start</tt> as their
94 argument. The rc*.d/ directories contain symlinks the files in to
95 /etc/init.d/.</li>
96
97 <li>The ordering is important.</li>
98
99 <li>The single-user runlevel will present a login prompt after rcS.d/
100 was executed. Runlevel 1 is not the single user runlevel, but it
101 behaves as a better single user.</li>
102
103 </ol>
104
105 <h2>SysV init in Debian - Switching runlevels</h2>
106
107 <ul>
108
109 <li>Call <tt>telinit X</tt> where X is the new runlevel, one of S, 0,
110 1, 2, 3, 4, 5, 6.</li>
111
112 <li>init runs in sequence all stop scripts in /etc/rcX.d/ that also
113 has a start symlink in the previous runlevel /etc/rcY.d/, with
114 <tt>stop</tt> as their argument.</li>
115
116 <li>init then run in sequence all start scripts in /etc/rcX.d/, with
117 <tt>start</tt> as their argument.</li>
118
119 </ul>
120
121 <p>Note that switching to runlevel S will not run the scripts in
122 /etc/rcS.d/. To get a similar effect after boot, switch to runlevel
123 1. It will (should) kill all services and prepare the machine for
124 maintenance.</p>
125
126 <h2>SysV init in Debian - Shutting down</h2>
127
128 <p>This is equivalent to switching to runlevel 0 (halt) or 6 (reboot),
129 with a minor exception. All scripts (both start and stop) are
130 executed with the <tt>stop</tt> argument.
131
132 <h2>The ordering problem</h2>
133
134 <p>Script ordering is vital for this to work. And how are the scripts
135 ordered? By numbers.
136
137 <p>And the numbers are picked using skills, knowledge and negotiation.
138 Getting it right is often hard.
139
140 <p>The current Debian default is wrong. Stop sequence should by
141 default be the reverse of the start sequence. It isn't.
142
143 <p>Reordering is hard and require cooperation between maintainers of
144 all packages involved. Given two packages with two scripts inserted
145 with the default settings in Debian:
146
147 <p>Package A: script_a sequence 20 (start and stop)
148 <br>Package B: script_b sequence 20 (start and stop)
149
150 <p>Along come script C, which should run before script_a and after
151 script_b. Current solution is to change packages A and C or packages
152 B and C to get something like this:
153
154 <p>Package A: script_a start seq. 22, stop seq. 18
155 <br>Package B: script_b sequence 20 (start and stop)
156 <br>Package C: script_c start seq 21, stop seq 19
157
158 <p>If other scripts depend on the old order of script_a, they will
159 have to change their sequence number too. Only way to discover this
160 is by a lot of testing, or documenting script dependencies.
161
162 <h2>A ordering solution</h2>
163
164 <p>Let each script document its dependency, and generate sequence
165 numbers using this dependency information. Example:
166
167 <p>Package A: script_a depend on nothing
168 <br>Package B: script_b depend on nothing
169 <br>Package C: script_c depend on script_b, a dependency of script_a
170
171 <p>Generated sequence:
172
173 <p>script_b start seq 1, stop seq 3
174 <br>script_c start seq 2, stop seq 2
175 <br>script_a start seq 3, stop seq 1
176
177 <p>An implementation of this system is the dependency based boot
178 sequencing, provided in the insserv package.</p>
179
180
181 <h2>LSB headers for insserv</h2>
182
183 <ul>
184 <li>"Provides" header, list the Facility/service provided by the
185 script. Do not list virtual facilities (like $time)</li>
186
187 <li>Runlevel entries (Default-Start and Default-Stop headers), list
188 what runlevels to activate for this script
189
190 <li>Dependency entries (Required-Start, Required-Stop, Should-Start,
191 Should-Stop, X-Start-Before, X-Stop-After), list the
192 facilities/services needed by this script. It will start after
193 its start dependencies and stop before its stop dependencies. The
194 X-* entreis are reverse dependencies. Required-* are hard
195 dependencies (will install even if they are missing), while
196 Should-* and X-* are soft dependencies (only taken into account if
197 scripts providing them are present).</li>
198
199 </ul>
200
201 <h2>What to list as dependencies I</h2>
202
203 <p>If your package used the default update-rc.d settings before, this
204 is the header for you:</p>
205 <pre>
206 ### BEGIN INIT INFO
207 # Provides: scriptname
208 # Required-Start: $remote_fs $syslog
209 # Required-Stop: $remote_fs $syslog
210 # Default-Start: 2 3 4 5
211 # Default-Stop: 0 1 6
212 ### END INIT INFO
213 </pre>
214
215 <p>$remote_fs is needed by all scripts using files in /usr/. $syslog
216 is needed only by scripts starting services logging to syslog.</p>
217
218
219 <h2>Status of dependency based boot</h2>
220
221 <img alt="LSB header progress graph" src="lsb-header-progress.png" width="50%" align="right">
222
223 <p>Release goal for Debian Lenny.
224
225 <p>Packages with LSB header: 654 of 866 (76%)
226 <br>Unsolved BTS reports: XXX
227 <br>Packages without BTS reports: ~150
228
229 <p>Need better documentation
230
231 <p>Need debian policy updates
232
233 <p>Fix insserv bugs
234
235 <p>
236
237 <h2>Thank you very much</h2>
238
239 <h3>Questions?</h3>
240
241 <p><a href="http://www.hungry.com/~pere/mypapers/200802-bootsequence/200802-bootsequence.html">http://www.hungry.com/~pere/mypapers/200802-bootsequence/200802-bootsequence.html</a></p>
242
243 </body>
244 </html>