]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/bootup.xml
man: fix link markup
[thirdparty/systemd.git] / man / bootup.xml
CommitLineData
013d8a39 1<?xml version='1.0'?> <!--*-nxml-*-->
3a54a157 2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
12b42c76 3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
0307f791 4<!-- SPDX-License-Identifier: LGPL-2.1+ -->
013d8a39
LP
5
6<refentry id="bootup">
7
798d3a52
ZJS
8 <refentryinfo>
9 <title>bootup</title>
10 <productname>systemd</productname>
798d3a52
ZJS
11 </refentryinfo>
12
13 <refmeta>
14 <refentrytitle>bootup</refentrytitle>
15 <manvolnum>7</manvolnum>
16 </refmeta>
17
18 <refnamediv>
19 <refname>bootup</refname>
20 <refpurpose>System bootup process</refpurpose>
21 </refnamediv>
22
23 <refsect1>
24 <title>Description</title>
25
543e6bd4
ZJS
26 <para>A number of different components are involved in the boot of a Linux system. Immediately after
27 power-up, the system firmware will do minimal hardware initialization, and hand control over to a boot
28 loader (e.g.
29 <citerefentry><refentrytitle>systemd-boot</refentrytitle><manvolnum>7</manvolnum></citerefentry> or
30 <ulink url="https://www.gnu.org/software/grub/">GRUB</ulink>) stored on a persistent storage device. This
31 boot loader will then invoke an OS kernel from disk (or the network). On systems using EFI or other types
32 of firmware, this firmware may also load the kernel directly.</para>
33
34 <para>The kernel (optionally) mounts an in-memory file system, often generated by
b7a47345 35 <citerefentry project='man-pages'><refentrytitle>dracut</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
543e6bd4
ZJS
36 which looks for the root file system. Nowadays this is usually implemented as an initramfs — a compressed
37 archive which is extracted when the kernel boots up into a lightweight in-memory file system based on
38 tmpfs, but in the past normal file systems using an in-memory block device (ramdisk) were used, and the
39 name "initrd" is still used to describe both concepts. It's the boot loader or the firmware that loads
40 both the kernel and initrd/initramfs images into memory, but the kernel which interprets it as a file
41 system. <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> may
42 be used to manage services in the initrd, similarly to the real system.</para>
43
44 <para>After the root file system is found and mounted, the initrd hands over control to the host's system
45 manager (such as
46 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>) stored in
47 the root file system, which is then responsible for probing all remaining hardware, mounting all
48 necessary file systems and spawning all configured services.</para>
798d3a52
ZJS
49
50 <para>On shutdown, the system manager stops all services, unmounts
51 all file systems (detaching the storage technologies backing
52 them), and then (optionally) jumps back into the initrd code which
53 unmounts/detaches the root file system and the storage it resides
54 on. As a last step, the system is powered down.</para>
55
56 <para>Additional information about the system boot process may be
57 found in
58 <citerefentry project='man-pages'><refentrytitle>boot</refentrytitle><manvolnum>7</manvolnum></citerefentry>.</para>
59 </refsect1>
60
61 <refsect1>
62 <title>System Manager Bootup</title>
63
64 <para>At boot, the system manager on the OS image is responsible
65 for initializing the required file systems, services and drivers
66 that are necessary for operation of the system. On
67 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>
68 systems, this process is split up in various discrete steps which
69 are exposed as target units. (See
70 <citerefentry><refentrytitle>systemd.target</refentrytitle><manvolnum>5</manvolnum></citerefentry>
71 for detailed information about target units.) The boot-up process
72 is highly parallelized so that the order in which specific target
73 units are reached is not deterministic, but still adheres to a
74 limited amount of ordering structure.</para>
75
76 <para>When systemd starts up the system, it will activate all
77 units that are dependencies of <filename>default.target</filename>
78 (as well as recursively all dependencies of these dependencies).
79 Usually, <filename>default.target</filename> is simply an alias of
80 <filename>graphical.target</filename> or
81 <filename>multi-user.target</filename>, depending on whether the
82 system is configured for a graphical UI or only for a text
83 console. To enforce minimal ordering between the units pulled in,
84 a number of well-known target units are available, as listed on
85 <citerefentry><refentrytitle>systemd.special</refentrytitle><manvolnum>7</manvolnum></citerefentry>.</para>
86
87 <para>The following chart is a structural overview of these
88 well-known units and their position in the boot-up logic. The
89 arrows describe which units are pulled in and ordered before which
90 other units. Units near the top are started before units nearer to
91 the bottom of the chart.</para>
013d8a39 92
24c44fdf
ZJS
93 <!-- note: do not use unicode ellipsis here, because docbook will replace that
94 with three dots anyway, messing up alignment -->
f71502c4
ZJS
95<programlisting> cryptsetup-pre.target
96 |
97(various low-level v
98 API VFS mounts: (various cryptsetup devices...)
99 mqueue, configfs, | |
100 debugfs, ...) v |
101 | cryptsetup.target |
102 | (various swap | | remote-fs-pre.target
103 | devices...) | | | |
104 | | | | | v
105 | v local-fs-pre.target | | | (network file systems)
106 | swap.target | | v v |
107 | | v | remote-cryptsetup.target |
108 | | (various low-level (various mounts and | | |
109 | | services: udevd, fsck services...) | | remote-fs.target
110 | | tmpfiles, random | | | /
111 | | seed, sysctl, ...) v | | /
112 | | | local-fs.target | | /
113 | | | | | | /
114 \____|______|_______________ ______|___________/ | /
115 \ / | /
116 v | /
117 sysinit.target | /
118 | | /
119 ______________________/|\_____________________ | /
120 / | | | \ | /
121 | | | | | | /
122 v v | v | | /
123 (various (various | (various | |/
124 timers...) paths...) | sockets...) | |
125 | | | | | |
126 v v | v | |
127timers.target paths.target | sockets.target | |
128 | | | | v |
129 v \_______ | _____/ rescue.service |
130 \|/ | |
131 v v |
132 basic.target <emphasis>rescue.target</emphasis> |
133 | |
134 ________v____________________ |
135 / | \ |
136 | | | |
137 v v v |
138 display- (various system (various system |
139 manager.service services services) |
140 | required for | |
141 | graphical UIs) v v
142 | | <emphasis>multi-user.target</emphasis>
143emergency.service | | |
144 | \_____________ | _____________/
145 v \|/
146<emphasis>emergency.target</emphasis> v
147 <emphasis>graphical.target</emphasis></programlisting>
798d3a52
ZJS
148
149 <para>Target units that are commonly used as boot targets are
150 <emphasis>emphasized</emphasis>. These units are good choices as
151 goal targets, for example by passing them to the
152 <varname>systemd.unit=</varname> kernel command line option (see
153 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>)
72b7d998
ZJS
154 or by symlinking <filename>default.target</filename> to them.
155 </para>
798d3a52
ZJS
156
157 <para><filename>timers.target</filename> is pulled-in by
158 <filename>basic.target</filename> asynchronously. This allows
159 timers units to depend on services which become only available
160 later in boot.</para>
161 </refsect1>
162
277519db
ZJS
163 <refsect1>
164 <title>User manager startup</title>
165
166 <para>The system manager starts the <filename>user@<replaceable>uid</replaceable>.service</filename> unit
167 for each user, which launches a separate unprivileged instance of <command>systemd</command> for each
168 user — the user manager. Similarly to the system manager, the user manager starts units which are pulled
169 in by <filename>default.target</filename>. The following chart is a structural overview of the well-known
170 user units. For non-graphical sessions, <filename>default.target</filename> is used. Whenever the user
171 logs into a graphical session, the login manager will start the
172 <filename>graphical-session.target</filename> target that is used to pull in units required for the
86b52a39 173 graphical session. A number of targets (shown on the right side) are started when specific hardware is
277519db
ZJS
174 available to the user.</para>
175
176<programlisting>
177 (various (various (various
178 timers...) paths...) sockets...) (sound devices)
179 | | | |
180 v v v v
181 timers.target paths.target sockets.target sound.target
182 | | |
183 \______________ _|_________________/ (bluetooth devices)
184 \ / |
185 V v
186 basic.target bluetooth.target
187 |
188 __________/ \_______ (smartcard devices)
189 / \ |
190 | | v
191 | v smartcard.target
192 v graphical-session-pre.target
193 (various user services) | (printers)
194 | v |
a51a3247 195 | (services for the graphical session) v
277519db
ZJS
196 | | printer.target
197 v v
198 <emphasis>default.target</emphasis> graphical-session.target</programlisting>
199
200 </refsect1>
201
798d3a52
ZJS
202 <refsect1>
203 <title>Bootup in the Initial RAM Disk (initrd)</title>
204 <para>The initial RAM disk implementation (initrd) can be set up
205 using systemd as well. In this case, boot up inside the initrd
206 follows the following structure.</para>
207
6e9d2465
JR
208 <para>systemd detects that it is run within an initrd by checking
209 for the file <filename>/etc/initrd-release</filename>.
210 The default target in the initrd is
798d3a52
ZJS
211 <filename>initrd.target</filename>. The bootup process begins
212 identical to the system manager bootup (see above) until it
213 reaches <filename>basic.target</filename>. From there, systemd
214 approaches the special target <filename>initrd.target</filename>.
6d9e45e9
JH
215
216 Before any file systems are mounted, it must be determined whether
217 the system will resume from hibernation or proceed with normal boot.
218 This is accomplished by <filename>systemd-hibernate-resume@.service</filename>
219 which must be finished before <filename>local-fs-pre.target</filename>,
220 so no filesystems can be mounted before the check is complete.
221
7163e1ca 222 When the root device becomes available,
57680ddd 223 <filename>initrd-root-device.target</filename> is reached.
798d3a52
ZJS
224 If the root device can be mounted at
225 <filename>/sysroot</filename>, the
226 <filename>sysroot.mount</filename> unit becomes active and
227 <filename>initrd-root-fs.target</filename> is reached. The service
228 <filename>initrd-parse-etc.service</filename> scans
229 <filename>/sysroot/etc/fstab</filename> for a possible
230 <filename>/usr</filename> mount point and additional entries
231 marked with the <emphasis>x-initrd.mount</emphasis> option. All
232 entries found are mounted below <filename>/sysroot</filename>, and
233 <filename>initrd-fs.target</filename> is reached. The service
234 <filename>initrd-cleanup.service</filename> isolates to the
235 <filename>initrd-switch-root.target</filename>, where cleanup
236 services can run. As the very last step, the
237 <filename>initrd-switch-root.service</filename> is activated,
238 which will cause the system to switch its root to
239 <filename>/sysroot</filename>.
240 </para>
241
72b7d998
ZJS
242<programlisting> : (beginning identical to above)
243 :
244 v
245 basic.target
246 | emergency.service
247 ______________________/| |
248 / | v
7163e1ca
DD
249 | initrd-root-device.target <emphasis>emergency.target</emphasis>
250 | |
251 | v
252 | sysroot.mount
72b7d998
ZJS
253 | |
254 | v
255 | initrd-root-fs.target
256 | |
257 | v
258 v initrd-parse-etc.service
259 (custom initrd |
260 services...) v
261 | (sysroot-usr.mount and
262 | various mounts marked
263 | with fstab option
264 | x-initrd.mount...)
265 | |
266 | v
267 | initrd-fs.target
268 \______________________ |
269 \|
270 v
271 initrd.target
272 |
273 v
274 initrd-cleanup.service
275 isolates to
276 initrd-switch-root.target
277 |
278 v
279 ______________________/|
280 / v
281 | initrd-udevadm-cleanup-db.service
282 v |
283 (custom initrd |
284 services...) |
285 \______________________ |
286 \|
287 v
288 initrd-switch-root.target
289 |
290 v
291 initrd-switch-root.service
292 |
293 v
294 Transition to Host OS</programlisting>
798d3a52
ZJS
295 </refsect1>
296
798d3a52
ZJS
297 <refsect1>
298 <title>System Manager Shutdown</title>
299
300 <para>System shutdown with systemd also consists of various target
301 units with some minimal ordering structure applied:</para>
302
72b7d998
ZJS
303<programlisting> (conflicts with (conflicts with
304 all system all file system
305 services) mounts, swaps,
306 | cryptsetup
307 | devices, ...)
308 | |
309 v v
310 shutdown.target umount.target
311 | |
312 \_______ ______/
313 \ /
314 v
315 (various low-level
316 services)
317 |
318 v
319 final.target
320 |
321 _____________________________________/ \_________________________________
322 / | | \
323 | | | |
324 v v v v
0e0320e0 325systemd-reboot.service systemd-poweroff.service systemd-halt.service systemd-kexec.service
72b7d998
ZJS
326 | | | |
327 v v v v
328 <emphasis>reboot.target</emphasis> <emphasis>poweroff.target</emphasis> <emphasis>halt.target</emphasis> <emphasis>kexec.target</emphasis></programlisting>
798d3a52 329
e799056e
LP
330 <para>Commonly used system shutdown targets are <emphasis>emphasized</emphasis>.</para>
331
332 <para>Note that
39e4f5bc 333 <citerefentry><refentrytitle>systemd-halt.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
e799056e
LP
334 <filename>systemd-reboot.service</filename>, <filename>systemd-poweroff.service</filename> and
335 <filename>systemd-kexec.service</filename> will transition the system and server manager (PID 1) into the second
336 phase of system shutdown (implemented in the <filename>systemd-shutdown</filename> binary), which will unmount any
337 remaining file systems, kill any remaining processes and release any other remaining resources, in a simple and
338 robust fashion, without taking any service or unit concept into account anymore. At that point, regular
339 applications and resources are generally terminated and released already, the second phase hence operates only as
340 safety net for everything that couldn't be stopped or released for some reason during the primary, unit-based
341 shutdown phase described above.</para>
798d3a52
ZJS
342 </refsect1>
343
344 <refsect1>
345 <title>See Also</title>
346 <para>
347 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
348 <citerefentry project='man-pages'><refentrytitle>boot</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
349 <citerefentry><refentrytitle>systemd.special</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
350 <citerefentry><refentrytitle>systemd.target</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
e799056e 351 <citerefentry><refentrytitle>systemd-halt.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
b7a47345 352 <citerefentry project='man-pages'><refentrytitle>dracut</refentrytitle><manvolnum>8</manvolnum></citerefentry>
798d3a52
ZJS
353 </para>
354 </refsect1>
013d8a39
LP
355
356</refentry>