Linux run levels explained
search cancel

Linux run levels explained

book

Article ID: 179829

calendar_today

Updated On:

Products

IT Management Suite

Issue/Introduction

Linux run levels explained

Environment

ITMS 8.x

Resolution

Question

Can you explain to me Linux run levels?

Answer
 

The following information was written by Joshua Erdman of Digital Foundation

Linux Run-Levels

Linux has 6 different run levels (or operating modes):

0 - Shutdown the system in orderly manner
1 - rc1.d - Single User Mode
2 - rc2.d - Single User Mode with Networking
3 - rc3.d - Multi-User Mode - boot up in text mode
4 - rc4.d - Not yet Defined
5 - rc5.d - Multi-User Mode - boot up in X Windows
6 - rc6.d - Reboot

Each mode has its own list of settings for what services to start and what services to shutdown. Not only does this list contain what is supposed to be running, but also what order each service should be started in.

chkconfig - will list all the registered services and display thier status at each different run level.

Most of the time when your server boots up it will start in runlevel 3 or 5 depending on what it is set to. This setting can be found in the file /etc/inittab

If you ever want to change what mode your server defaults to on bootup, just edit that file, but NEVER change it to runlevel 6 or else you will set your server to shutdown on bootup.

RC.D Directory Explanation

In the folder: /etc/rc.d are all the run level folders starting from rc1.d to rc6.d and including init.d

It is in each of these rc#.d folders where the service run settings are kept. If you change directory into /etc/rc.d/rc3.d all the files that start with a capital S are the services that will start at this runlevel. All the files that start with a K are the services that will be killed at that runlevel.

The reason why services that are not supposed to run are still listed is because it is popular to switch a server from one run level to another instead of just booting into the needed run level. That way you can take your server offline (single user mode) and then apply a patch or do a file restore.

Let's take a closer look at these files that are inside the rc#.d folders. Notice that they are symbolic links to the script file located in /etc/rc.d/init.d This makes things very easy. All the commands to start, stop, or reload a service are handled by these scripts. So when a server is to go into a specific run level it can find the correct script and knows whether to start it based on its name and link path.

Switching Run Levels

   init <Run Level number>

The original source of this article can be found at http://www.networkclue.com/os/Linux/run-levels.aspx.