Wednesday, July 18, 2012

run level and change run level


The term runlevel refers to a mode of operation in one of the computer operating systems that implement Unix System V-styleinitialization. Conventionally, seven runlevels exist, numbered from zero to six; though up to ten, from zero to nine[citation needed], may be used. S is sometimes used as a synonym for one of the levels. Only one "runlevel" is executed on bootup - run levels are notexecuted sequentially, i.e. either runlevel 2 OR 3 OR 4 is executed, not 2 then 3 then 4.
"Runlevel" defines the state of the machine after boot. Different runlevels are typically assigned to:
  • single-user mode
  • multi-user mode without network services started
  • multi-user mode with network services started
  • system shutdown
  • system reboot
The exact setup of these configurations will vary from OS to OS, and from one Linux distribution to another. For example, runlevel 4 might be multi-user, GUI, no-server on one distribution, and nothing on another. Note the difference in the Red Hat and Slackware distributions charted in this article. However, "runlevels" do commonly follow patterns described in this article. When installing Linux, it is best to consult that distribution's available user guides.
In standard practice, when a computer enters runlevel zero, it halts, and when it enters runlevel six, it reboots. The intermediate runlevels (1-5) differ in terms of which drives are mounted, and which network services are started. Default runlevels are typically 3, 4, or 5. Lower run levels are useful for maintenance or emergency repairs, since they usually don't offer any network services at all. The particular details of runlevel configuration differ widely among operating systems, and also among system administrators.
The runlevel system replaced the traditional /etc/rc script used in Version 7 Unix.

Linux

The Linux operating system can make use of runlevels through the programs of the sysvinit project. After the Linux kernel has booted, the init program reads the /etc/inittab file to determine the behavior for each runlevel. Unless the user specifies another value as a kernel boot parameter, the system will attempt to enter (start) the default runlevel.

[edit]Linux Standard Base specification

Conforming implementations are not required to provide these exact run levels or give them the meanings described here, and may map any level described here to a different level which provides the equivalent functionality.[1]
LSB 4.1.0
IDNameDescription
0HaltShuts down the system.
1Single-User ModeMode for administrative tasks.[2][3]
2Multi-User ModeDoes not configure network interfaces and does not export networks services.[4]
3Multi-User Mode with NetworkingStarts the system normally.[5]
4Not used/User-definableFor special purposes.
5Start the system normally with appropriate display manager. ( with GUI )As runlevel 3 + display manager.
6RebootReboots the system.
^ = The additional behavior of this runlevel varies greatly. All distributions provide at least one virtual terminal. Some distributions start a login shell as thesuperuser; some require correctly entering the superuser's password first; others provide a login prompt, allowing any user access.
^ = In some cases, runlevels 2 and 3 function identically; offering a Multi-User Mode with Networking.

[edit]Debian 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 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 [3] :
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 withchkconfig command like the Red Hat based distributions.

[edit]Slackware Linux

Slackware Linux uses runlevel 1 for maintenance, as on other Linux distributions; runlevels 2, 3 and 5 identically configured for a console (with all services active); and runlevel 4 adds the X Window System.
Slackware Linux runlevels
IDDescription
0Halt
1Single-User mode
2Unused but configured the same as runlevel 3
3Multi-User mode without display manager
4Multi-User mode with display manager
5Unused but configured the same as runlevel 3
6Reboot

[edit]Arch Linux

Arch Linux runlevels[4]
IDDescription
0Halt
1Single-User (Maintenance Mode)
2Not used
3Multi-User
4Not used
5Multi-User with X11
6Reboot

[edit]Gentoo Linux

Gentoo Linux runlevels
IDDescription
0Halt
1 or SSingle-User mode
2Multi-User mode without networking
3Multi-User mode
4Aliased for runlevel 3
5Aliased for runlevel 3
6Reboot

[edit]Unix

[edit]System V Releases 3 and 4

System V runlevels
IDDescription
0Shut down system, power-off if hardware supports it (only available from the console)
1Single-User mode, all filesystems unmounted but root, all processes except console processes killed
2Multi-User mode
3Multi-User mode with RFS (and NFS in Release 4) filesystems exported
4Multi-User, User-definable
5Halt the operating system, go to firmware
6Reboot
sSIdentical to 1, except current terminal acts as the system console

[edit]Solaris[5]

Solaris runlevels
IDDescription
0Operating system halted; (SPARC only) drop to OpenBoot prompt
SSingle-User mode with only root filesystem mounted (as read-only)
1Single-User mode with all local filesystems mounted (read-write)
2Multi-User mode with most daemons started
3Multi-User mode; identical to 2 (runlevel 3 runs both /sbin/rc2 and /sbin/rc3), with filesystems exported, plus some other network services started.
4Alternative Multi-User mode, User-definable
5Shut down, power-off if hardware supports it
6Reboot

[edit]HP-UX

