Debian Admin - Your way to Debian World

September 25, 2006

Debian and Ubuntu Linux Run Levels

by @ 8:37 pm. Filed under General

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Linux run levels are numbered 0 through 6. Run levels stop at six for practical and historical reasons, but it is entirely possible to have more if desired.

The following table summarizes the User Linux run levels:

* 0 System Halt
* 1 Single user
* 2 Full multi-user mode (Default)
* 3-5 Same as 2
* 6 System Reboot

Special Run Levels

Run level 0 is the system halt condition. Nearly all modern X86 computers will power off automatically when run level 0 is reached. Older X86 computers, and various different architectures will remain powered on and display a message referring to the halt condition.

Run Level 1 is known as ’single user’ mode. A more apt description would be ‘rescue’, or ‘trouble-shooting’ mode. In run level 1, no daemons (services) are started. Hopefully single user mode will allow you to fix whatever made the transition to rescue mode necessary.

(You can boot into single user mode typically by using your boot loader, lilo or grub, to add the word ’single’ to the end of the kernel command line).

Run levels 2 through 5 are full multi-user mode and are the same in a default User Linux (Debian) system. It is a common practice in other Linux distributions to use run level 3 for a text console login and run level 5 for a graphical login.

Run level 6 is used to signal system reboot. This is just like run level 0 except a reboot is issued at the end of the sequence instead of a power off.

In the interests of completeness, there is also a runlevel ‘S’ that the system uses on it’s way to another runlevel. Read the man page for the init command (”For manpage click here”) for more information, but you can safely skip this for all practical purposes.

Run Levels Location

Like everything else in a Linux system, run levels are defined by files in the file system. All the run level files are found in the /etc directory according to the following table:

/etc/rc0.d Run level 0
/etc/rc1.d Run level 1
/etc/rc2.d Run level 2
/etc/rc3.d Run level 3
/etc/rc4.d Run level 4
/etc/rc5.d Run level 5
/etc/rc6.d Run level 6

Each defined run level should have an rcX.d directory where X is the run level number. The contents of the rcX.d directory determines what happens at that run level.

Change run levels in Debian and Ubuntu Linux

Before we change run levels it might help to find out which run level is current. Use the ‘runlevel’ command to tell you two things: The last run level, and the current run level. Here is the command and the output shown together due to the sparsity of the output:

# runlevel N 2

The ‘N’ stands for none, meaning there has been no run level change since powering up.

The init system controls run levels, but then again, the init system pretty much controls everything. The init system will be looked at in detail in a future article.

The primary command used to change run levels is ‘telinit’.

#telinit 3

telinit takes one argument on the command line. As always, see the man page for full details. Normally the argument will be one of: 0,1,2,3,4,5,6, or the letter ‘S’. As you may have guessed, the numbers correspond to the run level you wish to move to. Using the ‘S’, for single-user, is the same as the number 1, but don’t do it; the ‘S’ runlevel is intended for use by the UserLinux (Debian)system.

A note of caution is warranted here. You can easily use the telinit command to reboot (run level 6), or shutdown (run level 0) the system, but it is not recommended. Certain programs need special processing for an orderly shutdown. Bypassing the expected shutdown sequence can have dire effects on your data. Older _Unix_ systems are especially sensitive to shutdown/bootup operations.

The preferred method for a serious runlevel change is ’shutdown’. There are easier mnemonics, but in a running system they all point to the ’shutdown’ command. You can use the ‘halt’, or ‘poweroff’ command to stop a system and the ‘reboot’ command to restart your system. In each case they call the ’shutdown’ command with different parameters.

If you wanted runlevel 3 to be the default, then you need to edit /etc/inittab.

# The default runlevel.

id:2:initdefault:

You’d change the ‘2′ to a ‘3′. Next time you reboot, your system will start in runlevel 3. There will be no display manager running in runlevel 3, because you turned it off. Therefore, runlevel 3 will become text only, and it will be the default. If that’s what you want to do.

Adding a new service

You can only add a new service to the boot sequence if a script in /etc/init.d exists. In that case the following command will install it with default settings (foo being the name of a script in /etc/init.d).

#update-rc.d foo default

Removing a service

