Linux runlevels and boot process

I always see lots of directories in /etc/rc.d/ like rc.0, rc.1, rc.2, rc.3, rc.4, rc.5, and rc.6. Once I tried to find out what are all these. Then I came to know these are runlevels. Then the question came how do they get triggered and whats the difference between these runlevels. Here is what I found :

When you turn on the system following things happens :

1. Boot loader finds the kernel image from disk and loads it in to memory.

2. Kernel initializes the devices and its drivers

3. Kernel mounts the root file system

4. Kernel starts a program called init.

5. init start all the rest processes.

init

There is nothing special about init. It is a program just like any other on the Linux system, and you’ll find it in /sbin along with other system binaries. The main purpose of init is to start and stop other programs in a particular sequence. All you have to know is how this sequence works.

Most linux system are System V (derived from AT&T System V) based . Another is based on BSD (Berkeley Software Distribution). What’s the difference between the two? Basically BSD doesn’t have any runlevels. This means that System V are more flexible

Most Linux distros put startup scripts in the rc subdirectories (rc1.d, rc2.d, etc.), whereas BSD systems house the system scripts in /etc/rc.d. Slackware’s init setup is similar to BSD systems, though Slackware does have runlevels and has had System V compatibility since Slackware 7.

Runlevels :

At any given time on a Linux system, a certain base set of processes is running. This state of the machine is called its runlevel, and it is denoted with a number from 0 through 6. The system spends most of its time in a single runlevel.
You will also find a file named /etc/inittab. The system uses these files (and/or directories) to control the services to be started. If you look in the file /etc/inittab you will see something like:

id:5:initdefault:

l0:0:wait:/etc/rc.d/rc.0

l6:6:wait:/etc/rc.d/rc.6

x1:4:wait:/etc/rc.d/rc.4

First line means that the default runlevel on the system is 5. All lines in the inittab file take this form, with four fields separated by colons occurring in the following order:

  • A unique identifier (a short string, such as id in the preceding example)
  • The applicable runlevel number(s)
  • The action that init should take (in the preceding example, the action is to set the default runlevel to 5)
  • A command to execute (optional)
  • Run Level Generic Linux/Fedora Core Slackware Debian
    0 Halt Halt Halt Halt
    1 Single-user mode Single-user mode Single-user mode Single-user mode
    2 Basic multi-user mode (without networking) User definable (Unused) User definable - configured the same as runlevel 3 Multi-user mode
    3 Full (text based) multi-user mode Multi-user mode Multi-user mode - default Slackware runlevel
    4 Not used Not used X11 with KDM/GDM/XDM (session managers) Multi-user mode
    5 Full (GUI based) multi-user mode Full multi-user mode (with an X-based login screen) - default runlevel User definable - configured the same as runlevel 3 Multi-user mode
    6 Reboot Reboot Reboot Reboot

    Leave a Comment

    "Quote of the Day"