Init
In Unix-based computer operating systems, init is the first process started during booting of the computer 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; a kernel panic will occur if the kernel is unable to start it. Init is typically assigned process identifier 1.
In Unix systems such as System III and System V, the design of init has diverged from the functionality provided by the init in Research Unix and its BSD derivatives. Up until recently, most Linux distributions employed a traditional init that is somewhat compatible with System V, while some distributions such as Slackware use BSD-style startup scripts, and others such as Gentoo have their own customized versions.
Since then, several additional init implementations have been created, attempting to address design limitations in the traditional versions. These include launchd, the Service Management Facility, systemd, Runit and OpenRC.
Research Unix-style/BSD-style
init ran the initialization shell script located at/etc/rc
, then launched getty on terminals under the control of /etc/ttys
. 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; in 4.3BSD, it added support for running a windowing system such as X on graphical terminals under the control of
/etc/ttys
. 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 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. The order in which scripts are executed is determined by the rcorder script based on the requirements stated in these tags.SysV-style
When compared to its predecessors, AT&T's UNIX System III introduced a new style of system startup configuration, which survived 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, 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
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: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
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. 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. 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 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:
- BootScripts in GoboLinux
- busybox-init, suited to embedded operating systems, employed by OpenWrt before it was replaced with procd
- Daemons, by a modification of the init start process by KahelOS, daemons are started only when the DE started
- eINIT, a full replacement of init designed to start processes asynchronously, but with the potential of doing it without shell scripts
- Epoch, a single-threaded Linux init system focused on simplicity and service management
- Initng, a full replacement of init designed to start processes asynchronously
- launchd, a replacement for init in Darwin/macOS/iOS/tvOS starting with Mac OS X v10.4
- , an init replacement written in Python and designed to start process asynchronously in use by the Pardus Linux distribution
- is used in LEDE/OpenWRT
- based on Make
- nosh, a suite of system-level utilities for initializing and running a BSD or Linux system, for managing daemons, terminals and logging
- OpenRC, a process spawner that utilizes system-provided init, while providing process isolation, parallelized startup, and service dependency; used by Gentoo and its derivatives and available as an option in Devuan
- runit, a cross-platform full replacement for init with parallel starting of services, used by default in Void Linux.
- s6, another cross-platform full replacement for init, similar to runit, based on clear principled architecture design choices.
- Sun Service Management Facility, a complete replacement/redesign of init from the ground up in illumos/Solaris starting with Solaris 10, but launched as the only service by the original System V-style init
- Shepherd, the GNU service and daemon manager which provides asynchronous, dependency-based initialisation; written in Guile Scheme and meant to be interactively hackable during normal system operation
- systemd, a software suite, full replacement for init in Linux that includes an init daemon, with concurrent starting of services, service manager, and other features.
- SystemStarter, a process spawner started by the BSD-style init in Mac OS X prior to Mac OS X v10.4
- Upstart, a full replacement of init designed to start processes asynchronously. Initiated by Ubuntu and used by them until 2014. It was also used in Fedora 9, Red Hat Enterprise Linux 6 and Google's Chrome OS.