Understanding Run Levels



Run levels define the services to be run by Linux. Each run level provides a different set of services which correspond to various user level capabilities. Some run levels are not used and others provide special functions.

There are seven defined run levels in Linux, run level 0 through run level 6. This goes back to the days of Unix at the old AT&T (before the original breakup) when telephone switches had seven run levels; it was thought that a Unix system should have the same number of run levels. Up to ten run levels are supported by Linux but run levels seven through nine have not been defined by any of the mainstream distributions and are typically not used.

Start Scripts

Each run level uses scripts called start scripts to start and stop services for that run level. These scripts are located in the /etc/init.d directory which is a symbolic link to /etc/rc.d/init.d. Each script should recognize at least three basic parameters, start, stop and restart. They may also recognize other parameters such as condrestart (conditional restart), status, setup and others.

These start scripts are based on the Unix System V start scripts and so may be called System V start scripts.

Each run level has a directory, /etc/rc.d/rcX.d, where X is the number of the run level. Symbolic links in each run level directory link to the scripts in the /etc/rc.d/init.d directory. Each link is named with “K” or “S,” for Kill or Start, and a number which specifies the order in which the scripts are to be run.

For example, a sample listing of the start scripts for run level three looks like that below.

K01dnsmasq -> ../init.d/dnsmasq
K01smartd -> ../init.d/smartd
K01smolt -> ../init.d/smolt
K10psacct -> ../init.d/psacct
K10saslauthd -> ../init.d/saslauthd
K10wine -> ../init.d/wine
K10zvbid -> ../init.d/zvbid
K15httpd -> ../init.d/httpd
K19ntop -> ../init.d/ntop
K20nfs -> ../init.d/nfs
K24irda -> ../init.d/irda
K36mysqld -> ../init.d/mysqld
K50netconsole -> ../init.d/netconsole
K50snmpd -> ../init.d/snmpd
K50snmptrapd -> ../init.d/snmptrapd
K66gpsd -> ../init.d/gpsd
K69rpcsvcgssd -> ../init.d/rpcsvcgssd
K73winbind -> ../init.d/winbind
K73ypbind -> ../init.d/ypbind
K74pcscd -> ../init.d/pcscd
K75netfs -> ../init.d/netfs
K75ntpdate -> ../init.d/ntpdate
K76openvpn -> ../init.d/openvpn
K83bluetooth -> ../init.d/bluetooth
K83nfslock -> ../init.d/nfslock
K83rpcgssd -> ../init.d/rpcgssd
K83rpcidmapd -> ../init.d/rpcidmapd
K84btseed -> ../init.d/btseed
K84bttrack -> ../init.d/bttrack
K84NetworkManager -> ../init.d/NetworkManager
K84wpa_supplicant -> ../init.d/wpa_supplicant
K85racoon -> ../init.d/racoon
K87multipathd -> ../init.d/multipathd
K87restorecond -> ../init.d/restorecond
K87rpcbind -> ../init.d/rpcbind
K89netplugd -> ../init.d/netplugd
K89rdisc -> ../init.d/rdisc
K92ip6tables -> ../init.d/ip6tables
K95firstboot -> ../init.d/firstboot
S01sysstat -> ../init.d/sysstat
S06cpuspeed -> ../init.d/cpuspeed
S08iptables -> ../init.d/iptables
S10network -> ../init.d/network
S11auditd -> ../init.d/auditd
S11portreserve -> ../init.d/portreserve
S12rsyslog -> ../init.d/rsyslog
S13irqbalance -> ../init.d/irqbalance
S15mdmonitor -> ../init.d/mdmonitor
S22messagebus -> ../init.d/messagebus
S24avahi-daemon -> ../init.d/avahi-daemon
S25cups -> ../init.d/cups
S26acpid -> ../init.d/acpid
S26haldaemon -> ../init.d/haldaemon
S26lm_sensors -> ../init.d/lm_sensors
S26udev-post -> ../init.d/udev-post
S30vboxdrv -> ../init.d/vboxdrv
S55sshd -> ../init.d/sshd
S58ntpd -> ../init.d/ntpd
S60apcupsd -> ../init.d/apcupsd
S80sendmail -> ../init.d/sendmail
S85gpm -> ../init.d/gpm
S90crond -> ../init.d/crond
S90xfs -> ../init.d/xfs
S95atd -> ../init.d/atd
S99local -> ../rc.local

Note: The above listing is for one of my Fedora computers and will most certainly be different from the listing for yours.

When entering a new run level, either at boot time or by using the init or telinit commands to change run levels, the kill scripts are run first and then the start scripts are run for that level. The Kill scripts are run first and then the Start scripts are run. The numbers after the “K” or “S” in the link name help to determine order in which the scripts are run. When two scripts share the same number, the rest of the name is used to determine the sequence which is alphabetic.

The sequence of starting and stopping scripts is very important. For example you want to ensure that the firewall (IPTables) is started before the network, and stopped after the network in order to maintain security.

Run Level Descriptions

Each run level has a specific purpose in Linux. Table 1, below, describes each run level.

Table 1: Linux Run Levels
Run Level Description
0 Run level 0 is “shutdown.” This shuts down Linux and powers off the computer.
S or s This is called single user mode, but the difference between this and run level 1 is that no start scripts are run when entering this level. This is not truly a run level.
1 Also known as single user mode but is more accurately referred to as run level 1. This mode is used when the system administrator needs to perform maintenance activities that require no other users be logged in. The scripts in /etc/init.d/rc1.d are run when entering this run level.
2 This run level brings Linux to a fully functioning state with the exception that NFS is not active, so NFS file systems will not be mounted.
3 Run level 3 tends to be the standard runlevel for text mode operation. It includes NFS functionality.
4 Not used.
5 Run level 5 is the same as run level 3, but with the GUI, X Window System, running.
6 Reboot. Entering this run level reboots Linux.

Changing Run Levels

The run level can be changed by using either the init or telinit commands. If Linux is currently running in run level 5 and you want to change to run level 3, issue the command init 3 or telinit 3. You can also set the “initdefault” parameter in /etc/inittab to whatever runlevel you want your computer to enter each time it boots.

You should never set the default run level in the inittab file to either run level 0 or run level 6. Your computer would either shut down every time you tried to start it or continuously reboot.