Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 1 | .. SPDX-License-Identifier: CC-BY-SA-2.0-UK |
| 2 | |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 3 | .. _init-manager: |
| 4 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 5 | Selecting an Initialization Manager |
| 6 | *********************************** |
| 7 | |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 8 | By default, the Yocto Project uses :wikipedia:`SysVinit <Init#SysV-style>` as |
| 9 | the initialization manager. There is also support for BusyBox init, a simpler |
| 10 | implementation, as well as support for :wikipedia:`systemd <Systemd>`, which |
| 11 | is a full replacement for init with parallel starting of services, reduced |
| 12 | shell overhead, increased security and resource limits for services, and other |
| 13 | features that are used by many distributions. |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 14 | |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 15 | Within the system, SysVinit and BusyBox init treat system components as |
| 16 | services. These services are maintained as shell scripts stored in the |
| 17 | ``/etc/init.d/`` directory. |
| 18 | |
| 19 | SysVinit is more elaborate than BusyBox init and organizes services in |
| 20 | different run levels. This organization is maintained by putting links |
| 21 | to the services in the ``/etc/rcN.d/`` directories, where `N/` is one |
| 22 | of the following options: "S", "0", "1", "2", "3", "4", "5", or "6". |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 23 | |
| 24 | .. note:: |
| 25 | |
| 26 | Each runlevel has a dependency on the previous runlevel. This |
| 27 | dependency allows the services to work properly. |
| 28 | |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 29 | Both SysVinit and BusyBox init are configured through the ``/etc/inittab`` |
| 30 | file, with a very similar syntax, though of course BusyBox init features |
| 31 | are more limited. |
| 32 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 33 | In comparison, systemd treats components as units. Using units is a |
| 34 | broader concept as compared to using a service. A unit includes several |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 35 | different types of entities. ``Service`` is one of the types of entities. |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 36 | The runlevel concept in SysVinit corresponds to the concept of a target |
| 37 | in systemd, where target is also a type of supported unit. |
| 38 | |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 39 | In systems with SysVinit or BusyBox init, services load sequentially (i.e. one |
| 40 | by one) during init and parallelization is not supported. With systemd, services |
| 41 | start in parallel. This method can have an impact on the startup performance |
| 42 | of a given service, though systemd will also provide more services by default, |
| 43 | therefore increasing the total system boot time. systemd also substantially |
| 44 | increases system size because of its multiple components and the extra |
| 45 | dependencies it pulls. |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 46 | |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 47 | On the contrary, BusyBox init is the simplest and the lightest solution and |
| 48 | also comes with BusyBox mdev as device manager, a lighter replacement to |
| 49 | :wikipedia:`udev <Udev>`, which SysVinit and systemd both use. |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 50 | |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 51 | The ":ref:`device-manager`" chapter has more details about device managers. |
| 52 | |
| 53 | Using SysVinit with udev |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 54 | ========================= |
| 55 | |
Patrick Williams | 520786c | 2023-06-25 16:20:36 -0500 | [diff] [blame] | 56 | SysVinit with the udev device manager corresponds to the |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 57 | default setting in Poky. This corresponds to setting:: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 58 | |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 59 | INIT_MANAGER = "sysvinit" |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 60 | |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 61 | Using BusyBox init with BusyBox mdev |
| 62 | ==================================== |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 63 | |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 64 | BusyBox init with BusyBox mdev is the simplest and lightest solution |
| 65 | for small root filesystems. All you need is BusyBox, which most systems |
| 66 | have anyway:: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 67 | |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 68 | INIT_MANAGER = "mdev-busybox" |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 69 | |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 70 | Using systemd |
| 71 | ============= |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 72 | |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 73 | The last option is to use systemd together with the udev device |
| 74 | manager. This is the most powerful and versatile solution, especially |
| 75 | for more complex systems:: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 76 | |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 77 | INIT_MANAGER = "systemd" |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 78 | |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 79 | This will enable systemd and remove sysvinit components from the image. |
| 80 | See :yocto_git:`meta/conf/distro/include/init-manager-systemd.inc |
| 81 | </poky/tree/meta/conf/distro/include/init-manager-systemd.inc>` for exact |
| 82 | details on what this does. |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 83 | |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 84 | Controling systemd from the target command line |
| 85 | ----------------------------------------------- |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 86 | |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 87 | Here is a quick reference for controling systemd from the command line on the |
| 88 | target. Instead of opening and sometimes modifying files, most interaction |
| 89 | happens through the ``systemctl`` and ``journalctl`` commands: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 90 | |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 91 | - ``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 Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 99 | |
| 100 | Using systemd-journald without a traditional syslog daemon |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 101 | ---------------------------------------------------------- |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 102 | |
| 103 | Counter-intuitively, ``systemd-journald`` is not a syslog runtime or provider, |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 104 | and the proper way to use ``systemd-journald`` as your sole logging mechanism is to |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 105 | effectively disable syslog entirely by setting these variables in your distribution |
| 106 | configuration file:: |
| 107 | |
| 108 | VIRTUAL-RUNTIME_syslog = "" |
| 109 | VIRTUAL-RUNTIME_base-utils-syslog = "" |
| 110 | |
| 111 | Doing so will prevent ``rsyslog`` / ``busybox-syslog`` from being pulled in by |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 112 | default, leaving only ``systemd-journald``. |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 113 | |
Andrew Geissler | 028142b | 2023-05-05 11:29:21 -0500 | [diff] [blame] | 114 | Summary |
| 115 | ------- |
| 116 | |
| 117 | The Yocto Project supports three different initialization managers, offering |
| 118 | increasing 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. |