blob: 20d61ea8305f492401a1bba149dc94c0f344117c [file] [log] [blame]
Andrew Geissler517393d2023-01-13 08:55:19 -06001.. SPDX-License-Identifier: CC-BY-SA-2.0-UK
2
Patrick Williams8e7b46e2023-05-01 14:19:06 -05003.. _init-manager:
4
Andrew Geissler517393d2023-01-13 08:55:19 -06005Selecting an Initialization Manager
6***********************************
7
Patrick Williams8e7b46e2023-05-01 14:19:06 -05008By default, the Yocto Project uses :wikipedia:`SysVinit <Init#SysV-style>` as
9the initialization manager. There is also support for BusyBox init, a simpler
10implementation, as well as support for :wikipedia:`systemd <Systemd>`, which
11is a full replacement for init with parallel starting of services, reduced
12shell overhead, increased security and resource limits for services, and other
13features that are used by many distributions.
Andrew Geissler517393d2023-01-13 08:55:19 -060014
Patrick Williams8e7b46e2023-05-01 14:19:06 -050015Within the system, SysVinit and BusyBox init treat system components as
16services. These services are maintained as shell scripts stored in the
17``/etc/init.d/`` directory.
18
19SysVinit is more elaborate than BusyBox init and organizes services in
20different run levels. This organization is maintained by putting links
21to the services in the ``/etc/rcN.d/`` directories, where `N/` is one
22of the following options: "S", "0", "1", "2", "3", "4", "5", or "6".
Andrew Geissler517393d2023-01-13 08:55:19 -060023
24.. note::
25
26 Each runlevel has a dependency on the previous runlevel. This
27 dependency allows the services to work properly.
28
Patrick Williams8e7b46e2023-05-01 14:19:06 -050029Both SysVinit and BusyBox init are configured through the ``/etc/inittab``
30file, with a very similar syntax, though of course BusyBox init features
31are more limited.
32
Andrew Geissler517393d2023-01-13 08:55:19 -060033In comparison, systemd treats components as units. Using units is a
34broader concept as compared to using a service. A unit includes several
Patrick Williams8e7b46e2023-05-01 14:19:06 -050035different types of entities. ``Service`` is one of the types of entities.
Andrew Geissler517393d2023-01-13 08:55:19 -060036The runlevel concept in SysVinit corresponds to the concept of a target
37in systemd, where target is also a type of supported unit.
38
Patrick Williams8e7b46e2023-05-01 14:19:06 -050039In systems with SysVinit or BusyBox init, services load sequentially (i.e. one
40by one) during init and parallelization is not supported. With systemd, services
41start in parallel. This method can have an impact on the startup performance
42of a given service, though systemd will also provide more services by default,
43therefore increasing the total system boot time. systemd also substantially
44increases system size because of its multiple components and the extra
45dependencies it pulls.
Andrew Geissler517393d2023-01-13 08:55:19 -060046
Patrick Williams8e7b46e2023-05-01 14:19:06 -050047On the contrary, BusyBox init is the simplest and the lightest solution and
48also comes with BusyBox mdev as device manager, a lighter replacement to
49:wikipedia:`udev <Udev>`, which SysVinit and systemd both use.
Andrew Geissler517393d2023-01-13 08:55:19 -060050
Patrick Williams8e7b46e2023-05-01 14:19:06 -050051The ":ref:`device-manager`" chapter has more details about device managers.
52
53Using SysVinit with udev
Andrew Geissler517393d2023-01-13 08:55:19 -060054=========================
55
Patrick Williams520786c2023-06-25 16:20:36 -050056SysVinit with the udev device manager corresponds to the
Patrick Williams8e7b46e2023-05-01 14:19:06 -050057default setting in Poky. This corresponds to setting::
Andrew Geissler517393d2023-01-13 08:55:19 -060058
Patrick Williams8e7b46e2023-05-01 14:19:06 -050059 INIT_MANAGER = "sysvinit"
Andrew Geissler517393d2023-01-13 08:55:19 -060060
Patrick Williams8e7b46e2023-05-01 14:19:06 -050061Using BusyBox init with BusyBox mdev
62====================================
Andrew Geissler517393d2023-01-13 08:55:19 -060063
Patrick Williams8e7b46e2023-05-01 14:19:06 -050064BusyBox init with BusyBox mdev is the simplest and lightest solution
65for small root filesystems. All you need is BusyBox, which most systems
66have anyway::
Andrew Geissler517393d2023-01-13 08:55:19 -060067
Patrick Williams8e7b46e2023-05-01 14:19:06 -050068 INIT_MANAGER = "mdev-busybox"
Andrew Geissler517393d2023-01-13 08:55:19 -060069
Patrick Williams8e7b46e2023-05-01 14:19:06 -050070Using systemd
71=============
Andrew Geissler517393d2023-01-13 08:55:19 -060072
Patrick Williams8e7b46e2023-05-01 14:19:06 -050073The last option is to use systemd together with the udev device
74manager. This is the most powerful and versatile solution, especially
75for more complex systems::
Andrew Geissler517393d2023-01-13 08:55:19 -060076
Patrick Williams8e7b46e2023-05-01 14:19:06 -050077 INIT_MANAGER = "systemd"
Andrew Geissler517393d2023-01-13 08:55:19 -060078
Patrick Williams8e7b46e2023-05-01 14:19:06 -050079This will enable systemd and remove sysvinit components from the image.
80See :yocto_git:`meta/conf/distro/include/init-manager-systemd.inc
81</poky/tree/meta/conf/distro/include/init-manager-systemd.inc>` for exact
82details on what this does.
Andrew Geissler517393d2023-01-13 08:55:19 -060083
Patrick Williams8e7b46e2023-05-01 14:19:06 -050084Controling systemd from the target command line
85-----------------------------------------------
Andrew Geissler517393d2023-01-13 08:55:19 -060086
Patrick Williams8e7b46e2023-05-01 14:19:06 -050087Here is a quick reference for controling systemd from the command line on the
88target. Instead of opening and sometimes modifying files, most interaction
89happens through the ``systemctl`` and ``journalctl`` commands:
Andrew Geissler517393d2023-01-13 08:55:19 -060090
Patrick Williams8e7b46e2023-05-01 14:19:06 -050091- ``systemctl status``: show the status of all services
92- ``systemctl status <service>``: show the status of one service
93- ``systemctl [start|stop] <service>``: start or stop a service
94- ``systemctl [enable|disable] <service>``: enable or disable a service at boot time
95- ``systemctl list-units``: list all available units
96- ``journalctl -a``: show all logs for all services
97- ``journalctl -f``: show only the last log entries, and keep printing updates as they arrive
98- ``journalctl -u``: show only logs from a particular service
Andrew Geissler517393d2023-01-13 08:55:19 -060099
100Using systemd-journald without a traditional syslog daemon
Patrick Williams8e7b46e2023-05-01 14:19:06 -0500101----------------------------------------------------------
Andrew Geissler517393d2023-01-13 08:55:19 -0600102
103Counter-intuitively, ``systemd-journald`` is not a syslog runtime or provider,
Patrick Williams8e7b46e2023-05-01 14:19:06 -0500104and the proper way to use ``systemd-journald`` as your sole logging mechanism is to
Andrew Geissler517393d2023-01-13 08:55:19 -0600105effectively disable syslog entirely by setting these variables in your distribution
106configuration file::
107
108 VIRTUAL-RUNTIME_syslog = ""
109 VIRTUAL-RUNTIME_base-utils-syslog = ""
110
111Doing so will prevent ``rsyslog`` / ``busybox-syslog`` from being pulled in by
Patrick Williams8e7b46e2023-05-01 14:19:06 -0500112default, leaving only ``systemd-journald``.
Andrew Geissler517393d2023-01-13 08:55:19 -0600113
Andrew Geissler028142b2023-05-05 11:29:21 -0500114Summary
115-------
116
117The Yocto Project supports three different initialization managers, offering
118increasing levels of complexity and functionality:
119
120.. list-table::
121 :widths: 40 20 20 20
122 :header-rows: 1
123
124 * -
125 - BusyBox init
126 - SysVinit
127 - systemd
128 * - Size
129 - Small
130 - Small
131 - Big [#footnote-systemd-size]_
132 * - Complexity
133 - Small
134 - Medium
135 - High
136 * - Support for boot profiles
137 - No
138 - Yes ("runlevels")
139 - Yes ("targets")
140 * - Services defined as
141 - Shell scripts
142 - Shell scripts
143 - Description files
144 * - Starting services in parallel
145 - No
146 - No
147 - Yes
148 * - Setting service resource limits
149 - No
150 - No
151 - Yes
152 * - Support service isolation
153 - No
154 - No
155 - Yes
156 * - Integrated logging
157 - No
158 - No
159 - Yes
160
161.. [#footnote-systemd-size] Using systemd increases the ``core-image-minimal``
162 image size by 160\% for ``qemux86-64`` on Mickledore (4.2), compared to SysVinit.