Init
1551363
226096007
2008-07-16T20:23:17Z
Wolfgang Oertl
6849313
/* Other styles */
{{lowercase|title=init}}
{{Mergewith|Runlevel|date=August 2007}}
'''init''' (short for "[[initialization]]") is the program on [[Unix]] and [[Unix-like]] systems that [[wikt:spawns|spawns]] all other processes. It runs as a [[daemon (computer software)|daemon]] and typically has [[process identifier|PID]] 1.
The functionality diverged, in Unixes such as [[Unix System III|System III]] and [[UNIX System V|System V]], from the functionality provided by the init in [[Research Unix]] and its [[Berkeley Software Distribution|BSD]] derivatives. The usage on most [[Linux distribution]]s is compatible with System V, but some distributions, such as [[Arch Linux]] and [[Slackware]], use a BSD-style and others, such as [[Gentoo Linux]], have their own customized version.
==BSD-style==
BSD init runs the initialization [[shell script]] located in <nowiki>'/etc/rc'</nowiki>, then launches [[getty (Unix)|getty]] on text-based terminals or a [[windowing system]] such as [[X Window System|X]] on graphical terminals. There are no runlevels; the <nowiki>'rc'</nowiki> file determines how init is to be run.
''Advantages:'' Simple and easy to edit manually.
''Problems:'' If a 3rd-party package needs to have an initialization script run during the boot procedure, it needs to edit one of the existing boot scripts, but a simple mistake in that process could lead to an unbootable system.
Note that modern [[*BSD]] variants have long supported a site-specific <nowiki>'rc.local'</nowiki> file that is run in a sub-shell near the end of the boot sequence to mitigate the risks of making the system unbootable, and later, a local <nowiki>'rc.d'</nowiki> directory where packages could install their own independent start/stop scripts (usually provided by the [[ports collection]]/[[pkgsrc]]). [[FreeBSD]] and [[NetBSD]] now use by default (as of version 5.0 and 1.5, respectively) the '''rc.d''' framework where the whole userland boot sequence is fragmented into smaller scripts, similarly to SysV. '''rcorder''' is used to determine in which order scripts are run, based on dependency information contained in the '''rc.d''' scripts.
==SysV-style==
System V init examines the <nowiki>'/etc/inittab'</nowiki> file for an <nowiki>'initdefault'</nowiki> 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.
''Advantages:'' Flexibility and scalability.
''Problems:'' Complexity.
===Runlevels===
The [[runlevel]]s in [[UNIX System V|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 <tt>/etc/inittab</tt> file, which defines what each runlevel does (if they do anything at all).
===Default runlevels===
{| class="wikitable"
! OS
! Default runlevel
|-
| [[AIX operating system|AIX]]
| 2
|-
| [[Debian GNU/Linux]]
| 2 [http://www.debianadmin.com/debian-and-ubuntu-linux-run-levels.html]
|-
| [[Gentoo Linux]]
| 3
|-
| [[Mandriva Linux]]
| 5
|-
| [[Red Hat Linux]] / [[Fedora Core]]
| 3 or 5
|-
| [[Slackware Linux]]
| 3
|-
| [[Solaris Operating System|Solaris]]
| 3 [http://docs.sun.com/app/docs/doc/817-1985/6mhm8o5ru]
|-
| [[SUSE Linux]]
| 5 [http://www.novell.com/documentation/sles10/pdfdoc/sles_admin/sles_admin.pdf] (Page 377)
|-
| [[Ubuntu (operating system)|Ubuntu (Server and Desktop)]]
| 2 [http://www.debianadmin.com/debian-and-ubuntu-linux-run-levels.html]
|}
On the two 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|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 [[superuser|root]] running the <tt>telinit</tt> or <tt>init</tt> commands. The default runlevel is set in the <tt>/etc/inittab</tt> file with the <tt>:initdefault:</tt> entry.
==Skipping init==
In Linux systems, with most modern [[bootloader]]s (such as [[LILO (boot loader)|LILO]] or [[GRUB]]), users can change which process the kernel spawns at the end of its initialization from the normal default of <code>/sbin/init</code>. This is generally done by typing <code>init=[[foobar|/foo/bar]]</code> at the bootloader's prompt. Appending <code>init=/bin/bash</code>, for example, will bring up a single root shell, without a password.
For BSD variants, on most platforms, the bootstrap program can be interrupted and given the <code>boot -s</code> command to boot into single-user mode. Single-user mode does not technically skip init; it still executes <code>/sbin/init</code>, but it will make init ask for the path to a program to <code>exec()</code> (the default being <code>/bin/sh</code>) instead of doing the regular multi-user boot sequence. If the [[tty]] the kernel was booted from was marked as "insecure" in the <code>/etc/ttys</code> file (on some systems, the current "securelevel" might also matter), init will first ask for the [[superuser|root]] password before allowing this (or fallback to multi-user mode if the user hits <code>CTRL+D</code>). If this program is exited, the kernel will restart init in multi-user mode. The same things will happen if the system is switched from multi-user to single-mode while running. If init cannot be started after the kernel booted, it will panic and the system will be unusable. Changing the path to init itself is done differently on different variants (<code>boot -a</code> on NetBSD, the <code>init_path</code> loader variable on FreeBSD).
==Other styles==
Various efforts have been made to replace the traditional init daemons with something better. Below is a list of these alternatives in no particular order.
*[[SystemStarter]], superceeded by [[launchd]] — [[Apple Computer|Apple]] [[Mac OS X]]'s process spawner
*[[Initng]], a full replacement of init designed to start processes [[asynchronous]]ly
*[[Upstart]], a full replacement of init designed to start processes [[asynchronous]]ly initiated by [[Ubuntu (operating system)|Ubuntu]]
*[[Service Management Facility]], a complete full replacement/redesign of init from the ground up in [[Solaris Operating System|Solaris]] starting with Solaris 10
*runit, a cross platform full replacement for init with parallel starting of services
*[[GoboLinux#Boot_system | BootScripts]] in [[GoboLinux]]
The following list are links to projects that are not (yet) in widespread use.
*[[Einit|eINIT]], a full replacement of init designed to start processes [[asynchronous]]ly, but with the potential of doing it without shell-scripts
*''svscan'' from [[daemontools]] used as process 1 - seems to be superceded by runit
*cinit
*twsinit, partly written in x86 assembler, more a proof of concept
*minit
==See also==
*[[pidof]] or killall5, another program from the System V set used in many distributions
==External links==
*[http://unixhelp.ed.ac.uk/CGI/man-cgi?init+8 man pages for init]
*[http://www.freebsd.org/cgi/man.cgi?query=init&apropos=0&sektion=0&manpath=FreeBSD+6.2-stable&format=html FreeBSD init man page]
*[http://www.atnf.csiro.au/people/rgooch/linux/boot-scripts/ boot-scripts]
*[http://smarden.org/runit/index.html runit]
*[http://www.fefe.de/minit/ minit]
*[http://www.netbsd.org/guide/en/chap-rc.html rc.d]
*[http://www.busybox.net/downloads/BusyBox.html#item_init busybox]
*[http://www.sun.com/bigadmin/content/selfheal/smf-quickstart.html smf and milestones in Solaris 10]
*[http://linux.schottelius.org/cinit/ cinit]
*[http://www.energymech.net/users/proton/ twsinit]
[[Category:Unix]]
[[Category:Process (computing)]]
[[de:Init]]
[[es:Init]]
[[eu:Init]]
[[fr:Init]]
[[it:Init]]
[[ja:Init]]
[[pt:Init]]
[[ru:Init]]
[[fi:Init]]