April 28th, 2005, 05:40 AM
Intro to run levels
This is just an intro to the big World of Run Levels in Linux. If I get some feed back I may do a second one with more detail but I don't want to start off with something huge yet, first I want opinions on this one and then I shall go from there. So here itis, an small intro into the World of Run levels. All comments are welcome and if it's liked or if some of you want more, then reply here and I can start the next one up. I'm going to be finished with this semester in college soon so I can make more time for things.
When you boot up a Linux system and see "uncompressing Linux" that tells you the Kernel is now taking over your hardware. It checks and sets your console. Next your drivers "probe" existing hardware and start it up as needed.
After checking the partitions and loading the root file system the Kernel starts up init which then finishes booting up programs and configurations that are used for booting the system up.
The Kernel controls the entire system, which includes hardware access and the CPU time programs use. This is called a Preemptive Multi Tasking OS. As opposed to Cooperative Multi Tasking that OSs such as Windows used all the way up to Windows 9X. This itself is a bad idea and explains why they were so unstable.
To quote webopedia:
A type of multitasking in which the process currently controlling the CPU must offer control to other processes. It is called cooperative because all programs must cooperate for it to work. If one program does not cooperate, it can hog the CPU. In contrast, preemptive multitasking forces applications to share the CPU whether they want to or not. Versions 8.0-9.2.2 of Macintosh OS and Windows 3.x operating systems are based on cooperative multitasking, whereas UNIX, Windows 95, Windows NT, OS/2, and later versions of Mac OS are based on preemptive multitasking.
Init is responsible for correctly initializing all system processes. It's the Parent Process of all other system processes. Init is started by the Kernel and is immune to every BOFH's favorite "kill -9". All other programs are started either by init or one of it's child processes.
init is centrally configured via /etc/inittab. Here are where run levels are defined and what services and daemons are loaded by the system in whichever run level you choose.
In Linux, run levels define how the system is started. After booting, the system starts as defined in /etc/inittab which is in the line initdefault. For the most part, this is going to be 3, or 5. An Alternative to this is assigning a special run level at boot time (Like at the boot prompt). The Kernel passes any parameters it does not need directly to init.
Changing run levels while the system is running is easy, just type init and whichever run level you want. You must be root to do this.
0 - Systems halt (Like typing halt or shutdown at the prompt)
S - Single user mode
1 - Single user mode
2 - Local multiuser but without network
3 - full multi user with network. This is standard on Slackware.
4 - Unused unless you're using Slackware, which would be what other Linux distros use as 5.
5 - Full multiuser, network, and X. Except on Slackware, in which this is 4.
6 - reboot
(You can imagine the fun I've had making my cousin's box default run level 6 )
If /etc/inittab is damaged, the system may not boot properly. In other words, only play with it if ou don't care about having to reinstall. If you do damage it though, you should have a back up. I assume you do because in any OS, before oyu screw with it, back it up. If you do screw it up though, try entering this:
after the Kernel name in the LILO boot prompt to boot right into a shell, and then use cp to replace the FUBARED version with your back up copy.
To change your GUI run level to text, type init 3.
Generally two things happen when you are changing run levels. First, stop scripts of the current run level are run, closing down programs essential for the current run level and then start scripts are ran where most of the time programs needed for this run level get started.
when starting the same run level you're already in, init only checks /etc/inittab checking for changes.