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+
8 Copyright 2012 Lennart Poettering
11 <refentry id=
"bootup">
15 <productname>systemd
</productname>
19 <contrib>Developer
</contrib>
20 <firstname>Lennart
</firstname>
21 <surname>Poettering
</surname>
22 <email>lennart@poettering.net
</email>
28 <refentrytitle>bootup
</refentrytitle>
29 <manvolnum>7</manvolnum>
33 <refname>bootup
</refname>
34 <refpurpose>System bootup process
</refpurpose>
38 <title>Description
</title>
40 <para>A number of different components are involved in the system
41 boot. Immediately after power-up, the system BIOS will do minimal
42 hardware initialization, and hand control over to a boot loader
43 stored on a persistent storage device. This boot loader will then
44 invoke an OS kernel from disk (or the network). In the Linux case,
45 this kernel (optionally) extracts and executes an initial RAM disk
46 image (initrd), such as generated by
47 <citerefentry project='die-net'
><refentrytitle>dracut
</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
48 which looks for the root file system (possibly using
49 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>
50 for this). After the root file system is found and mounted, the
51 initrd hands over control to the host's system manager (such as
52 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>)
53 stored on the OS image, which is then responsible for probing all
54 remaining hardware, mounting all necessary file systems and
55 spawning all configured services.
</para>
57 <para>On shutdown, the system manager stops all services, unmounts
58 all file systems (detaching the storage technologies backing
59 them), and then (optionally) jumps back into the initrd code which
60 unmounts/detaches the root file system and the storage it resides
61 on. As a last step, the system is powered down.
</para>
63 <para>Additional information about the system boot process may be
65 <citerefentry project='man-pages'
><refentrytitle>boot
</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
</para>
69 <title>System Manager Bootup
</title>
71 <para>At boot, the system manager on the OS image is responsible
72 for initializing the required file systems, services and drivers
73 that are necessary for operation of the system. On
74 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>
75 systems, this process is split up in various discrete steps which
76 are exposed as target units. (See
77 <citerefentry><refentrytitle>systemd.target
</refentrytitle><manvolnum>5</manvolnum></citerefentry>
78 for detailed information about target units.) The boot-up process
79 is highly parallelized so that the order in which specific target
80 units are reached is not deterministic, but still adheres to a
81 limited amount of ordering structure.
</para>
83 <para>When systemd starts up the system, it will activate all
84 units that are dependencies of
<filename>default.target
</filename>
85 (as well as recursively all dependencies of these dependencies).
86 Usually,
<filename>default.target
</filename> is simply an alias of
87 <filename>graphical.target
</filename> or
88 <filename>multi-user.target
</filename>, depending on whether the
89 system is configured for a graphical UI or only for a text
90 console. To enforce minimal ordering between the units pulled in,
91 a number of well-known target units are available, as listed on
92 <citerefentry><refentrytitle>systemd.special
</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
</para>
94 <para>The following chart is a structural overview of these
95 well-known units and their position in the boot-up logic. The
96 arrows describe which units are pulled in and ordered before which
97 other units. Units near the top are started before units nearer to
98 the bottom of the chart.
</para>
100 <!-- note: do not use unicode ellipsis here, because docbook will replace that
101 with three dots anyway, messing up alignment -->
102 <programlisting>local-fs-pre.target
105 (various mounts and (various swap (various cryptsetup
106 fsck services...) devices...) devices...) (various low-level (various low-level
107 | | | services: udevd, API VFS mounts:
108 v v v tmpfiles, random mqueue, configfs,
109 local-fs.target swap.target cryptsetup.target seed, sysctl, ...) debugfs, ...)
111 \__________________|_________________ | ___________________|____________________/
116 ____________________________________/|\________________________________________
120 (various (various | (various rescue.service
121 timers...) paths...) | sockets...) |
123 v v | v
<emphasis>rescue.target
</emphasis>
124 timers.target paths.target | sockets.target
126 v \_________________ | ___________________/
131 ____________________________________/| emergency.service
134 v v v
<emphasis>emergency.target
</emphasis>
135 display- (various system (various system
136 manager.service services services)
139 | |
<emphasis>multi-user.target
</emphasis>
141 \_________________ | _________________/
144 <emphasis>graphical.target
</emphasis></programlisting>
146 <para>Target units that are commonly used as boot targets are
147 <emphasis>emphasized
</emphasis>. These units are good choices as
148 goal targets, for example by passing them to the
149 <varname>systemd.unit=
</varname> kernel command line option (see
150 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>)
151 or by symlinking
<filename>default.target
</filename> to them.
154 <para><filename>timers.target
</filename> is pulled-in by
155 <filename>basic.target
</filename> asynchronously. This allows
156 timers units to depend on services which become only available
157 later in boot.
</para>
161 <title>Bootup in the Initial RAM Disk (initrd)
</title>
162 <para>The initial RAM disk implementation (initrd) can be set up
163 using systemd as well. In this case, boot up inside the initrd
164 follows the following structure.
</para>
166 <para>The default target in the initrd is
167 <filename>initrd.target
</filename>. The bootup process begins
168 identical to the system manager bootup (see above) until it
169 reaches
<filename>basic.target
</filename>. From there, systemd
170 approaches the special target
<filename>initrd.target
</filename>.
172 Before any file systems are mounted, it must be determined whether
173 the system will resume from hibernation or proceed with normal boot.
174 This is accomplished by
<filename>systemd-hibernate-resume@.service
</filename>
175 which must be finished before
<filename>local-fs-pre.target
</filename>,
176 so no filesystems can be mounted before the check is complete.
178 When the root device becomes available,
179 <filename>initd-root-device.target
</filename> is reached.
180 If the root device can be mounted at
181 <filename>/sysroot
</filename>, the
182 <filename>sysroot.mount
</filename> unit becomes active and
183 <filename>initrd-root-fs.target
</filename> is reached. The service
184 <filename>initrd-parse-etc.service
</filename> scans
185 <filename>/sysroot/etc/fstab
</filename> for a possible
186 <filename>/usr
</filename> mount point and additional entries
187 marked with the
<emphasis>x-initrd.mount
</emphasis> option. All
188 entries found are mounted below
<filename>/sysroot
</filename>, and
189 <filename>initrd-fs.target
</filename> is reached. The service
190 <filename>initrd-cleanup.service
</filename> isolates to the
191 <filename>initrd-switch-root.target
</filename>, where cleanup
192 services can run. As the very last step, the
193 <filename>initrd-switch-root.service
</filename> is activated,
194 which will cause the system to switch its root to
195 <filename>/sysroot
</filename>.
198 <programlisting> : (beginning identical to above)
203 ______________________/| |
205 | initrd-root-device.target
<emphasis>emergency.target
</emphasis>
211 | initrd-root-fs.target
214 v initrd-parse-etc.service
217 | (sysroot-usr.mount and
218 | various mounts marked
224 \______________________ |
230 initrd-cleanup.service
232 initrd-switch-root.target
235 ______________________/|
237 | initrd-udevadm-cleanup-db.service
241 \______________________ |
244 initrd-switch-root.target
247 initrd-switch-root.service
250 Transition to Host OS
</programlisting>
254 <title>System Manager Shutdown
</title>
256 <para>System shutdown with systemd also consists of various target
257 units with some minimal ordering structure applied:
</para>
259 <programlisting> (conflicts with (conflicts with
260 all system all file system
261 services) mounts, swaps,
266 shutdown.target umount.target
277 _____________________________________/ \_________________________________
281 systemd-reboot.service systemd-poweroff.service systemd-halt.service systemd-kexec.service
284 <emphasis>reboot.target
</emphasis> <emphasis>poweroff.target
</emphasis> <emphasis>halt.target
</emphasis> <emphasis>kexec.target
</emphasis></programlisting>
286 <para>Commonly used system shutdown targets are
<emphasis>emphasized
</emphasis>.
</para>
289 <citerefentry><refentrytitle>systemd-halt.service
</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
290 <filename>systemd-reboot.service
</filename>,
<filename>systemd-poweroff.service
</filename> and
291 <filename>systemd-kexec.service
</filename> will transition the system and server manager (PID
1) into the second
292 phase of system shutdown (implemented in the
<filename>systemd-shutdown
</filename> binary), which will unmount any
293 remaining file systems, kill any remaining processes and release any other remaining resources, in a simple and
294 robust fashion, without taking any service or unit concept into account anymore. At that point, regular
295 applications and resources are generally terminated and released already, the second phase hence operates only as
296 safety net for everything that couldn't be stopped or released for some reason during the primary, unit-based
297 shutdown phase described above.
</para>
301 <title>See Also
</title>
303 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
304 <citerefentry project='man-pages'
><refentrytitle>boot
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
305 <citerefentry><refentrytitle>systemd.special
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
306 <citerefentry><refentrytitle>systemd.target
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
307 <citerefentry><refentrytitle>systemd-halt.service
</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
308 <citerefentry project='die-net'
><refentrytitle>dracut
</refentrytitle><manvolnum>8</manvolnum></citerefentry>