Be free…. be yourself with Linux.

Runlevels in Ubuntu

If you have a script and you it run automatically during loading process then you have to know to runlevels process in Ubuntu. At first time you learn about runlevels, you may find yourself in a bit hard time to figure out how it work. There are so many articles explain about runlevels in the internet. I’ll try to explain the runlevels process in a easy way.

Hopefully, the way I describe the process will be clear enough for you to get a picture about runlevels.

Introduction

Runlevel is a mode of operation or level of run in a computer that uses Unix/Linux System V-style.

There 7 runlevels in Ubuntu, start from 0 to 6.

The following table summarizes it:

runlevel 0 = System Halt

runlevel 1 = Single User

runlevel 2 = Multi-user with GUI

runlevel 3 = Multi-user with GUI

runlevel 4 = Multi-user with GUI

runlevel 5 = runlevel 3 + X windows system

runlevel 6 = Reboot

Runlevel 1 is a single user mode. In this level, there are no daemons (services) are started. You can do rescue or trouble-shooting in this mode. Runlevel 0 for shutdown and runlevel 6 for reboot. The rest are used for running the system.

Like other Linux systems, run levels are defined by files in the file system.

All run level files are found in the /etc directory.

/etc/rc0.d/ runlevel 0

/etc/rc1.d/ runlevel 1

/etc/rc2.d/ runlevel 2

/etc/rc3.d/ runlevel 3

/etc/rc4.d/ runlevel 4

/etc/rc5.d/ runlevel 5

/etc/rc6.d/ runlevel 6

The contents of each directory determines what happens at that run level.

Check your current runlevel

taufanlubis@zyrex:~$ runlevel

N 2

taufanlubis@zyrex:~$

Ubuntu system come with id=2, which indicates that the default runlevel will be ‘2’ when the multi-user state is entered, and the scripts in /etc/rc2.d/ will be run.

taufanlubis@zyrex:~$ who -r

run-level 2 2007-09-25 03:53 last=

taufanlubis@zyrex:~$

Note, taken from update-rc.d manual:

/etc/init.d/

The directory containing the actual init scripts.

/etc/rc?.d/

The directories containing the links used by init and managed by update-rc.d.

There is also another runlevel named runlevel ‘S’.

For more details, you can read the manual.

taufanlubis@zyrex:~$ man rcS

……..

……..

The configuration of rcS are placed in /etc/default/rcS or /usr/share/initscripts/default.rcS

To see the content just type:

taufanlubis@zyrex:/etc/init.d$ cat /usr/share/initscripts/default.rcS

#

# /etc/default/rcS

#

# Default settings for the scripts in /etc/rcS.d/

#

# For information about these variables see the rcS(5) manual page.

#

# This file belongs to the “initscripts” package.

TMPTIME=0

SULOGIN=no

DELAYLOGIN=no

UTC=yes

VERBOSE=no

FSCKFIX=no

Booting Process

Ubuntu boots up by executing the program init. The step of scripts to be executed are

/etc/init.d/rcS

/etc/rc.boot

all scripts in a directory specified by the default runlevel

/etc/rc0.d

/etc/rc1.d

/etc/rc2.d

/etc/rc3.d

/etc/rc4.d

/etc/rc5.d

/etc/rc6.d

Let’s check the content of /etc/init.d/rcS.

taufanlubis@zyrex:~$ cat /etc/init.d/rcS

#! /bin/sh

#

# rcS

#

# Call all S??* scripts in /etc/rcS.d/ in numerical/alphabetical order

Like this:

Related

One Response

pass any arguments the app init to the script dependind on the folder there are???

I think that because all files in /etc/rc2.d/ and /etc/rc6.s/ are symbolic links to /etc/init.d. To the same file. Where is the diferent between executing the symlink in rc2 and rc6? I think in the arguments star for rc2 and stop for rc6