HP-UX runlevels
IDDescription
0System halted
SSingle-User mode, booted to system console only, with only root filesystem mounted (as read-only)
sSingle-User mode, identical to S except the current terminal acts as the system console
1Single-User mode with local filesystems mounted (read-write)
2Multi-User mode with most daemons started and Common Desktop Environment launched
3Identical to runlevel 2 with NFS exported
4Multi-User mode with VUE started instead of CDE
56Not used/User-definable

[edit]FreeBSD, OpenBSD and NetBSD

The BSD variants don't use the concept of run levels, although on some versions init(8) provides an emulation of some of the common run levels.

[edit]AIX

AIX does not follow the System V R4 (SVR4) run level specification, with run levels from 0 to 9 available, as well as from a to c. 0 and 1 are reserved, 2 is the default normal multi-user mode and run levels from 3 to 9 are free to be defined by the administrator. Run levels from a to c allow the execution of processes in that run level without killing processes started in another.
AIX runlevels
IDNameDescription
0reserved
1reserved
2Normal Multi-User modedefault mode



How to Change Runlevels

by bobjensen — last modified Oct 27, 2009 08:24 AM
— filed under: 
Many people get confused when trying to boot in to a runlevel other than runlevel 5, for example runlevel 3, disabiling the GUI front end with which most users are familiar. Hopefully this howto will help answer the questions "How do I disable X" or "How do I boot without X" or even "How do I get to single user mode."

Requirements

One requirement of this document is to have an understanding of what runlevels are,how changing runlevels will impact your system, and what services may or may not be started. In general this is beyond the scope of this document but I will give a quick rundown of things as listed in /etc/inittab.

Runlevels

0 - halt (Do NOT set initdefault to this)
1 - Single user mode
2 - Multiuser, without NFS (The same as 3, if you do not have networking)
3 - Full multiuser mode
4 - unused or Admin
5 - X11
6 - reboot (Do NOT set initdefault to this)
The most commonly used runlevels in Fedora Core are 0, 1, 3, 5 and 6. As you can see you use runlevels everytime you shutdown (runlevel 0) or reboot (runlevel 6) your machine. Most users boot to runlevel 5 with X11 support and a GUI login. Somehowever, boot to Full multiuser mode (runlevel 3) and may choose to "startx" manually once logged in. Single user mode (runlevel 1) can be very handy if you have forgotten your root password or are having trouble booting for any number of reasons. Full multi user mode (runlevel 3) is desirable when  you are having trouble with X11 and  would like to repair your xorg configuration or when running a server where you do not want the added overhead of having X running.

Doing the work

We will discuss ways to change your runlevel in this howto. First how to change yourrunlevel "permanently."  Second how to change your current runlevel and finally how tochange the runlevel at boot time.

Editing /etc/inittab to change your default runlevel 

  1. Open /etc/inittab in your favorite editor (I use nano).
    su -c 'nano -w /etc/inittab'
  2. On about line 18 you will see a line like the one shown below.
    id:5:initdefault:
  3. You simply change the "5" in this case to the runlevel you desire. Save the file and exit.

Changing your current run level 

  1. You can change runlevels using the telinit or init commands as in the example below.
    su -c 'telinit 3'

Changing your runlevel at boot time. (aka Grub Method)

The Grub menu is hidden by default

  1. Reboot then press and hold a key until the grub menu appears
  2. Choose your desired kernel and press "a" to modify the kernel arguments.
  3. Simply add a 3 to the line for runlevel 3 or 1 for single user mode and Press "enter".  After pressing enter press "b" to boot with the changes you have made. (NOTE: If you are having booting issues you might want to remove "quiet" and "rhgb.")
  4. Log in and do the damage you desire. If you are booting to single user you do not need to login you will simply be presented with a prompt.
  5. Logout, change runlevels or reboot as needed.


    Linux Find Out Current Run Level Command

    Type the following command:
    $ who -r
    Sample outputs:
             run-level 2  2011-10-12 05:38   

    Linux Change Run Level Command

    Use the init command to change rune levels:
    # init 1

    Runlevel And Its Usage

    The Init is the parent of all processes with PID # 1. Its primary purpose is to create processes from a script stored in the file /etc/inittab file. This file usually has entries which cause init to spawn gettys on each line that users can log in. A runlevel is nothing but a software configuration of the Linux system which allows only a selected group of processes to exist. The processes spawned by init for each of these runlevels are defined in the /etc/inittab file. Init can be in one of eight runlevels as follows:
    • Runlevel 0 is halt
    • Runlevel 1 is single-user
    • Runlevels 2-5 are multi-user (some distro uses RUN level 5 to start X [KDE/Gnome])
    • Runlevel 6 is for rebooting system
    For example, typing the init 3 command will move system to run level 3:
    # init 3
    On most Linux server system default run level is 3 and on most Linux Desktop system default run level is 5. The default run level is defined by the initdefault line at the top of /etc/inittab file under CentOS / Fedora / Redhat / RHEL / Debian Linux. To change the default run level, edit /etc/inittab file, and edit entry initdefault:
    # vi /etc/inittab
    Set initdefault to 5, so that you can boot to X next time when Linux comes up:
    id:5:initdefault:
    Save and close the file. Reboot the system to see changes:
    # reboot

No comments:

Post a Comment