init-manager.rst 5.7 KB

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