Understanding the Linux Startup Process
To troubleshoot problems at startup of your Linux PC you need to have a basic understanding of the startup process that occurs. Some distributions of Linux maybe slightly different but the basics remain the same.
The following is based on a process referred to as "lilo" there is another popular one called "Grub" which also uses the same basic process.
Edited by flw with reprint permission from http://www.comptechdoc.org. This content is copyrighted
Linux Startup Process using LILO
Note: If using Grub, a similar process also occurrs.
LILO will read the file "/etc/lilo.conf". LILO will give the user a choice of booting from any label included in this file.
The Linux kernel is installed compressed, so it will first uncompress itself. The beginning of the kernel image contains a small program that does this.
If you have a super-VGA card that Linux recognizes and that has some special text modes (such as 100 columns by 40 rows), Linux asks you which mode you want to use. After this, the kernel checks what other hardware there is (hard disks, floppies, network adapters, etc), and configures some of its device drivers appropriately; while it does this, it outputs messages about its findings.
Then the kernel will try to mount the root filesystem. The place is configurable at compilation time, or any time with rdev or LILO. The filesystem type is detected automatically. If the mounting of the root filesystem fails, for example because you didn't remember to include the corresponding filesystem driver in the kernel, the kernel panics and halts the system (there isn't much it can do, anyway). The root filesystem is usually mounted read-only (this can be set in the same way as the place). This makes it possible to check the filesystem while it is mounted; it is not a good idea to check a filesystem that is mounted read-write.
After this the kernel starts the program "init" (located in /sbin/init) in the background (This will always become process number 1). Init will start the services setup in the system. This document is written to explicitly analyze the methods used for init to bring system services up. This should enable the reader to better understand how the system is set up and operates.
The init process reads the file "/etc/inittab" and uses this file to determine how to create processes. Read the init man page for more information. Also note that init is always running and can dynamically do things and run processes based upon various signals. The administrator can also cause it to dynamically change system processes and runlevels by using the telinit program or editing the "/etc/inittab" file. Unix and Linux utilize what is called "runlevels". A runlevel is a software configuration of the system that allows only a selected group of processes to exist. Init can run the system in one of eight runlevels. These runlevels are 0-6 and S or s. The system runs in only one of these runlevels at a time. Typically these runlevels are used for different purposes. For Redhat Linux version 6, they are:
0 - halt
1 - Single user mode
2 - Multiuser, without NFS (The same as 3, if you don't have networking)
3 - Full multiuser mode
4 - unused
5 - X11
6 - Reboot
The /etc/inittab file instructs init which runlevel to start the system at and describes the processes to be run at each runlevel.. An entry in the inittab file has the following format:
id – A unique sequence of 1-4 characters which identifies an entry in inittab.
runlevels – Lists the runlevels for which the specified action should be taken. This field may contain multiple characters for different
runlevels allowing a particular process to run at multiple runlevels.
For example, 123 specifies that the process should be started in runlevels 1, 2, and 3.
action - Describes which action should be taken. Valid actions are listed below
respawn - The process will be restarted whenever it terminates.
wait – The process will be started once when the specified runlevel is entered and init will wait for its termination.
once – The process will be executed once when the specified runlevel is entered
boot – The process will be executed during system boot. The runlevels field is ignored.
bootwait – Same as "boot" above, but init waits for its termination
off – This does nothing.
ondemand – This process will be executed whenever the specified ondemand runlevel is called.
initdefault – Specifies the runlevel which should be entered after system boot. If none exists, init will ask for a runlevel on the console. The process field is ignored.
sysinit – The process will be executed during system boot. It will be executed before any boot or bootwait entries. The runlevels field is ignored.
powerwait – The process will be executed when init receives the SIGPWR signal. Init will wait for the process to finish before continuing.
powerfail – Same as powerwait but init does not wait for the process to complete.
powerokwait – The process will be executed when init receives the SIGPWR signal provided there is a file called "/etc/powerstatus" containing the word "OK". This means that the power has come back again.
ctrlaltdel – This process is executed when init receives the SIGINT signal. This means someone on the system console has pressed the "CTRL
-ALT-DEL" key combination.
kbrequest – The process will be executed when init receives a signal from the keyboard handler that a special key combination was pressed on the console keyboard.
process – Specifies the process to be executed. If the process starts with the '+' character, init will not do utmp and wtmp accounting for that process. This is needed for gettys that insist on doing their own tmp/wtmp housekeeping (a historic bug).
On line 1 you'll see "id:3:initdefault:". The id is "id" which stands for initdefault. Note it is unique on all the numbered lines. The runlevel is 3 which sets the default starting runlevel to runlevel 3.
The action is initdefault which tells init to make this runlevel the default runlevel. Note that the process field is blank since it is ignored by the initdefault action.
Line 2 tells init to run the program "/etc/rc.d/rc.sysinit" during system boot, before any other processes.
Lines 3 through 9 tell init to run the program "/etc/rc.d/rc" for runlevels 0 through 6. Note that for each line the appropriate runlevel is passed to the "/etc/rc.d/rc" script program on the command line.
For example note on line 5 above the second field is the runlevel specifying 2. At the end of the line there is a space and a 2 which allows the variable 2 to be passed on the command line to the program.
the order of programs to run as specified above are:
/etc/rc.d/rc 3 - Note: we are running runlevel 3 here.
Line 10 specifies that the program "/sbin/update" will run once for every runlevel.
Line 11 sets up the program "/sbin/shutdown" to run when someone on the system console has pressed the "CTRL-ALT-DEL" key combination.
Line 12 specifies "/sbin/shutdown" to run if the power fails. Note that there are different options passed on the command line for lines 11 and 12 although they run the same program.
Line 13 specified "/sbin/shutdown" will run if power is restored for any of runlevels 1 through 5.
Lines 14 through 19 specifies the "/sbin/mingetty" program to run on 6 different terminals for runlevels 2 through 5. This means that you can run 6 virtual terminals from your keyboard simultaneously by pressing "ALT-F1" through "ALT-F6". Note pressing "ALT-F&" or above will do nothing, but the screen will not change from your current terminal.