Jump to content

Init

From Wikipedia, the free encyclopedia

Template:Short description Template:About Template:Primary sources Template:Lowercase title

File:Version 7 UNIX SIMH PDP11 Etc.png
Version 7 Unix: Template:Mono listing, showing Template:Mono and Template:Mono
File:Version 7 UNIX SIMH PDP11 Etc Rc.png
Version 7 Unix: contents of an Template:Mono Bourne shell script

In Unix-like computer operating systems, init (short for initialization) is the first user-space process started during booting of the operating system. Init is a daemon process that continues running until the system is shut down. It is the direct or indirect ancestor of all other processes and automatically adopts all orphaned processes. Init is started by the kernel during the booting process; in most Unix-like systems, a kernel panic will occur if the kernel is unable to start it or if it dies for any reason. Init is typically assigned process identifier 1.

In Unix systems such as System III and System V, the design of init diverged from the functionality provided by the init in Research Unix and its BSD derivatives. Up until the early 2010s,[1]Template:Failed verification most Linux distributions employed a traditional init that was somewhat compatible with System V, while some distributions such as Slackware use BSD-style startup scripts, and other distributions such as Gentoo have their own customized versions.

Since then, most Linux distributions have employed a more modern init system, with most employing the init provided by the systemd project. Some distributions have elected to create their own System V-init compatible system, such as Gentoo Linux's OpenRC and Void Linux's runit. These projects typically include features originally not in System V's init, such as multi-threading or interactive init. Most modern init systems are also able to dynamically start, stop and enable services after boot with prompting by the user.

Research Unix-style/BSD-style

Research Unix init runs the initialization shell script located at /etc/rc,[2] then launches getty on terminals under the control of /etc/ttys.[3] There are no runlevels; the /etc/rc file determines what programs are run by init. The advantage of this system is that it is simple and easy to edit manually. However, new software added to the system may require changes to existing files that risk producing an unbootable system.

BSD init was, prior to 4.3BSD, the same as Research UNIX's init;[4][5] in 4.3BSD, it added support for running a windowing system such as X on graphical terminals under the control of /etc/ttys.[6][7] To remove the requirement to edit /etc/rc, BSD variants have long supported a site-specific /etc/rc.local file that is run in a sub-shell near the end of the boot sequence.

A fully modular system was introduced with NetBSD 1.5 and ported to FreeBSD 5.0, OpenBSD 4.9 and successors. This system executes scripts in the /etc/rc.d directory. Unlike System V's script ordering, which is derived from the filename of each script, this system uses explicit dependency tags placed within each script.[8] The order in which scripts are executed is determined by the rcorder utility based on the requirements stated in these tags.

SysV-style

File:Sysv-rc-conf.png
Template:Mono, a TUI utility that selects which SysV-style init scripts will be run in each runlevel

When compared to its predecessors, AT&T's UNIX System III introduced a new style of system startup configuration,[9] which survived (with modifications) into UNIX System V and is therefore called the "SysV-style init".

At any moment, a running System V is in one of the predetermined number of states, called runlevels. At least one runlevel is the normal operating state of the system; typically, other runlevels represent single-user mode (used for repairing a faulty system), system shutdown, and various other states. Switching from one runlevel to another causes a per-runlevel set of scripts to be run, which typically mount filesystems, start or stop daemons, start or stop the X Window System, shutdown the machine, etc.

Runlevels

Template:Details

The runlevels in System V describe certain states of a machine, characterized by the processes and daemons running in each of them. In general, there are seven runlevels, out of which three runlevels are considered "standard", as they are essential to the operation of a system: Template:Ordered list Aside from these standard ones, Unix and Unix-like systems treat runlevels somewhat differently. The common denominator, the /etc/inittab file, defines what each configured runlevel does in a given system.

Default runlevels

Operating system Default runlevel
AIX 2[10]
antiX 5
Gentoo Linux 3[11]
HP-UX 3 (console/server/multiuser) or 4 (graphical)
Slackware Linux 3
Solaris / illumos 3[12]
UNIX System V Releases 3.x, 4.x 2
UnixWare 7.x 3

