Monday, June 07, 2004

How linux boots

librenix.com carried a beautiful article about the booting process in linux available at
http://www.pycs.net/lateral/stories/23.html

In the regular, plain-old-booting-linux business, all the boot loader does is:


Load the kernel into memory
Optionally load a ramdisk called initrd containing stuff like disk drivers
Pass the kernel arguments, of which we are only interested in runlevel and init
Start execution of the kernel.



knew that already ...the interesting part starts from here :)
What does the kernel do with init? It starts it. It's the only program the kernel itself starts, everything else is started by init.
remember reading that somewhere


In Red Hat's default inittab, that's just this:

si::sysinit:/etc/rc.d/rc.sysinit

So, it will run a script called /etc/rc.d/rc.sysinit, which does stuff like loading a terminal font, check disks, mount stuff... basic system habitability drudge work.

Then it will get all lines with action once and wait that have the desired runlevel in the runlevel field, and will run its commands, and will wait until the wait lines commands are finished.

In Red Hat, for runlevel 5:

l5:5:wait:/etc/rc.d/rc 5

What this particular script does is start all services configured for runlevel 5. That's what you see when it says things like "configuring the frobnozz [OK]" on boot. Now, let's see the details...


interesting
For each runlevel N, there is a folder, called /etc/rc.d/rcN.d.

Here's part of my folder for runlevel 5:

K05saslauthd -> ../init.d/saslauthd
K10lircd -> ../init.d/lircd
K10lircmd -> ../init.d/lircmd
K15httpd -> ../init.d/httpd
K15nessusd -> ../init.d/nessusd
:
:
:
S00microcode_ctl -> ../init.d/microcode_ctl
S05kudzu -> ../init.d/kudzu
S08iptables -> ../init.d/iptables
S10network -> ../init.d/network
S12syslog -> ../init.d/syslog
S13irqbalance -> ../init.d/irqbalance
:
:
:

The things that start with K are to be stopped. Those which start with S are to be started. The numbers are to give them an order to be killed or started.

So, we start by taking all the K stuff. For each, we check if the service is running. If it is, it's stopped.

didnt know that !!

good overview of the bootup process..sliglhtly outdated though :)