init

init (short for initialization) is a program for Unix-based computer operating systems that spawns all other processes. It runs as a daemon and typically has PID 1. The boot loader starts the kernel and the kernel starts init. If one were to delete init without a replacement, the system would encounter a kernel panic on the next reboot.

The functionality diverged, in Unix systems such as System III and System V, from the functionality provided by the init in Research Unix and its BSD derivatives. The usage on most Linux distributions is compatible with System V, but some distributions, such as Arch, use a BSD-style and others, such as Gentoo, have their own customized version.

Several replacements for init have been written which attempt to address design limitations such as systemd or Upstart, used by Ubuntu[1][2] and some other Linux distributions.[3][4]

Contents

SysV-style

System V init examines the /etc/inittab file for an :initdefault: entry, which tells init whether there is a default runlevel. If there is no default runlevel, then the user is dumped to a system console, where a runlevel must be entered manually.

Runlevels

The runlevels in System V describe certain states of a machine, characterized by the processes run. There are generally 8 runlevels. These are the runlevels 0 to 6 and S or s, which are aliased to the same runlevel. Of these eight, 3 are so-called "reserved" runlevels:

0. Halt
1. Single user mode
6. Reboot

Aside from runlevels 0, 1, and 6, every Unix and Unix-like system treats runlevels a little differently. The common denominator is the /etc/inittab file, which defines what each runlevel does (if they do anything at all).

Default runlevels

Operating System Default runlevel
AIX 2
Arch Linux 3
CentOS 3 or 5
Debian 2[5]
Gentoo Linux 3[6]
HP-UX 3
Mac OS X 3
Mandriva Linux 5
Red Hat Linux / Fedora Core 3 or 5
Slackware Linux 3
Solaris 3[7]
SUSE Linux 5[8]
Ubuntu (Server and Desktop) 2[5]

On the Linux distributions defaulting to runlevel 5 in the table above, runlevel 5 is a multiuser graphical environment running the X Window System, usually with a display manager. However, in the Solaris operating system, runlevel 5 is typically reserved to shut down and automatically power off the machine.

On most systems users can check the current runlevel with either of the following commands:

$ runlevel
$ who -r

The current runlevel is typically changed by root running the telinit or init commands. The default runlevel is set in the /etc/inittab file with the :initdefault: entry.

BSD-style

BSD init runs the initialization shell script located in /etc/rc, then launches getty on text-based terminals or a windowing system such as X on graphical 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. To mitigate against this, 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.[9] The order in which scripts are executed is determined by the rcorder script based on the requirements stated in these tags.

Replacements for init

Various efforts have been made to replace the traditional init daemons with something better, including:

See also

References

External links