1 <?xml version='
1.0'
?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 SPDX-License-Identifier: LGPL-2.1+
13 <productname>systemd
</productname>
17 <refentrytitle>bootup
</refentrytitle>
18 <manvolnum>7</manvolnum>
22 <refname>bootup
</refname>
23 <refpurpose>System bootup process
</refpurpose>
27 <title>Description
</title>
29 <para>A number of different components are involved in the system
30 boot. Immediately after power-up, the system BIOS will do minimal
31 hardware initialization, and hand control over to a boot loader
32 stored on a persistent storage device. This boot loader will then
33 invoke an OS kernel from disk (or the network). In the Linux case,
34 this kernel (optionally) extracts and executes an initial RAM disk
35 image (initrd), such as generated by
36 <citerefentry project='die-net'
><refentrytitle>dracut
</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
37 which looks for the root file system (possibly using
38 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>
39 for this). After the root file system is found and mounted, the
40 initrd hands over control to the host's system manager (such as
41 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>)
42 stored on the OS image, which is then responsible for probing all
43 remaining hardware, mounting all necessary file systems and
44 spawning all configured services.
</para>
46 <para>On shutdown, the system manager stops all services, unmounts
47 all file systems (detaching the storage technologies backing
48 them), and then (optionally) jumps back into the initrd code which
49 unmounts/detaches the root file system and the storage it resides
50 on. As a last step, the system is powered down.
</para>
52 <para>Additional information about the system boot process may be
54 <citerefentry project='man-pages'
><refentrytitle>boot
</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
</para>
58 <title>System Manager Bootup
</title>
60 <para>At boot, the system manager on the OS image is responsible
61 for initializing the required file systems, services and drivers
62 that are necessary for operation of the system. On
63 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>
64 systems, this process is split up in various discrete steps which
65 are exposed as target units. (See
66 <citerefentry><refentrytitle>systemd.target
</refentrytitle><manvolnum>5</manvolnum></citerefentry>
67 for detailed information about target units.) The boot-up process
68 is highly parallelized so that the order in which specific target
69 units are reached is not deterministic, but still adheres to a
70 limited amount of ordering structure.
</para>
72 <para>When systemd starts up the system, it will activate all
73 units that are dependencies of
<filename>default.target
</filename>
74 (as well as recursively all dependencies of these dependencies).
75 Usually,
<filename>default.target
</filename> is simply an alias of
76 <filename>graphical.target
</filename> or
77 <filename>multi-user.target
</filename>, depending on whether the
78 system is configured for a graphical UI or only for a text
79 console. To enforce minimal ordering between the units pulled in,
80 a number of well-known target units are available, as listed on
81 <citerefentry><refentrytitle>systemd.special
</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
</para>
83 <para>The following chart is a structural overview of these
84 well-known units and their position in the boot-up logic. The
85 arrows describe which units are pulled in and ordered before which
86 other units. Units near the top are started before units nearer to
87 the bottom of the chart.
</para>
89 <!-- note: do not use unicode ellipsis here, because docbook will replace that
90 with three dots anyway, messing up alignment -->
91 <programlisting>local-fs-pre.target
94 (various mounts and (various swap (various cryptsetup
95 fsck services...) devices...) devices...) (various low-level (various low-level
96 | | | services: udevd, API VFS mounts:
97 v v v tmpfiles, random mqueue, configfs,
98 local-fs.target swap.target cryptsetup.target seed, sysctl, ...) debugfs, ...)
100 \__________________|_________________ | ___________________|____________________/
105 ____________________________________/|\________________________________________
109 (various (various | (various rescue.service
110 timers...) paths...) | sockets...) |
112 v v | v
<emphasis>rescue.target
</emphasis>
113 timers.target paths.target | sockets.target
115 v \_________________ | ___________________/
120 ____________________________________/| emergency.service
123 v v v
<emphasis>emergency.target
</emphasis>
124 display- (various system (various system
125 manager.service services services)
128 | |
<emphasis>multi-user.target
</emphasis>
130 \_________________ | _________________/
133 <emphasis>graphical.target
</emphasis></programlisting>
135 <para>Target units that are commonly used as boot targets are
136 <emphasis>emphasized
</emphasis>. These units are good choices as
137 goal targets, for example by passing them to the
138 <varname>systemd.unit=
</varname> kernel command line option (see
139 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>)
140 or by symlinking
<filename>default.target
</filename> to them.
143 <para><filename>timers.target
</filename> is pulled-in by
144 <filename>basic.target
</filename> asynchronously. This allows
145 timers units to depend on services which become only available
146 later in boot.
</para>
150 <title>Bootup in the Initial RAM Disk (initrd)
</title>
151 <para>The initial RAM disk implementation (initrd) can be set up
152 using systemd as well. In this case, boot up inside the initrd
153 follows the following structure.
</para>
155 <para>The default target in the initrd is
156 <filename>initrd.target
</filename>. The bootup process begins
157 identical to the system manager bootup (see above) until it
158 reaches
<filename>basic.target
</filename>. From there, systemd
159 approaches the special target
<filename>initrd.target
</filename>.
161 Before any file systems are mounted, it must be determined whether
162 the system will resume from hibernation or proceed with normal boot.
163 This is accomplished by
<filename>systemd-hibernate-resume@.service
</filename>
164 which must be finished before
<filename>local-fs-pre.target
</filename>,
165 so no filesystems can be mounted before the check is complete.
167 When the root device becomes available,
168 <filename>initd-root-device.target
</filename> is reached.
169 If the root device can be mounted at
170 <filename>/sysroot
</filename>, the
171 <filename>sysroot.mount
</filename> unit becomes active and
172 <filename>initrd-root-fs.target
</filename> is reached. The service
173 <filename>initrd-parse-etc.service
</filename> scans
174 <filename>/sysroot/etc/fstab
</filename> for a possible
175 <filename>/usr
</filename> mount point and additional entries
176 marked with the
<emphasis>x-initrd.mount
</emphasis> option. All
177 entries found are mounted below
<filename>/sysroot
</filename>, and
178 <filename>initrd-fs.target
</filename> is reached. The service
179 <filename>initrd-cleanup.service
</filename> isolates to the
180 <filename>initrd-switch-root.target
</filename>, where cleanup
181 services can run. As the very last step, the
182 <filename>initrd-switch-root.service
</filename> is activated,
183 which will cause the system to switch its root to
184 <filename>/sysroot
</filename>.
187 <programlisting> : (beginning identical to above)
192 ______________________/| |
194 | initrd-root-device.target
<emphasis>emergency.target
</emphasis>
200 | initrd-root-fs.target
203 v initrd-parse-etc.service
206 | (sysroot-usr.mount and
207 | various mounts marked
213 \______________________ |
219 initrd-cleanup.service
221 initrd-switch-root.target
224 ______________________/|
226 | initrd-udevadm-cleanup-db.service
230 \______________________ |
233 initrd-switch-root.target
236 initrd-switch-root.service
239 Transition to Host OS
</programlisting>
243 <title>System Manager Shutdown
</title>
245 <para>System shutdown with systemd also consists of various target
246 units with some minimal ordering structure applied:
</para>
248 <programlisting> (conflicts with (conflicts with
249 all system all file system
250 services) mounts, swaps,
255 shutdown.target umount.target
266 _____________________________________/ \_________________________________
270 systemd-reboot.service systemd-poweroff.service systemd-halt.service systemd-kexec.service
273 <emphasis>reboot.target
</emphasis> <emphasis>poweroff.target
</emphasis> <emphasis>halt.target
</emphasis> <emphasis>kexec.target
</emphasis></programlisting>
275 <para>Commonly used system shutdown targets are
<emphasis>emphasized
</emphasis>.
</para>
278 <citerefentry><refentrytitle>systemd-halt.service
</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
279 <filename>systemd-reboot.service
</filename>,
<filename>systemd-poweroff.service
</filename> and
280 <filename>systemd-kexec.service
</filename> will transition the system and server manager (PID
1) into the second
281 phase of system shutdown (implemented in the
<filename>systemd-shutdown
</filename> binary), which will unmount any
282 remaining file systems, kill any remaining processes and release any other remaining resources, in a simple and
283 robust fashion, without taking any service or unit concept into account anymore. At that point, regular
284 applications and resources are generally terminated and released already, the second phase hence operates only as
285 safety net for everything that couldn't be stopped or released for some reason during the primary, unit-based
286 shutdown phase described above.
</para>
290 <title>See Also
</title>
292 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
293 <citerefentry project='man-pages'
><refentrytitle>boot
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
294 <citerefentry><refentrytitle>systemd.special
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
295 <citerefentry><refentrytitle>systemd.target
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
296 <citerefentry><refentrytitle>systemd-halt.service
</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
297 <citerefentry project='die-net'
><refentrytitle>dracut
</refentrytitle><manvolnum>8</manvolnum></citerefentry>