RedHat Linux - Boot Process
RedHat Linux - Boot Process
Procedure
Roadmap
Bootstrapping
Boot Loaders
Startup/Init Scripts
Reboot & Shutdown
Q&A
How Linux boot?
Booting sequence
1. Turn on
2. CPU jump to address of BIOS (0xFFFF0)
3. BIOS runs POST (Power-On Self Test)
4. Find bootable devices
5. Loads and execute boot sector form MBR
6. Load OS
BIOS (Basic Input/Output System)
BIOS refers to the software code run by a computer when first
powered on
The primary function of BIOS is code program embedded on a chip
that recognises and controls various devices that make up the
computer.
MBR (Master Boot Record)
OS is booted from a hard disk, where the Master
Boot Record (MBR) contains the primary boot
loader
The MBR is a 512-byte sector, located in the first
sector on the disk (sector 1 of cylinder 0, head 0)
After the MBR is loaded into RAM, the BIOS yields
control to it.
MBR (Master Boot Record)
MBR (Master Boot Record)
The first 446 bytes are the primary boot loader, which contains both
executable code and error message text
The next sixty-four bytes are the partition table, which contains a
record for each of four partitions
The MBR ends with two bytes that are defined as the magic number
(0xAA55). The magic number serves as a validation check of the MBR
Boot loader
Boot loader could be more aptly called the kernel loader.
The task at this stage is to load the Linux kernel
root=/dev/hda1
timeout=5
image=/boot/vmlinuz-2.6.20
label=Linux
read-only
other=/dev/hdb1
label=Windows
table=/dev/hdb
To install it
$ lilo
filename
GRUB device (hd0,0) → /dev/hda1 or /dev/sda1
To install GRUB (for the very first time)
$ grub-install ‘(hd0,0)’
Edit /boot/grub/grub.conf
Boot Loaders – GRUB (cont)
/boot/grub/grub.conf
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-8.el5 ro root=LABEL=/
initrd /boot/initrd-2.6.18-8.el5.img
title Windows
rootnoverify (hd1,0)
chainloader +1
Boot Loaders – GRUB (cont)
At the splash screen
Hit ‘a’ and type “ single” to boot to single-user mode
Hit ‘c’ to enter command-line mode
To boot other OSes that aren’t in grub.conf
Display system information
Press TAB to see possible commands
Kernel Initialization
A program itself
/vmlinuz or /boot/vmlinuz
Two-stage loading process
initrd (init RAM disk)
A transient root filesystem in RAM before a real root filesystem is
available
Eg. It is used to install file system modules into the kernel
The real root filesystem
Device detection and configuration
You tell the kernel what to expect
The kernel probes the H/W itself
Kernel threads creation
Eg. init (a user process), kjournald, kswapd
Task of kernel
Process management
Memory management
Device management
System call
Single-user mode
A manual mode after kernel initialization and before
running startup scripts
“single” is passed to init, sulogin is run instead
Most system processes are not running
Users can’t log in, except root
/ is mounted read-only
$ mount -o rw,remount /
Check/repair the disk if there are disk problems
$ fsck -y /dev/sda1
Run ‘exit’ to exit single-user mode
Startup/Init Scripts
After Kernel initialization, a process called init is
created with PID 1
init runs startup scripts (normal shell scripts) to
perform specific tasks, eg.
Setting the hostname, time zone, etc
Checking and mouting the disks
Configuring network interfaces
Starting up daemons and network services
Startup/Init Scripts (cont)
Startup scripts (rc files) are run based on run levels
0 the level in which the system is completely shut down
1 single-user mode
2 multiuser mode w/out NFS
3 full multiuser mode
4 unused
5 X11
6 reboot level
Starts with run level 0 to the default run level (usually 3)
/etc/inittab tells init what to do at each level
To find out which run level the system is current in
$ runlevel
Startup/Init Scripts (cont)
init runs the scripts from /etc/rc.d/rc[0-6].d/
/etc/rc.d/rc0/K25sshd → /etc/init.d/sshd
/etc/rc.d/rc3/S55sshd → /etc/init.d/sshd
Each server/daemon provides a master script
Stored in /etc/init.d
Understands the arguments: start, stop, restart
/etc/init.d/sshd start
run level 0 → 3
/etc/rc.d/rc3/S* start
run level 3 → 0
/etc/rc.d/rc0/K* stop
Pretty ugly!
Startup/Init Scripts (cont)
Use chkconfig instead. Eg.
$ chkconfig --add sshd
$ chkconfig --del sshd
Before that, need to add/modify /etc/init.d/sshd
# chkconfig: 2345 55 25
sshd should be started/stopped at run level 2, 3, 4 and 5 with the
start priority of 55 and the stop priority of 25
Reboot & Shutdown
To reboot
$ shutdown -r now
$ reboot
$ telinit 6
To halt
$ shutdown -h now
$ halt
$ telinit 0
$ poweroff
Reboot & Shutdown (cont)
To shutdown gracefully
$ shutdown -h +15 “Shutdown in 15 mins”