]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/bootup.xml
travis: use UBSan checks from OSS-Fuzz
[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
798d3a52 35 <citerefentry project='die-net'><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 -->
013d8a39 95<programlisting>local-fs-pre.target
72b7d998
ZJS
96 |
97 v
013d8a39 98(various mounts and (various swap (various cryptsetup
72b7d998
ZJS
99 fsck services...) devices...) devices...) (various low-level (various low-level
100 | | | services: udevd, API VFS mounts:
101 v v v tmpfiles, random mqueue, configfs,
013d8a39 102 local-fs.target swap.target cryptsetup.target seed, sysctl, ...) debugfs, ...)
72b7d998
ZJS
103 | | | | |
104 \__________________|_________________ | ___________________|____________________/
105 \|/
106 v
107 sysinit.target
108 |
109 ____________________________________/|\________________________________________
110 / | | | \
111 | | | | |
112 v v | v v
113 (various (various | (various rescue.service
114 timers...) paths...) | sockets...) |
115 | | | | v
116 v v | v <emphasis>rescue.target</emphasis>
117 timers.target paths.target | sockets.target
118 | | | |
b44787bd 119 v \_________________ | ___________________/
72b7d998
ZJS
120 \|/
121 v
122 basic.target
123 |
124 ____________________________________/| emergency.service
125 / | | |
126 | | | v
127 v v v <emphasis>emergency.target</emphasis>
128 display- (various system (various system
129 manager.service services services)
130 | required for |
131 | graphical UIs) v
132 | | <emphasis>multi-user.target</emphasis>
133 | | |
134 \_________________ | _________________/
135 \|/
136 v
137 <emphasis>graphical.target</emphasis></programlisting>
798d3a52
ZJS
138
139 <para>Target units that are commonly used as boot targets are
140 <emphasis>emphasized</emphasis>. These units are good choices as
141 goal targets, for example by passing them to the
142 <varname>systemd.unit=</varname> kernel command line option (see
143 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>)
72b7d998
ZJS
144 or by symlinking <filename>default.target</filename> to them.
145 </para>
798d3a52
ZJS
146
147 <para><filename>timers.target</filename> is pulled-in by
148 <filename>basic.target</filename> asynchronously. This allows
149 timers units to depend on services which become only available
150 later in boot.</para>
151 </refsect1>
152
153 <refsect1>
154 <title>Bootup in the Initial RAM Disk (initrd)</title>
155 <para>The initial RAM disk implementation (initrd) can be set up
156 using systemd as well. In this case, boot up inside the initrd
157 follows the following structure.</para>
158
6e9d2465
JR
159 <para>systemd detects that it is run within an initrd by checking
160 for the file <filename>/etc/initrd-release</filename>.
161 The default target in the initrd is
798d3a52
ZJS
162 <filename>initrd.target</filename>. The bootup process begins
163 identical to the system manager bootup (see above) until it
164 reaches <filename>basic.target</filename>. From there, systemd
165 approaches the special target <filename>initrd.target</filename>.
6d9e45e9
JH
166
167 Before any file systems are mounted, it must be determined whether
168 the system will resume from hibernation or proceed with normal boot.
169 This is accomplished by <filename>systemd-hibernate-resume@.service</filename>
170 which must be finished before <filename>local-fs-pre.target</filename>,
171 so no filesystems can be mounted before the check is complete.
172
7163e1ca
DD
173 When the root device becomes available,
174 <filename>initd-root-device.target</filename> is reached.
798d3a52
ZJS
175 If the root device can be mounted at
176 <filename>/sysroot</filename>, the
177 <filename>sysroot.mount</filename> unit becomes active and
178 <filename>initrd-root-fs.target</filename> is reached. The service
179 <filename>initrd-parse-etc.service</filename> scans
180 <filename>/sysroot/etc/fstab</filename> for a possible
181 <filename>/usr</filename> mount point and additional entries
182 marked with the <emphasis>x-initrd.mount</emphasis> option. All
183 entries found are mounted below <filename>/sysroot</filename>, and
184 <filename>initrd-fs.target</filename> is reached. The service
185 <filename>initrd-cleanup.service</filename> isolates to the
186 <filename>initrd-switch-root.target</filename>, where cleanup
187 services can run. As the very last step, the
188 <filename>initrd-switch-root.service</filename> is activated,
189 which will cause the system to switch its root to
190 <filename>/sysroot</filename>.
191 </para>
192
72b7d998
ZJS
193<programlisting> : (beginning identical to above)
194 :
195 v
196 basic.target
197 | emergency.service
198 ______________________/| |
199 / | v
7163e1ca
DD
200 | initrd-root-device.target <emphasis>emergency.target</emphasis>
201 | |
202 | v
203 | sysroot.mount
72b7d998
ZJS
204 | |
205 | v
206 | initrd-root-fs.target
207 | |
208 | v
209 v initrd-parse-etc.service
210 (custom initrd |
211 services...) v
212 | (sysroot-usr.mount and
213 | various mounts marked
214 | with fstab option
215 | x-initrd.mount...)
216 | |
217 | v
218 | initrd-fs.target
219 \______________________ |
220 \|
221 v
222 initrd.target
223 |
224 v
225 initrd-cleanup.service
226 isolates to
227 initrd-switch-root.target
228 |
229 v
230 ______________________/|
231 / v
232 | initrd-udevadm-cleanup-db.service
233 v |
234 (custom initrd |
235 services...) |
236 \______________________ |
237 \|
238 v
239 initrd-switch-root.target
240 |
241 v
242 initrd-switch-root.service
243 |
244 v
245 Transition to Host OS</programlisting>
798d3a52
ZJS
246 </refsect1>
247
798d3a52
ZJS
248 <refsect1>
249 <title>System Manager Shutdown</title>
250
251 <para>System shutdown with systemd also consists of various target
252 units with some minimal ordering structure applied:</para>
253
72b7d998
ZJS
254<programlisting> (conflicts with (conflicts with
255 all system all file system
256 services) mounts, swaps,
257 | cryptsetup
258 | devices, ...)
259 | |
260 v v
261 shutdown.target umount.target
262 | |
263 \_______ ______/
264 \ /
265 v
266 (various low-level
267 services)
268 |
269 v
270 final.target
271 |
272 _____________________________________/ \_________________________________
273 / | | \
274 | | | |
275 v v v v
0e0320e0 276systemd-reboot.service systemd-poweroff.service systemd-halt.service systemd-kexec.service
72b7d998
ZJS
277 | | | |
278 v v v v
279 <emphasis>reboot.target</emphasis> <emphasis>poweroff.target</emphasis> <emphasis>halt.target</emphasis> <emphasis>kexec.target</emphasis></programlisting>
798d3a52 280
e799056e
LP
281 <para>Commonly used system shutdown targets are <emphasis>emphasized</emphasis>.</para>
282
283 <para>Note that
39e4f5bc 284 <citerefentry><refentrytitle>systemd-halt.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
e799056e
LP
285 <filename>systemd-reboot.service</filename>, <filename>systemd-poweroff.service</filename> and
286 <filename>systemd-kexec.service</filename> will transition the system and server manager (PID 1) into the second
287 phase of system shutdown (implemented in the <filename>systemd-shutdown</filename> binary), which will unmount any
288 remaining file systems, kill any remaining processes and release any other remaining resources, in a simple and
289 robust fashion, without taking any service or unit concept into account anymore. At that point, regular
290 applications and resources are generally terminated and released already, the second phase hence operates only as
291 safety net for everything that couldn't be stopped or released for some reason during the primary, unit-based
292 shutdown phase described above.</para>
798d3a52
ZJS
293 </refsect1>
294
295 <refsect1>
296 <title>See Also</title>
297 <para>
298 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
299 <citerefentry project='man-pages'><refentrytitle>boot</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
300 <citerefentry><refentrytitle>systemd.special</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
301 <citerefentry><refentrytitle>systemd.target</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
e799056e 302 <citerefentry><refentrytitle>systemd-halt.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
798d3a52
ZJS
303 <citerefentry project='die-net'><refentrytitle>dracut</refentrytitle><manvolnum>8</manvolnum></citerefentry>
304 </para>
305 </refsect1>
013d8a39
LP
306
307</refentry>