On Linux distributions defaulting to runlevel 5 in the table on the right, runlevel 5 invokes a multiuser graphical environment running the X Window System, usually with a display manager like GDM or KDM. However, the Solaris and illumos operating systems typically reserve runlevel 5 to shut down and automatically power off the machine.

On most systems, all users can check the current runlevel with either the runlevel or who -r command.[13] The root user typically changes the current runlevel by running the telinit or init commands. The /etc/inittab file sets the default runlevel with the :initdefault: entry.

On Unix systems, changing the runlevel is achieved by starting only the missing services (as each level defines only those that are started / stopped).Template:Citation needed For example, changing a system from runlevel 3 to 4 might only start the local X server. Going back to runlevel 3, it would be stopped again.

Other implementations

Traditionally, one of the major drawbacks of init is that it starts tasks serially, waiting for each to finish loading before moving on to the next. When startup processes end up Input/output (I/O) blocked, this can result in long delays during boot. Speeding up I/O, e.g. by using SSDs, may shorten the delays but it does not address the root cause.

Various efforts have been made to replace the traditional init daemons to address this and other design problems, including:

General

Template:Sort-under

Name Developer Latest release License Notes
Version Date
BootScripts GoboLinux Scripts Contributors[14] 016.02 Template:Dts; Template:Time ago Template:Open source Template:Efn
busybox-init Bruce Perens etc.[15][16][17] Template:Wikidata Template:Dts; Template:Time ago Template:Open source Template:Efn
dinit Davin McCall[18] Template:Wikidata Template:Dts; Template:Time ago Template:Open source Template:Efn
Epoch Epoch Contributors[19] 1.3.0 Template:Dts; Template:Time ago Template:Open source Template:Efn
finit Joachim Wiberg, etc.[20] 4.17[20] Template:Dts; Template:Time ago Template:Open source
ginitd S. M. Wood-Mattheusson[21] Template:Efn
Initng Initng Contributors[22] 0.6.10.2 Template:Dts; Template:Time ago Template:Open source[22] Template:Efn
launchd Apple Inc. 10.4 Template:Dts; Template:Time ago Template:Proprietary (was APSL then AL2) Template:Efn
OpenRC Roy Marples[23] etc.[24] Template:Wikidata Template:Dts; Template:Time ago Template:Open source Template:Efn
procd Daniel Golle, etc.[25] Template:Dts; Template:Time ago Template:Open source
runit Gerrit Pape[26] etc.[27] Template:Wikidata Template:Dts; Template:Time ago Template:Open source Template:Efn
s6 Laurent Bercot[28] Template:Wikidata Template:Dts; Template:Time ago Template:Open source Template:Efn
Service Management Facility (SMF) Sun Microsystems 5.10 Template:Dts; Template:Time ago Template:Open source Template:Efn
Shepherd Template:Wikidata[29]etc.[30] Template:Wikidata Template:Dts; Template:Time ago Template:Open source Template:Efn
systemd Red Hat[31]345 in 2018[32]2,032 total[33] Template:Wikidata Template:Dts; Template:Time ago Template:Open source[34] Template:Efn
SystemStarter Wilfredo Sanchez[35] 10.4 Template:Dts; Template:Time ago Template:Open source Template:Efn
Upstart Canonical Ltd. 1.13.2[36] Template:Dts; Template:Time ago Template:Open source Template:Efn
Name Developer Latest release License Notes
Version Date

Template:Reflist

Operating system support