A service may only be removed after the script in /etc/init.d as deleted already. If so, the following command will remove its references (foo being the name of a script in /etc/init.d).

#update-rc.d foo remove

If you want to remove a service without removing the start/stop script as well, you may consider using the file-rc package and editing the runlevel configuration file /etc/runlevel.conf. When using the SysV method you should rename the start/stop script, then call update-rc.d and then rename the start/stop script back to its old name.

Some of the content for this article source from here

Tags: , , , ,

You may also be interested in...

9 Responses to “Debian and Ubuntu Linux Run Levels”

  1. Walid Says:

    Hi! Could you please tell me HOW TO CHANGE DISPLAY MODE (from console to graphic) IN RUNLELVEL 3 please ? Thanks

  2. Admin Says:

    i am not sure if you are asking about GUI you need to install gnome or kde if you install any one of them the you can try to run the following command to get GUI mode

    startx

    hope this helps

  3. metro305 Says:

    Thanks this was a exactly what I needed!

  4. alf lacis Says:

    I’ve got ubuntu 6.10 & a NVIDIA driver, that
    (a) wants no X Server running, but
    (b) complains if I run at runlevel 1, saying that some required services won’t be available.
    Under RedHat I would “init 3″ and proceed with the text-based (no X server) install quite happily.
    What should I do?

  5. cameron Says:

    Alf Lacis;
    if you want to just boot into the command line, rename /etc/rc3.d/S13gdm to /etc/rc3.d/s13gdm, and edit your /etc/inittab to default to init level 3, then reboot.

  6. Philippe Says:

    I was wondering in a Debian system. The following boot sequence is followed.

    * lilo or loadlin loads ram disk image
    * kernel runs /linuxrc
    * kernel runs /sbin/init
    * /etc/init.d/rcS which runs:
    * /etc/rcS.d/S* scripts
    * Switch to Default runlevel (2 in our case).

    Skipping runlevels 0 and 1.

    Can someone confirm this? thank you

  7. Arstan Says:

    Great indepth explanation of runlevels. Now for those who want to keep it simple, install a sysv-rc-conf package. It will make your configs easier.

  8. Jonathan Says:

    Great work, but on last ubuntu (aka Hardy Heron) version you have to add an “s” to default, (replace “#update-rc.d foo default” by “#update-rc.d foo defaults”).

  9. eskey Says:

    Easy Howto change runlevel 3 in ubuntu 8.04.x:

    1. Install sysv-rc-conf
    2. Start sysv-rc-conf
    3. Remove gdm from runlevel 3.
    4. Close sysc-rc-conf
    5. Create /etc/inittab (if not exists)
    6. Add/edit following line in /etc/inittab “id:3:initdefault:”
    7. Reboot
    8. Ubuntu starts on text mode

Leave a Reply

Subscribe RSS Feed

subscribe to the Debian Admin RSS feed

Internal links:

Sponsors:



Categories:

Support Debian Admin

Amount $:
Website(Optional):

Sponsors:

Archives:

Related Links:


Favourite Sites:

Wordpress Collection
Windows Reference
Ubuntu Geek
DebianHelp
All About Debian Tutorials
Power Electrical
Check Your IP Here
Debian,Ubuntu News
DebCentral
Tuxmachines
Capnkirby
Libervis
Nuxifield
Linux Horizon
Linux Appfinder
Debuntu
GNU/Linux For Everyone
Free Penguin
DebianAdmin is not related to the Debian Project.
This site is copyright © 2006,2007 Debian Admin
All Trademarks are the property of their respective owners.
The contents of this website may not be mirrored or archived without the express written permission of DebianAdmin Site Owner.

DISCLAIMER: All the information, troubleshooting methods, utilities offered in this website is provided AS-IS, without any warranties. Though I strive for perfection, and always test the validity and effectiveness of the troubleshooting content in various systems, I assume no responsibility for your use of these Fixes, Utilities and other troubleshooting advice. The author will not be liable for any special, incidental, consequential or indirect damages due to loss of data or any other reason. All use is completely at your own risk. Changes to the existing content and new additions are made to this website periodically, without notification.
Rodney's Kontera DynamiContext Plugin plugged in.