Tuesday, April 9

The Runlevels in Linux

Many Windows users are familiar with different modes of execution of their operating system:
a. Safe mode
b. Command prompt only
c. Safe mode with network support
d. Safe mode with vga


And other such options that are presented during the boot-up process. Similarly, Linux has different modes of executing as well, which are known as runlevels. But unlike Windows, we can change runlevels on a fly.
Definition for runlevel : The term runlevel refers to a mode of operation in one of the computer operating system that implement Unix System V-style initialization. This system replaces the traditional /etc/rc and /etc/rc.local scripts used in BSD UNIX. Conventionally, seven runlevels exist, numbered from zero to six, plus an alias runlevel named ‘S’ and/or ‘s’.
Runlevels control services started by the initialization process. The number of runlevels and services started on those runlevels varies with Linux distributions. Information about the runlevels of a particular distribution is listed in file /etc/inittab.
The contents of the file include the following:
DNameDescription
0HaltShuts down the system.
1Single-user ModeMode for administrative tasks.
2Multi-user ModeDoes not configure network interfaces and does not export networks services.
3Multi-user Mode with NetworkingStarts the system normally.
4Not used/User-definableFor special purposes.
5Start the system normally with appropriate display manager. ( with GUI )As runlevel 3 + display manager.
6RebootReboots the system.

Runlevel 0 : Is halt mode. Telling init to enter runlevel 0 will cause all processes to be killed off, the filesystems unmounted, and the machine to be halted. This is a perfectly acceptable way to bring down the system. On many laptops and modern desktop computers, this will also cause the machine to be turned off. Different commands to go to runlevel 0.
# halt
# init 0
# telinit 0
# shutdown -h
Now in the above command h is halting and now indicates shutdown the computer now it self no grace/trancision time for example you want to shutdown the command after 60 min so give the below command # shutdown -h +60.
Runlevel 1 : Runlevels 1 and 2 are generally used for debugging purposed only, and are not used during normal operations. Most desktop linux distributions boot into runlevel 5, which starts up the Graphical Login Prompt. This allows the user to use the system with X-Windows server enabled. Most servers boot into runlevel 3, which starts the text based login prompt. Linux runlevels can be changed on the fly using the init tool. If you want to switch from text based operations to the Graphical Interface, you just have to type in ‘telinit 5′ in the root prompt. This will bring up the Graphical Interface in your system. Each runlevel can be configured by the system administrator. The ”/etc/inittab” file has information on which runlevel to start the system at and lists the processes to be run at each runlevel. Each runlevel has its own directory structure where you can define the order in which the services start. These directories are located in the /etc/rc.d/ directory, under which you have rc1.d, rc2.d, rc3.d…. rc6.d.Directories where the number from 0 to 6 that corresponds to the runlevel. Inside each directory are symbolic links that point to master initscripts found in /etc/init.d or /etc/rc.d/init.d. You can also change the runlevel at boot time. If your system uses LILO as the boot manager, you can append the runlevel to the boot command : LILO: linux 3 or LILO: linux 5. If your system uses GRUB, you can change the boot runlevel by pressing the `e’ key to edit the boot configuration. Append the runlevel to the end of the boot command as shown : kernel /vmlinuz ro root=/dev/hda1 5 different linux/unix disterbution’s runlevels

Debian GNU/Linux

Debian, as well as most of the distributions based on it, like early Ubuntu, does not make any distinction between runlevels 2 to 5.
Debian GNU/Linux runlevels
IDDescription
SOnly run on boot (replaces /etc/rc.boot)
0Halt
1Single-user mode
2-5Full Multi-user with console logins and display manager if installed
6Reboot

[edit]

Ubuntu

Ubuntu 6.10 (Edgy Eft) and later contain Upstart as a replacement for the traditional init-process, but they still use the traditional init scripts and Upstart's SysV-rc compatibility tools to start most services and emulate runlevels.

[edit]

Red Hat Linux and Fedora

Red Hat as well as most of its derivatives (such as CentOS) uses runlevels like this:
Red Hat Linux/Fedora runlevels
CodeInformation
0Halt
1Single-user mode
2Multi-user mode console logins only (without networking)
3Multi-user mode, console logins only
4Not used/User-definable
5Multi-user mode, with display manager as well as console logins (X11)
6Reboot

[edit]

SUSE Linux

SUSE uses a similar setup to Red Hat:
SUSE Linux runlevels
IDDescription
0Halt
1 or SSingle-user mode
2Multi-user mode without networking
3Multi-user mode, console logins only
4Not used/User-definable
5Multi-user mode with display manager
6Reboot
The services that run under a specific runlevel can be modified with YaST | System Services (runlevel), insserv command or with chkconfig command like the Red Hat based distributions.


No comments:

Post a Comment