Name Linux BSD Darwin Hurd Solaris Other
BootScripts Template:Yes Template:No Template:No Template:No Template:No Template:No
busybox-init Template:Yes Template:Yes Template:Yes Template:Yes Template:Yes Template:Yes
dinit Template:Yes Template:Yes Template:Yes Template:Yes Template:Yes Template:Yes
Epoch Template:Yes Template:No Template:No Template:No Template:No Template:No
finit Template:Yes Template:No Template:No Template:No Template:No Template:No
Initng Template:Yes Template:Yes Template:No Template:No Template:No Template:Yes
launchd Template:No Template:No Template:Yes Template:No Template:No Template:No
OpenRC Template:Yes Template:Yes Template:No Template:No Template:No Template:No
procd Template:Yes Template:No Template:No Template:No Template:No Template:No
runit Template:Yes Template:Yes Template:Yes Template:Yes Template:Yes Template:Yes
s6 Template:Yes Template:Yes Template:Yes Template:Yes Template:Yes Template:Yes
Service Management Facility (SMF) Template:No Template:No Template:No Template:No Template:Yes Template:No
Shepherd Template:Yes Template:No Template:No Template:Yes Template:No Template:No
systemd Template:Yes Template:No Template:No Template:No Template:No Template:No
SystemStarter Template:No Template:No Template:Yes Template:No Template:No Template:No
Upstart Template:Yes Template:No Template:No Template:No Template:No Template:No
Name Linux BSD Darwin Hurd Solaris Other

Compatibility, interface and programming

Comparison of init systems[37][38]
Name musl
libc
compatible
dependency
free
script/
service
format
Plain
log
format
Per-
service
config
Cross-
service
events
Parallel
service
startup
Process
supervision
Programming language Codebase
size
(lines)
BootScripts Template:? Template:? Template:Yes[14] Template:? Template:? Template:? Template:? Template:? Shell 66.6%; C 19.0%; Python 12.7%; Other 1.7%[14] Template:?
busybox-init Template:? Template:? Template:? Template:? Template:? Template:? Template:? Template:? C 90.4%; shell script 4.6%; C++ 1.7%; HTML 1.4%; Assembly 0.8%; Make 0.5%; XML 0.2%; Perl 0.3%; Python 0.1%[39] Template:No
[39]
dinit Template:Yes Template:Yes Template:Yes Template:Yes Template:Yes Template:Yes Template:Yes Template:Yes C++ 96.1%; Starlark 1.0%; C 1.0%; Shell 0.9%; Makefile 0.7%; Zig 0.2%; Go 0.1%[18] Template:Yes
Epoch Template:Yes Template:Yes Template:Yes Template:Yes Template:Yes
(v1.1+)
Template:Yes Template:No Template:Yes C 98.2%; shell script 1.8%; Make 0.1%[40] Template:Yes[40]
finit Template:? Template:? Template:Yes Template:Yes Template:? Template:? Template:Yes Template:Yes C 86.7%; shell script 9.7%; Automake 1.8%; Autoconf 1.5%; Make 0.3%[41] Template:Yes[41]
Initng Template:? Template:? Template:? Template:? Template:? Template:? Template:? Template:? C 67.5%; Assembly 12.8%; shell script 13.2%; Python 2.7%; CMake 1.5%; Jam 1.1%; HTML 0.6%; Make 0.5%; Vim Script 0.1%[42] Template:Partial[42]
launchd Template:? Template:Yes Template:Yes Template:? Template:Yes Template:No Template:Yes Template:Yes C 96.1%; shell script 2.2%; C++ 1.3%; Make 0.4%; XML 0.1%[43] Template:Yes[43]
OpenRC Template:Yes Template:Yes
(sysv or BSD)
Template:Yes Template:Yes Template:Yes
(conf.d)
Template:Yes Template:Yes Template:Partial C 87.6%; shell script 12.2%; Perl 0.2%[44] Template:Yes[44]
procd Template:? Template:? Template:Yes[45] Template:? Template:Yes[45] Template:? Template:? Template:Yes[46] C 98.8%; CMake 0.8%; shell script 0.4%[47] Template:Yes[47]
runit Template:Yes Template:Yes Template:Yes Template:Yes Template:No Template:Yes Template:Partial Template:Yes C 57.4%; HTML 32.1%; shell script 6.3%; Make 4.0%; XML 0.2%[48] Template:Yes[48]
s6 Template:Yes Template:Yes Template:Yes Template:Yes Template:No Template:Yes Template:Yes Template:Yes C 48.3%; HTML 46.1%; shell script 2.8%; Autoconf 2.0%; Make 0.7%; Emacs Lisp 0.1%[49] Template:Yes[49]
Service Management Facility (SMF) Template:? Template:Yes
(sysv?)
Template:Yes Template:Yes Template:Yes
(service
instances)
Template:Yes Template:Yes Template:Yes C Template:?
Shepherd Template:? Template:? Template:? Template:? Template:? Template:? Template:? Template:? Scheme 70.5%; shell script 28.3%; Automake 0.7%; Autoconf 0.4%[50] Template:Yes[50]
systemd Template:No Template:No Template:Yes Template:No
(journald)
Template:Yes Template:Yes Template:Yes Template:Partial C 77.9%; XML 12.5%; shell script 3.9%; Python 3.2%; C++ 2.4%; CSS 0.1%[51] Template:No
[51]
Upstart Template:? Template:? Template:? Template:? Template:? Template:? Template:? Template:? C 93.1%; Python 2.5%; Automake 1.1%; C++ 2.4%; shell script 0.3%; XML 0.3%; Autoconf 0.1%; Vim Script 0.1%[52] Template:Partial
[52]
Name musl
libc
compatible
dependency
free
script/
service
format
Plain
log
format
Per-
service
config
Cross-
service
events
Parallel
service
startup
Process
supervision
Programming language Codebase
size
(lines)

