Debian and Ubuntu Linux Run Levels

Posted by Admin on September 25th, 2006

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

Random Posts

You can leave a response, or trackback from your own site.

18 Responses to “Debian and Ubuntu Linux Run Levels”

  1. Walid Says:
    December 3rd, 2006 at 6:14 pm

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

  2. Admin Says:
    December 3rd, 2006 at 6:37 pm

    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:
    March 13th, 2007 at 3:29 pm

    Thanks this was a exactly what I needed!

  4. alf lacis Says:
    March 16th, 2007 at 9:55 am

    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:
    March 26th, 2007 at 6:48 pm

    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:
    June 22nd, 2007 at 3:48 pm

    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:
    May 23rd, 2008 at 3:27 am

    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:
    July 1st, 2008 at 8:28 am

    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:
    July 5th, 2008 at 2:04 pm

    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

  10. Anthony Wrather Says:
    July 20th, 2008 at 2:15 pm

    On Ubuntu Intrepid 8.10 you can use update-rc.d

    sudo update-rc.d -f gdm remove
    sudo update-rc.d gdm stop 01 0 1 6 .
    sudo reboot

    Then once the restarts you will be in console mode.

  11. F4jr Pics Says:
    October 8th, 2008 at 5:45 am

    It works fine !

    Thanks !

  12. Martin Braunstein Says:
    February 15th, 2009 at 4:25 pm

    @ Anthony Wrather

    I too need this option in order to install a NVIDIA driver. After, I would like to by default to boot into x again. My question, how do I reverse you tip.

  13. jcran Says:
    March 23rd, 2009 at 3:56 am

    an easier version of this procedure:

    1) boot up ubuntu to an X login screen
    2) press ctrl-alt-1 to drop to a console login
    3) login to the console
    4) browse to the /etc/rc4.d/ directory ( ‘cd /etc/rc4.d’ )
    5) move the S30gdm file to K30gdm ( ‘mv S30gdm K30gdm’ )
    6) change runlevels to runlevel 4 using telinit ( ‘telinit 4′) *GNOME should stop*
    7) run nvidia installer
    8) when you’re finished, change back to default runlevel 3 ( ‘telinit 3′ )

    jcran

  14. Oegarcia75 Says:
    April 2nd, 2009 at 3:20 pm

    How do I change it back from command line login to Gnome login??

  15. Admin Says:
    April 2nd, 2009 at 3:34 pm

    type the following command

    startx

  16. shahbaz Says:
    August 18th, 2009 at 5:40 am

    Hi,
    Can anybody tell me that how can I change run level 6. By mistake I have fix run level 6, now it is keep on rebooting, I am not able to work it out ?

    Thanks

  17. Alex Says:
    September 24th, 2009 at 6:23 pm

    There is an even easier way to install NVIDIA drivers for debian based distributions (like ubuntu).

    1) Press Ctrl+Alt+F1 to go to tty1
    2) Log in
    3) enter “sudo /etc/init.d/gdm stop” (without the quotes). This command will stop gnome display manager.
    4) install NVIDIA drivers. (in order to install the drivers you may need the package build-essential – “sudo apt-get install build-essential”)
    5) After installation completes successfully enter “sudo /etc/init.d/gdm start”
    6) Enjoy your hardware accelerated desktop ;)

  18. veraitt50 Says:
    December 17th, 2009 at 2:05 am

    what would you name the link to an init script that start the daemon bigd early in the boot



Hosted by uCoz