Results 1 to 9 of 9

Thread: Intro to run levels

  1. #1
    Senior Member gore's Avatar
    Join Date
    Oct 2002
    Location
    Michigan
    Posts
    7,177

    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:

    cooperative multitasking


    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.



    Run levels:

    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:

    init=/bin/sh

    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.

  2. #2
    Senior Member
    Join Date
    Oct 2002
    Posts
    1,130
    Good tutorial.

    But one some distros, the runlevels are different. On slackware, runlevel 4 is multiuser with X, and runlevel 5, although not used, is the same as runlevel 3.

    There might be other differences with some distros, but I'm not aware of them.

    I'd like to see a tutorial explaining the differnces between runlevels on all the different operating systems.
    Government is like fire - a handy servant, but a dangerous master - George Washington
    Government is not reason, it is not eloquence - it is force. - George Washington.

    Join the UnError community!

  3. #3
    Senior Member gore's Avatar
    Join Date
    Oct 2002
    Location
    Michigan
    Posts
    7,177
    OK, then I can probably get one going. The Slackware thing I did point out when I listed the run levels, I pointed out 4 is the same as 5 is one most and the run levels 5 was what Slackware uses as 4.

  4. #4
    Senior Member
    Join Date
    Oct 2002
    Posts
    1,130
    Oops. My bad. Sorry about that. Must be this damn headache.



    Apologies.
    Government is like fire - a handy servant, but a dangerous master - George Washington
    Government is not reason, it is not eloquence - it is force. - George Washington.

    Join the UnError community!

  5. #5
    Senior Member gore's Avatar
    Join Date
    Oct 2002
    Location
    Michigan
    Posts
    7,177
    No problem

  6. #6
    AO übergeek phishphreek's Avatar
    Join Date
    Jan 2002
    Posts
    4,325
    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.
    Does each runlevel have its own scripts? Or are the scripts the same across the board?

    For example. I originally booted into inti5 and I modified my network script to set my wifi parameters. Then I decide to change from init5 to init3. Will the changes to the script I made in init5 also be in init3?
    Quitmzilla is a firefox extension that gives you stats on how long you have quit smoking, how much money you\'ve saved, how much you haven\'t smoked and recent milestones. Very helpful for people who quit smoking and used to smoke at their computers... Helps out with the urges.

  7. #7
    Senior Member gore's Avatar
    Join Date
    Oct 2002
    Location
    Michigan
    Posts
    7,177
    Yes, Yes, you in the back.

    Ahhh, good question!

    Yes, each run levels has it's own scripts.

  8. #8
    Senior Member
    Join Date
    Jan 2003
    Posts
    3,915
    Originally posted here by gore
    Yes, each run levels has it's own scripts.
    Hey Hey,

    To expand a little on what gore said,

    There are specific start and kill scripts for each run level.. The application scripts themselves (start, stop, restart and anything else that might be included) only exist in a single location.

    The main two linux systems that I have worked with are SuSE 9.x and RedHat Linux (7 and 9, primarily 7)..

    In RedHat, a handy little CLI tool is included called chkconfig... This tool would save you the tedium of creating all your symbolic links in the appropriate locations..

    Here's the structure of the boot environment for start and kill scripts.

    /etc/init.d or /etc/rc.d contain your boot scripts... For example on SuSE 9.3 /etc/rc.d in a symbolic link to /etc/init.d. On RH7 your init scripts were found in /etc/init.d without a symlink from /etc/rc.d to /etc/init.d. On RH7, you'll find that /etc/rc.d contains only the run level scripts and a few other system scripts (rc.sysinit, rc.local, etc). In this way RH7 is slightly more organized, but requires a little more movement in your setup. Inside /etc/rc.d you'll find rc0.d, rc1.d, rc2.d, rc3.d, rc4.d, rc5.d, rc6.d, and rcS.d...

    Inside these scripts you'll find a list of sym links that follow the format S##name and K##name. These links point back to the scripts in /etc/init.d. The S scripts are your start-up scripts, they are run in numerical and then alphabetical order.. so S10network would come before S11portmap, and S11apache would come after S10network but before S11portmap. The K scripts are your kill scripts, they are run in reverse numerical order and shutdown your services. Depending on the run level that you boot into decides which folder to run.

    Linux addicts, who believe that everything should be perfect, will insist that you should have the approriate kill scripts for each of your start up scripts, this was something that chkconfig assisted with, however for simplicity sake and if you just need a quick fix, you can just specify the startup script.

    Hopefully this helps.

    Peace,
    HT

  9. #9
    AO übergeek phishphreek's Avatar
    Join Date
    Jan 2002
    Posts
    4,325
    Yes... that clears things up a lot! I've never really messed with the services outside of a config utility. I've mostly used Redhat/Fedora so I normally open up a terminal and type "setup". There is a services config utility right there... Then I just manually start/stop/etc using "service network restart" or whatever.

    In SuSE, for the little time I used it..., I used yast.

    Hopefully by the time I get home my torrent will be done. Then I can load SuSE on my laptop. I'll just blow away FC3 since I have it on two other boxes.
    Quitmzilla is a firefox extension that gives you stats on how long you have quit smoking, how much money you\'ve saved, how much you haven\'t smoked and recent milestones. Very helpful for people who quit smoking and used to smoke at their computers... Helps out with the urges.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •