Previous Section
 < Day Day Up > 
Next Section

System Runlevels: telinit, initab, and shutdown

A Linux system can run in different levels, depending on the capabilities you want to give it. For example, you can run your system at an administrative level, locking out user access. Normal full operations are activated by simply running your system at a certain level of operational capability such as supporting multiuser access or graphical interfaces. These levels (also known as states or modes) are referred to as runlevels, the level of support that you are running your system at.


A Linux system has several runlevels, numbered from 0 to 6. When you power up your system, you enter the default runlevel. Runlevels 0, 1, and 6 are special runlevels that perform specific functions. Runlevel 0 is the power-down state and is invoked by the halt command to shut down the system. Runlevel 6 is the reboot state—it shuts down the system and reboots. Runlevel 1 is the single-user state, which allows access only to the superuser and does not run any network services. This enables you, as the administrator, to perform administrative actions without interference from others.

Other runlevels reflect how you want the system to be used. Runlevel 2 is a partial multiuser state, allowing access by multiple users, but without network services like NFS or xinetd (eXtended InterNET services daemon). This level is useful for a system that is not part of a network. Both runlevel 3 and runlevel 5 run a fully operational Linux system, with multiuser support and remote file sharing access. They differ in terms of the interface they use. Runlevel 3 starts up your system with the command line interface (also known as the text mode interface). Runlevel 5 starts up your system with an X session, running the X Window System server and invoking a graphical login, using display managers, such as gdm or xdm. If you choose to use graphical logins during installation, runlevel 5 will be your default runlevel. Linux provides two keyboard sequences to let you switch between the two during a login session: CTRL-ALT-F1 changes from the graphical interface (runlevel 5) to the command line interface (runlevel 3), and CTRL-ALT-F7 changes from the command line interface to the graphical interface. The runlevels are listed in Table 27-3.

Changing runlevels can be helpful if you have problems at a particular runlevel. For example, if your video card is not installed properly, then any attempt to start up in runlevel 5 will likely fail, as this level immediately starts your graphical interface. Instead, you should use the command line interface, runlevel 3, to fix your video card installation.


You can use the single-user runlevel (1) as a recovery mode state, allowing you to start up your system without running startup scripts for services like DNS. This is helpful if your system hangs when you try to start such services. Networking is disabled, as well as any multiuser access. You can also use linux –s at the boot prompt to enter runlevel 1. If you want to enter the single-user state and also run the startup scripts, you can use the special s or S runlevels.

Table 27-3: System Runlevels (States)



System Runlevels (states)



Halt (do not set the default to this level); shuts down the system completely.


Administrative single-user mode; denies other users access to the system, but allows root access to the entire multiuser file system. Startup scripts are not run. (Use s or S to enter single-user mode and have startup scripts run.)


Multiuser, without network services like NFS, xinetd, and NIS (the same as 3, but you do not have networking).


Full multiuser mode with login to command-line interface; allows remote file sharing with other systems on your network. Also referred to as the text mode state.




Full multiuser mode that starts up in an X session, initiating a graphical login; allows remote file sharing with other systems on your network (same as 3, but with graphical login).


Reboots; shuts down and restarts the system (do not set the default to this).

initab Runlevels

When your system starts up, it uses the default runlevel as specified in the default init entry in the /etc/inittab file. For example, if your default init runlevel is 5 (the graphical login), the default init entry in the /etc/inittab file would be


You can change the default runlevel by editing the /etc/inittab file and changing the init default entry. Editing the /etc/inittab file can be dangerous. You should do this with great care. As an example, if the default runlevel is 3 (command line), the entry for your default runlevel in the /etc/inittab file should look like the following:


You can change the 3 to a 5, to change your default runlevel from the command line interface (3) to the graphical login (5). Change only this number and nothing else.


If your /etc/inittab file becomes corrupted, you can reboot and enter linux single at the boot prompt to start up your system, bypassing the inittab file. You can then edit the file to fix it.

Changing Runlevels with telinit

No matter what runlevel you start in, you can change from one runlevel to another with the telinit command. If your default runlevel is 3, you power up in runlevel 3, but you can change to, say, runlevel 5 with telinit 5. The command telinit 0 shuts down your system. In the next example, the telinit command changes to runlevel 1, the administrative state:

# telinit 1

telinit is really a symbolic link (another name for a command) to the init command. The init command performs that actual startup operations and is automatically invoked when your system starts up. Though you could use init to change runlevels, it is best to use telinit. When invoked as telinit, init merely changes runlevels.

runlevel Command

Use the runlevel command to see what state you are currently running in. It lists the previous state followed by the current one. If you have not changed states, the previous state will be listed as N, indicating no previous state. This is the case for the state you boot up in. In the next example, the system is running in state 3, with no previous state change.

# runlevel
N 3


Although you can power down the system with the telinit command and the 0 state, you can also use the shutdown command. The shutdown command has a time argument that gives users on the system a warning before you power down. You can specify an exact time to shut down, or a period of minutes from the current time. The exact time is specified by hh:mm for the hour and minutes. The period of time is indicated by a + and the number of minutes. The shutdown command takes several options with which you can specify how you want your system shut down. The -h option, which stands for halt, simply shuts down the system, whereas the -r option shuts down the system and then reboots it. In the next example, the system is shut down after ten minutes.

# shutdown -h +10

To shut down the system immediately, you can use +0 or the word now. The following example shuts down the system immediately, and then reboots.

# shutdown -r now

With the shutdown command, you can include a warning message to be sent to all users currently logged in, giving them time to finish what they are doing before you shut them down.

# shutdown -h +5 "System needs a rest"

If you do not specify either the -h or the -r options, the shutdown command shuts down the multiuser mode and shifts you to an administrative single-user mode. In effect, your system state changes from 3 (multiuser state) to 1 (administrative single-user state). Only the root user is active, allowing the root user to perform any necessary system administrative operations with which other users might interfere.


You can also shut down your system from the GNOME or KDE desktops.

The shutdown options are listed in Table 27-4.

Table 27-4: System Shutdown Options



shutdown [-rkhncft] time [warning-message]

Shuts the system down after the specified time period, issuing warnings to users; you can specify a warning message of your own after the time argument; if neither -h nor -r is specified to shut down the system, the system sets to the administrative mode, runlevel state 1.




Has two possible formats: it can be an absolute time in the format hh:mm, with hh as the hour (one or two digits) and mm as the minute (in two digits); it can also be in the format +m, with m as the number of minutes to wait; the word now is an alias for +0.



-t sec

Tells init to wait sec seconds between sending processes the warning and the kill signals, before changing to another runlevel.


Doesn't actually shut down; only sends the warning messages to everybody.


Reboots after shutdown, runlevel state 6.


Halts after shutdown, runlevel state 0.


Doesn't call init to do the shutdown; you do it yourself.


Skips file system checking (fsck) on reboot


Cancels an already running shutdown; no time argument.

Previous Section
 < Day Day Up > 
Next Section
This HTML Help has been published using the chm2web software.