If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
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
You may also be interested in...
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
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
March 13th, 2007 at 3:29 pm
Thanks this was a exactly what I needed!
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?
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.
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
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.
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”).
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