Booting and Kernel Initialization
Booting and Kernel Initialization
Initialization
Boot Terminology
Loader:
Program that moves bits from disk (usually)
to memory and then transfers CPU control to the newly
loaded bits (executable).
Bootloader / Bootstrap:
Program that loads the first program (the kernel).
Boot PROM / PROM Monitor / BIOS:
Persistent code that is already loaded on power-up.
Boot Manager:
Program that lets you choose the first program to load.
System Lifecycle: Ups & Downs
Power
on
Power
off
Boot Kernel
Init
OS
Init
RUN! Shut
down
Linux booting process
BIOS (Basic Input/Output System):
when we power on, BIOS performs a Power-On Self-Test
(POST) for all the different hardware components in the
system to make sure everything is working fine
Begin searching for an operating system Boot Sector on
a valid master boot sector on available drives like hard
disk, CD ROM drive
Once BIOS finds a valid MBR it will give instructions to
boot and execute the first 512 byte boot sector that is
the first sector.
Linux booting processcntd
MBR (Master Boot Record)
Searches for valid primary partition marked as bootable
on the hard disk.
When found then it executes the first 512 bytes of that
partition which is second level MBR
In linux two types of second level MBR known as LILO
(Linux Loader) or GRUB(Grand Unified Bootloader)
Linux booting processcntd
LILO: LInux LOader
A versatile boot manager that supports:
Choice of Linux kernels.
Boot time kernel parameters.
Booting non-Linux kernels.
A variety of configurations.
Characteristics:
Lives in MBR or partition boot sector.
Has no knowledge of filesystem structure so
Builds a sector map file (block map) to find kernel
Loads kernel into memory and starts it.
/sbin/lilo map installer.
/etc/lilo.conf is lilo configuration file.
Linux booting processcntd
Kernel:Once GRUB/LILO transfers control to kernel
It initializes devices and loads initrd module
Mounts root file system
Init
First process which is started in Linux
Kernel once loaded finds init in sbin (/sbin/init) and
executes it
Init process reads /etc/inittab file and sets the path,
starts swapping, checks file system and starts the system
on specified run level
Runs all the boot scripts (/etc/rc.d/*, /etc/rc.boot/*)
Startup scripts/runcontrol/rc files in Linux
Files and directories Description
/etc/sysconfig Directory that holds system configuration files and directories
/etc/rc.d Directory that holds system startup and shutdown files
/etc/rc.d/rc.sysinit Initialization files for your system
/etc/init.d/rc.local Initialization file for your own commands, editable file to add your own startup commands; last
startup file executed
/etc/init.d Directory that holds network scripts to start network connections
/etc/rc.d/rcnum.d Directory for different runlevels, where num is a runlevel
/etc/init.d/halt Operations to be performed each time you shutdown the system eg. Unmounting file system
Linux has number of startup scripts which are files located in /etc/rc.d directory and
some others in sub directory init.d. These are all initialization files organized according to
different task to control daemons. They provide control and monitor the system and
invokes other required processes for that particular level or environment.
Run levels in Linux
Controls transitions between runlevels:
0: shutdown
1: single-user
2: multi-user (no NFS).. Same as 3, w/o networking
3: full multi-user with networking services. Default on
RedHat Server
5: X server and presents a graphical login window.
Default for RedHat linux workstation
6: reboot
Run level can be set by defining it on /etc/inittab
file
More about /sbin/init
Ultimate parent process.
Always the first process that gets started with process id
always 1
Linux allows processes to provide a return code for their
parent (wait). So process context must remain in the kernel
until the parent joins the child. Orphan processes
resulting from early parent death are inherited by init.
Handles various run levels by executing the appropriate
programs when a particular runlevel is reached. This
behavior is defined by /etc/inittab file.
Basics of /etc/inittab file
Format for enteries in /etc/inittab file
Id : runlevels : action : process
Where
Id: is identification code
Runlevel: list of runlevels for which this entry applicable
Action: how to treat the process
Process: process to run for this entry
Eg.
L0:0:wait:/etc/init.d/rc 0
Options available for action field in /etc/inittab file
Values for action field Description
Respawn Process will be started whenever it terminates
Wait Process will be started once when runlevel is entered and init will wait for its completion
Once Process will be started once when runlevel is entered and init wont wait for its completion before
executing additional programs
Boot Process will be executed at system boot. Runlevel field is ignored in this case
Bootwait Process will be executed at system boot and init will wait for completion of boot before advancing to
next process to be run
Ondemand Process will be executed when a specific runlevel request occurs
Initdefault Specifies the default runlevel for init or startup. If no default specified then user will be prompted
Sysinit Process will be executed during system boot, before any of the boot or bootwait entries
Powerwait If init receives a signal from another process that there are problems with the power, this process will
be run. Before continuing, init will wait for this process to finish
Powerfail Same as powerwait, except that init will not wait for the process to finish
Powerokwait If init receives the same type of signal as powerwait, when a file called /etc/powerstatus exists with the
string OK in it, this process will be executed and init will wait for its completion
Ctrlaltdel Process is executed when init receives a signal indicating that the user has pressed CTRL_ALT_DEL
Example lilo.conf File
boot=/dev/hda
map=/boot/map
install=/boot/boot.b
prompt
timeout=50
default=linux
image=/boot/vmlinuz-2.2.12-20
label=linux
initrd=/boot/initrd-2.2.12-20.img
read-only
root=/dev/hda1
Adding kernel to LILO
1. Load /etc/lilo.conf into text editor
2. In the existing stanza, modify the label=line to give
the copy a new name
3. Change the image=line to point to new kernel file
4. Change any other option if need be. Eg. If youve
prepared a new RAM disk, change initrd=line to
point it
5. Save your changes and exit from editor
6. At root command prompt, type lilo. This cmd
installs LILO in MBR
Difference between LILO and GRUB
LILO GRUB
No interactive command interface Interactive command interface
Does not support booting from a
network
Does support booting from a
network
If any change in LILO config file,
then LILO stage one boot loader to
the MBR has to be rewritten
Automatically detects any change
in config file and auto loads the OS
Supports only linux OS Supports large number of OS
Configuration file: /etc/lilo.conf Configuration file:
/boot/grub/grub.conf OR
/boot/grub/menu.lst
Shut down or rebooting ways in Linux
Turning off the power
Using the shutdown command
Using the halt and reboot commands
Using telinit to change inits run level
Using power off command to tell the system to turn
off the power.
Shutdown process in Linux
Easiest way: enter the desired run level in command
line i.e.cmd: /sbin/init 0 to power down and
/sbin/init 6 to reboot. This doesnt inform the user.
Practical way: shutdown cmd. This broadcasts to all
users that run level is about to change
Shutdown cmd tells init to change the current run
level. Eg.
Shutdown r now : shutdown and reboot now
Shutdown h 5 : shutdown and halt the system in 5mins
Shutdown c : cancels a running shutdown
Shutdown k : doesnt shutdown but sends a broadcast
Shutdown
Shutdown inhibits login, asks init to send SIGTERM
to all processes, then SIGKILL.
Reboot command: to shutdown and reboot system
Halt command: to halt. Performs essential duties
required to bring the system down. It logs
shutdown, kills non-essential processes, executes
the sync system call, waits for filesystem writes to
complete and then halts the kernel
Ctrl-Alt-Delete Vulcan neck pinch:
defined by a line in /etc/inittab.
ca::ctrlaltdel:/sbin/shutdown -t3 -r now.