Sep 252006
 

Sponsored Link

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

Sponsored Link

 Posted by at 8:37 pm

  22 Responses to “Debian and Ubuntu Linux Run Levels”

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

  2. 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. Thanks this was a exactly what I needed!

  4. 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. 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. 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. 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. 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. 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. 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. It works fine !

    Thanks !

  12. @ 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. 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. How do I change it back from command line login to Gnome login??

  15. type the following command

    startx

  16. 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. 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. what would you name the link to an init script that start the daemon bigd early in the boot

  19. A minor change to Alex’s instructions, if you system has been configured to use upstart instead of the Sys-V:

    3) enter sudo service gdm stop

    5) sudo service gdm start

  20. Thank you for this article. It helped me understand.

  21. In versions 10.10 and later, I don’t see where the graphics get started in any of the runlevel scripts. So what is the procedure for booting to a text based prompt now? (i.e. like into runlevel 3 on system V type unix – basically everything except graphics running.)

    Here is what I am really trying to accomplish: on Redhat 8.0, I can boot to a text login prompt. The following line in a specific user’s .bash_profile will cause the PC to basically act as an xterminal for the named server:

    X -query server_name

    anyone know how to do this with these later versions of ubuntu?

    Thanks;

  22. “Normally the argument will be one of: 0,1,2,3,4,5,6, or the letter ‘S’.”
    Since when is there a runlevel called 4?

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>