Linux

Booting of Linux

In this page, we will discuss the bootstrapping of the Linux operating system with GRUB. After that we will proceed to processes of starting up and shutting down the Linux.

BOOT LOADERS

The boot loader is the first software program that runs when a computer starts. It is accountable for transfer control of the system to the operating system. Boot loader knows how to get the operating system up and running.

Master Boot Record (MBR)

How your Computer knows where is boot loader. Boot loader is reside in the MBR. Master Boot Record is located in the first sector of your PC's hard disk. First sector of the partition where you loaded Red Hat Linux

GRUB

Most modern Linux distributions use GRUB as the default boot loader during installation.

The Linux Boot Sequence

When a computer powers up, the hardware transfers control to a BIOS program, which resides in ROM. The BIOS scans the list of boot devices as defined in boot menu and looking for a boot loader. For each device, the BIOS will read the very first sector of the drive, called the boot sector, looking for the first one that provides a boot loader. The job of boot loader is to load the operating system into memory and start it running. Once loaded into RAM and started by the bootloader, the Linux kernel performs a sequence of actions as it starts:
  • It scans the hardware configuration, initialises device drivers.
  • It takes the CPU into protected mode with virtual memory.
  • It mounts the root file system (read only).
  • Once these preparations are completed, the Linux kernel starts a user process, /sbin/init, which is responsible for starting everything else.
  • The init program has process id 1, you can check with the help of pidof init command.
  • The init program is the root of the process tree. All processes running on the computer are descended from init. init remains in existence until the computer is halted.
  • When init is started, init looks for the file /etc/inittab for instructions on how to proceed.

Important files and Directories

In this section we will discuss the important files one by one.

grub.conf

Full path /etc/grub.conf , contain boot information. It contain many settings, you should know this in order to change the default settings.
Linux grub.conf
grub.conf

Descriptions lines after # like a comment. default=0 (default= 0 linux would be start, if deafault=1 were written then other operating system would have started )
timeout=5 (only 5 second to select operating system otherwise default will start, This can be interrupted by pressing any key on the keyboard before the counter runs out.)
splashimage=(hd0,0)/grub/splash.xpm.gz (this is the screen would appear at the time selection)
title Red Hat Enterprises This is used to display a short title or description for the following entry it defines.
root (hd0,0) (tells GRUB that the kernel is on the first partition of /dev/hda or /dev/sda)
kernel (Used for specifying the path to a kernel image.
initrd The initrd option allows you to load kernel modules from an image, not the modules from /lib/modules.

inittab

full path /etc/inittab.
# inittab       This file describes how the INIT process should set up
#               the system in a certain run-level.
#
# Author:       Miquel van Smoorenburg, 
#               Modified for RHS Linux by Marc Ewing and Donnie Barnes
#

# Default runlevel. The runlevels used by RHS are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
# 
id:5:initdefault:

# System initialization.
si::sysinit:/etc/init.d/rcS

l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6

# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now

# When our UPS tells us power has failed, assume we have a few minutes
# of power left.  Schedule a shutdown for 2 minutes from now.
# This does, of course, assume you have powerd installed and your
# UPS connected and working correctly.  
pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"

# If power was restored before the shutdown kicked in, cancel it.
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"


# Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6

# Run xdm in runlevel 5
x:5:respawn:/etc/X11/prefdm -nodaemon
runlevel
0 - halt (Do NOT set initdefault to this)
1 - Single user mode (like a safe mode of windows)
2 - Multiuser, without NFS (The same as 3, if you do not have networking)
3 - Full multiuser mode (without graphics or X windows )
4 - unused
5 - Full multiuser mode with X windows
6 - reboot (Do NOT set initdefault to this)
A runlevel of initdefault is selected. The default runlevel that the system boots into is determined by the initdefault entry in the /etc/inittab file.
Let us explorer the file contents.
Linux inittab file run level
Run levels

Lines in inittab have the form
id : runlevel(s) : action : command
  • The id is just a convenient identifier, with no particular meaning to init.
  • The command is a command to be executed, either a program or a shell script.
  • Runlevel and action control when and how command is executed. This will become clear as we continue.
The /etc/rc.d/rc is responsible for calling the appropriate scripts in the correct order for each runlevel. For each runlevel, a subdirectory exists in the /etc/rc.d directory.
/etc/rc.d/rc3.d
rc X .d

for further learning you can download full document download


/var/log/messages

This is log file of real time. Use tail command to check the bottom part of file.
[root@localhost /mohit]# tail -f /var/log/messages






admin