Linux Runlevels explained
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4044
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
Linux has a what are known as runlevels. In windows you basically always are in runlevel 5, for all practical purposes, and there's really no other choice. Linux gives you a choice. What a surprise, no?

Some more serious Unix/Linux guys I met always set their machines to run in level 3, that's the basic command line mode, direct access to the kernel, no x window system running if I understand it right.

At times it can be useful to switch runlevels.

To do this live, simply type in this command [hit enter after each]:
su
[type in password]
telinit 3 [or: init 3]
[if you want to enter runlevel 3, to fix a configuration file, run some utility if you're having problem with the GUI desktop, and for many other reasons]. For serious servers of course there's no real need to use runlevel 5 at all, just uses up system resources.

In run level 3, if you wanted to modify a configuration file, you could use the command:
pico /yourfolder/config_file

Pico is a nice simple command line text editor, a good one for newbies. Emacs and vi are much more powerful, but also very hard to learn. One step at a time. If pico isn't available, nano is excellent, that's my personal choice, it's very easy to use, unlike the fabled vi or emacs.

:: Quote ::
Linux systems today generally use eight runlevels. Runlevels define what services or processes should be running on the system. The init process can run the system in one of eight runlevels. The system runs only one of the eight runlevels at a time. The main runlevels are from 0 - 6.

Runlevel - System State
  • 0 - Halt the system
  • 1 - Single-user mode
  • 2 - Multi-user mode (without NFS)
  • 3 - Multi-user mode
  • 4 - unused
  • 5 - Multi-user mode, graphical login
  • 6 - Reboot the system

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. 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 through 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
src: vinuthomas.com under Creative Commons license.


And so on, step by step we'll get into this thing.

The main advantage of being able to switch runlevels is that if you're in runlevel 5, and it's not working, you can jump down to 3, fix the problem, like in this case hopefully, then jump back up. No reboots, begins to give you a sense that unlike with Windows, you have a series of options to move to when you run into problems.

Runlevel 3 is where you want to be to do things like full system upgrades with apt, if you are ugrading kde for example, never do that while in runlevel 5, gui mode, that can cause all kinds of unpleasant and hard to fix errors.

You can read more on runlevels at debianhelp.

Most linux stability problems I've seen so far are due to software, or the desktop systems, the kernel itself is very solid as a rule.

Update: 2011-05-17
Debian Runlevels
The above link from debianhelp.org has been updated to reflect the following information:

Debian, for some utterly inexplicable reason, has dropped this fine standard and uses the simplified: 0 1 2 6
where
0 = halt
1 = single user mode, many services not started, only for emergency repairs of core system components
2 = everything starts, including the desktop login
6 = reboot

Having desktop login start with everything else creates no end of problems when there is a bug with the video driver, free or non-free. That case, for example, involves the current Xorg radeon driver and crashing virtual terminal switching, a frequent and reappearing bug in fglrx non free and radeon free xorg drivers. I could post to many other such issue reports, but since that's a recent one, it's fresh and can't be accused of being some old thing long since fixed.

Since I run only Debian based systems, what I do is keep the defaults of everything over than the desktop login at 2, and make the desktop login appear at 3, and change inittab to 3 as default. This lets me do maintenance and recovery work as regular user in 2 while keeping the rest of the system as debian default. The smxi tool also lets me change these defaults very easily in its advanced-tweaks, set-default-runlevel section. (only Debian is supported, and Debian based distros)

Ubuntu, the new, relative to this article's original appearance, leading GNU/Linux desktop globally, also uses this annoying 0 1 2 6 method, thus getting rid of one of the really nice things about linux desktops, the ability to easily and without much fuss boot into a terminal session as user with all other services running except the desktop. This was a strength of unix like systems, not a weakness or failure, so why they had to change this is really beyond me, if you boot desktops at runlevel 3, all that happens as far as the user is concerned is, well, frankly, they see exactly zero difference, until they need or want to be able to start without X running, then they can.

Other changes since this article was written
A few things have changed, by the way, since this article was posted:

telinit is almost never used anymore, instead we use init, like so:
init 3

Pico has long since been replaced by nano, so don't go looking for it, nano was basically just forked from pico, and took over as the nice, fairly sane, non vi type command line text editor, that is fairly user friendly, and usable.

Lilo, while almost totally deprecated over the years, has seen some new breaths of life since grub 2 and it's convoluted and nearly incomprehensible configuration file methods and syntax appeared, some people just prefer a simple file to edit using simple configurations that are easy to learn, all areas that grub2 gets a huge FAIL in so far.
Back to top
Display posts from previous:   

All times are GMT - 8 Hours