See also

References

Template:Reflist

Template:Service management in Unix

  1. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  2. ↑ Template:Man
  3. ↑ Template:Man
  4. ↑ Template:Man
  5. ↑ Template:Man
  6. ↑ Template:Man
  7. ↑ Template:Man
  8. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  9. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  10. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  11. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  12. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  13. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  14. ↑ 14.0 14.1 14.2 {{#invoke:citation/CS1|citation |CitationClass=web }}
  15. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  16. ↑ Active Projects Template:Webarchive, Rob Landley's website
  17. ↑ Denys Vlasenko Template:Webarchive, BusyBox maintainer
  18. ↑ 18.0 18.1 Cite error: Invalid <ref> tag; no text was provided for refs named dinit
  19. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  20. ↑ 20.0 20.1 {{#invoke:citation/CS1|citation |CitationClass=web }}
  21. ↑ Cite error: Invalid <ref> tag; no text was provided for refs named ginitd
  22. ↑ 22.0 22.1 {{#invoke:citation/CS1|citation |CitationClass=web }}
  23. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  24. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  25. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  26. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  27. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  28. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  29. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  30. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  31. ↑ Template:Citation
  32. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  33. ↑ Used the "contributors" statistic from: Template:Citation
  34. ↑ Template:Citation
  35. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  36. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  37. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  38. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  39. ↑ 39.0 39.1 {{#invoke:citation/CS1|citation |CitationClass=web }}
  40. ↑ 40.0 40.1 {{#invoke:citation/CS1|citation |CitationClass=web }}
  41. ↑ 41.0 41.1 {{#invoke:citation/CS1|citation |CitationClass=web }}
  42. ↑ 42.0 42.1 {{#invoke:citation/CS1|citation |CitationClass=web }}
  43. ↑ 43.0 43.1 {{#invoke:citation/CS1|citation |CitationClass=web }}
  44. ↑ 44.0 44.1 {{#invoke:citation/CS1|citation |CitationClass=web }}
  45. ↑ 45.0 45.1 {{#invoke:citation/CS1|citation |CitationClass=web }}
  46. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  47. ↑ 47.0 47.1 {{#invoke:citation/CS1|citation |CitationClass=web }}
  48. ↑ 48.0 48.1 {{#invoke:citation/CS1|citation |CitationClass=web }}
  49. ↑ 49.0 49.1 {{#invoke:citation/CS1|citation |CitationClass=web }}
  50. ↑ 50.0 50.1 {{#invoke:citation/CS1|citation |CitationClass=web }}
  51. ↑ 51.0 51.1 {{#invoke:citation/CS1|citation |CitationClass=web }}
  52. ↑ 52.0 52.1 {{#invoke:citation/CS1|citation |CitationClass=web }}