Many Unix-like systems — particularly those that follow the SysV model — make use of the concept of the runlevel. On these systems, runlevels are different modes of operation, some of which can be customized by the system administrator.
In the Linux world, the typical assignment of functionality to runlevels is:
- 0: system halted
- 1: single user mode
- 2: single user mode with networking
- 3: text-only multi-user mode
- 4-5: multi-user modes
- 6: restart
Switching runlevels is simple from the command line. The
init command takes a number as an argument that can be used to switch runlevels.
The actual init daemon starts when the system starts, and manages process startup and shutdown for the current runlevel. When you use the
init command within a root user shell, it executes
telinit, however. The telinit program can be used to switch to the runlevel corresponding to the numeric argument given to the
init command. This means that the command
init 0 will shut down the system,
init 1 will shut down processes and enter single user mode, and
init 6 will restart the system.
Three non-numeric arguments can also be used.
- The letter
qrequests that init reload its configuration. It is largely unnecessary in many current Linux-based operating system configurations.
- The letter
s, can be used to enter single user mode as well. Care should be taken when doing so, however;
init sdoes not shut down current processes the way
- The letter
urequests that init re-execute itself.
For the most part, numeric values will be the only arguments you will need to give the
init command (and, by extension, the
telinit command). In fact, most often you would not need anything but
init 0 or
init 6, with an occasional need to use
init 1. It is typical for Linux-based systems to be set up to automatically boot into the appropriate runlevel for normal operation.
Configuration of which processes are started and stopped with a given runlevel is primarily handled by the contents of
/etc/rcN.d directories. Within these directories, symlinks to scripts in the
/etc/init.d directory indicate which processes should be started or stopped when entering or leaving a given runlevel.
BSD Unix init
The BSD Unix
init command serves a similar role, but it does not use the SysV init system. On BSD Unix systems, init is actually a utility that executes the rc utility. In some ways much like SysV init, BSD rc manages startup of processes on boot. The
init command is used with a somewhat different set of arguments, however, because it does not use SysV runlevels:
init 0: shut down the system
init 1: enter single user mode
init 6: restart the system
init c: block further logins
init q: rescan the
q option serves a purpose similar to the same argument to the Linux/SysV version of the
Configuration of the rc system can vary across systems that use it. In the case of FreeBSD, most relevant configuration is handled by the
/etc/rc.conf file, and by rc scripts in the
/etc/rc.d directory. See the rc.conf manpage for details.
Many Unix-like systems provide a
shutdown command that performs much the same purpose as certain
init commands, and typically adds some convenient features such as sending warnings to user shells, delaying change of operating mode for a specified period of time or at a particular time of day, and kicking all users out of their logins and preventing all new logins. The
shutdown command varies from system to system, and its manpage should be consulted for specifics on a given Unix-like OS.
This is not a comprehensive guide.
Obviously, an in-depth, comprehensive survey and explanation of the entire system related to the
init command is beyond the scope of a single article. With a little bit of enthusiasm and time, however, a lot can be learned about how to manage system operation modes via commands like
shutdown, and to configure the underlying system, from manpages.
Chad Perrin is an IT consultant, developer, and freelance professional writer. He holds both Microsoft and CompTIA certifications and is a graduate of two IT industry trade schools.