Linux Boot Process
Booting Linux:
Part 1: Loading the Kernel
- Of course the first step is the display of the BIOS info, but this too can be changed.
Instead of the Energy Star logo you are able to place a nice penguin logo here.
More information about changing the BIOS logo can be found at here . - Next, the kernel is loaded into the memory and executed. This can be done by different programs like LOADLIN that reads a kernel file you specify and writes it into the memory (it overwrites DOS loaded into the memory).
Another way can be LILO , the LInux LOader. It loads the kernel directly from the physical sector on a hard disk. Therefore, LILO writes itself into the Master Boot Record (MBR) together with the sectors where the kernels are placed. After choosing the appropriate kernel, it writes it into memory and executes it.
- The kernel is responsible for recognizing and including all the hardware into the system. Every discovered (and not discovered) component is printed on the screen. If you want to read some of the scrolling lines a little bit longer, the key PAUSE , Scroll Back, or Roll are useful. Of course the scroll back buffer has already been activated by Linux (Ctrl+PgUp or Ctrl+PgDn).
- The last task of the kernel is to mount the root partition. The root partition is specified in LILO- or LOADLIN- as a parameter. Then it starts the first process, which is usually called INIT (the program is placed at /sbin/init).
The kernel finished its job and the complete system of all discovered and mounted hardware is available.
The messages that show the point where the kernel ends and the programs begin looks like: VFS: mounted root (ext2fs) filesystem read-only. (still Kernel) INIT: Version X.XX booting (already INIT).
Part 2: INIT sequences
- INIT checks different items. First, it looks for the file /etc/inittab where it finds the runlevel that has to be started ( id:X:initdefault: , where `X' is the number of the runlevel).
Then INIT checks which program has to be started next, because not a server nor a shell has been started, nor has a network connection been made nor any partition been made available. All this happens in the line si:I:wait:PROGRAM ).
In general PROGRAM stands for /etc/rc.d/init.boot or /sbin/init.d/boot and this one is executed now. - The BOOT script usually does the following (from here everything can be configured and tailored to your wishes):
- Turn on swap
- check the root partition and remount it read/write-able
- check for other partitions and mount them
and if one partition has a problem, it would stop the process and requires a root login - start the module manager that is responsible for "auto loading" the required modules
- if needed, basic network programs are started (e.g. loopback device)
Please Remember: Every system can be different.
Often, you find the file boot.local in the same directory which is executed by boot at the end. In it, you can place additional commands.
Of course, you could put these commands into the boot script, but be careful! You should not change anything there as long as you do not know what you are doing. - Then, INIT checks which runlevel is declared to be the next ( /etc/inittab ) and now all scripts of this runlevel are /etc/inittab: lN:N:wait:SCRIPT (N=runlevel). In general, this means that all scripts in /etc/init.d/rcN.d/ (or similar) are started (N=runlevel).
Here, all the services and daemons are started which are run in the background. At the same time, lock- and log-files are created if necessary.
- Next, INIT starts a getty for all terminals. It controls the terminal and starts the /bin/login first.
This is specified in the /etc/inittab ,too.
" respawn " means here that the program would be restarted at once if it was finished. Without this option you would be able to login only once ... - If you chose a graphical login (at SuSE it is the runlevel 3, at RedHat the runlevel 5), 'xdm' or 'kdm' is started and you get a graphical login window.
This works over a network like so many other things, too. E.g. a simple startx --query another_computer:0 places a login window of another computer in the network on your screen. - After you logged in the script /etc/profile (identical for all users) is called and then the files ~/.profile , ~/.login or for the bash shell ~/.bashrc ~/.bash_login and ~/.bash_profile would be "executed" if they existed.
- After the login, the shell is started and you can use the system.
Definition Runlevel
First the expensive product:
M$ Windows knows 6 runlevels which cannot be changed:
- 1. Normal
- 2. Logged
- 3. Safe mode
- 4. Step-by-step with confirmation
- 5. Command prompt only
- 6. Safe mode - command prompt only
Now everyone should know what is meant by the term "run level".
Linux theoretically can have unlimited runlevels but the following ones are included by default:
0: Halted system. The system is going down, the kernel is halted and the PC would be turned of if you had a ATX mainboard.
6: Reboot system. Everything is going down and the system is rebooted.
S: Single User Mode. Just one terminal is started and only root has access to log in; no network at all. A good mode for fixing things.
1: Multiuser without network. (in general, but in RedHat, runlevel 1 is the single user runlevel)
From now on everything depends on the chosen distribution - look in the /etc/inittab
2: Multiuser with network.
3: Multiuser with network and graphical login.
4: User defined.
5: User defined (RedHat: the same as runlevel 3) What exactly is started or stopped in each runlevel is defined by the scripts you find in /etc/rcN.d or /etc/rc.d/rcN.d or /sbin/init.d/rcN.d (with N=runlevel).
More information can be reviewed with >> man 8 init.