01 BOOT Process Ver 1
01 BOOT Process Ver 1
======
Part I
======
01. Power On
02. ROM - BIOS loaded into RAM auto by the boot code at the start of ROM
[bootstrap]
Purpose of BIOS : Load the OS - any/some OS
05. BIOS loads/starts [boots] whatever it finds in the first Sector [Sect 1]
of HDD into RAM i.e. [cylinder 0, head 0, sector 1 of a hard disk]
- This first Sector is aka the MBR [on Windows-based systems]
Note: There is only one MBR per HDD, obviously !!
0x228
<=========x=================== 512 bytes ========================>
| |
<-----446 bytes ---->| <--PT -64 bytes->| < Magic no 2 bytes--->
BS | PT | Magic #
| |
<============================ 512 bytes ========================>
M B R
2. LILO: /etc/lilo.conf
[/boot/boot.b] [binary format]
CHS# a. /boot/boot.b hda2 extended ok
b. /boot/message hda5 /boot
c. /boot/map hda6 /home
d. /boot/initrd-2.4.20-8.img hda7 swap
hda8 /
hda9 /tmp
hda10 /var
hda11 /usr
07. During installation, when the Linux kernel is being installed, its
exact size and location [CHS] on the HDD is stored in /boot/map
in the /boot partition.
Note: Every Partition on a HDD has a BS [First Sec] where one can put
the BL
- In our case here, the first Sector of the AP is also the BS of the MBR
AND NOT
11. Makes BIOS calls - Int 13 fn 8 --> "Get drive parameters" and -
Int 13 fn 2 --> "Read sectors from drive" -
which returns the disk geometry in 24-bit address format upto the
1024 cylinder limit.
Since you have enabled the LBA mode, 64-bit address format is used and
instead of the CHS way, BIOS reads the disk by numbering the sectors
from 1,2,3... etc
The requested info from this BIOS call is stored by the BIOS in the first
page of memory ( < 4k )
12 The first-stage loader then requests the BIOS for an Int 13 fn 2, gives it
the CHS # of the /boot/boot.map file
Now the BL speaks CHS and the BIOS speaks 24-bit addresses.
It is LBA which allows the BIOS to act as a speaker of both, CHS and
Linear Sector Addressing - using 64-bit addresses - Translator
13 BIOS loads this 2nd stage BL - from the CHS no supplied by the 1st stage
14. The 2nd-stage BL now loads the contents of the balance of the BS
into the RAM
/etc/lilo.conf
but the contents of the BS - which is the same file - but in binary form
and was put there by the installer
15. The 2nd stage BL now examines this binary-format-BS which contains
"lilo.conf" and follows the instructions given there !!
It requests BIOS for an Int 13h and gives it the CHS # of the
/boot/message file which BIOS promptly fetches and the 2nd stage BL
executes - This is the splash screen
16 The 2nd stage BL then executes the instructions it got from the BS
after the 1st stage had loaded it, and executes those instructions
/etc/lilo.conf
==============
prompt <--------- Display labels
or present lilo prompt so user can
interact with lilo
timeout=50 <--------- In decisecs
default=linux <--------- What to do after timeout
Default image to boot
boot=/dev/hda <--------- Where to install the 1st stage BL
or IPL when you do a /sbin/lilo -v
Here, in the BS of the MBR of Primary
Master HDD
To install in the MBR, specify /dev/hda
map=/boot/map <--------- Location of map file which contains
Size and location of kernel
install=/boot/boot.b <--------- Location of the 2nd Stage BL
L = First stage boot loaded and started. Usually indicates disk problems
or invalid options in /etc/lilo.conf.
LI = Second stage boot loaded from /boot, but /etc/lilo.conf has invalid
parameters or /boot/boot.b was moved without re-running /sbin/lilo.
LIL = Second stage loader started, but the descriptor table can't be
loaded due to a bad disk or invalid parms in /etc/lilo.conf.
LIL? = Second stage loaded at an incorrect address because of invalid
parms in /etc/lilo.conf or /boot/boot.b was moved without
re-running /sbin/lilo.
LIL- = Descriptor table is corrupt. Caused by invalid parms in
/etc/lilo.conf or /boot/boot.b was moved without re-running
/sbin/lilo.
LILO = All of LILO loaded correctly.
17. After timing out AND IF the default image is the Linux kernel, and IT IS
in the case above, the 2nd stage boot loader - /boot/boot.b -
loads the Linux kernel in RAM
BootLoaders load "kernel images" into mem and hand control of the CPU
over to the newly loaded kernel [/boot/vmlinuz-2.4.20.8]
To make your new kernel work, you must tell the BL about the kernel
19. Now the 2nd-stage wishes to load the kernel, as instructed by the
binary-format lilo.conf after timing out or whatever the user chooses
In /boot to be precise !!
And the 2nd-stage LILO BL has no idea how to access the HDD
Why ?
Hen-and-Egg situation !!
20 The 2nd stage BL has no choice but to use the BIOS as its HDD device
driver to access the HDD at boot time.
21. The 2nd stage BL once again requests BIOS - Int 13h fn 2 - and hands it
the CHS # of the /boot/map file, which BIOS loads
22. The 2nd stage loader now examines this /boot/map and extracts the
CHS # inside it - which was put there by the BL installer - anaconda -
and /sbin/lilo - and requests BIOS once more to load whatever is there
in that CHS # address
23 BIOS then loads the Linux kernel /boot/vmlinuz-2.4.20-8 into the RAM
and hands it to the 2nd stage BL
24 The 2nd stage BL uncomptars this file and fills the memory with kernel
mem structures which can be seen in the /proc virtual file system
To Part II --------->
/sbin/lilo
==========
What does /sbin/lilo do : 1. Reinstalls LILO - The 1st stage BL in BS of MBR
2. Examines /etc/lilo.conf and iff no errors then
compiles [ie converts to binary] and installs this
in the BS of the MBR near LILO
[map installer] 3. Re-creates the map file - /boot/map - by examining
/etc/lilo.conf for location of kernel
=============================
Part II /sbin/init takes over
=============================
25 Now that the Linux Kernel is in the RAM, and is much more powerful
and immensely larger than the 2nd stage BL, it takes over total control
from it and makes yet another BIOS call Int 13h fn 2 for the
file /boot/initrd-2.4.20-8.img
27 Note that the HDD driver is available now; Hence the kernel executes the
"linuxrc" script which mounts the "root" partition in R/O mode and
loads the /sbin/init* program into RAM
=======================================================================
/etc/inittab
============
id:3:initdefault:
# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit
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
ls:S:wait:/etc/rc.d/rc S
~:S:respawn:/sbin/sulogin
# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now
# If power was restored before the shutdown kicked in, cancel it.
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"
/etc/init.d/functions
=====================
1 action() {
2 checkpid() {
3 confirm() {
4 daemon() {
5 echo_failure() {
6 echo_passed() {
7 echo_success() {
8 echo_warning() {
9 failure() {
10 killproc() {
11 passed() {
12 pidfileofproc() {
13 pidofproc() {
14 status() {
15 strstr() {
16 success() {
17 warning() {
35 d. shutdown CAD magic keys are set - You can hack it if you wish
37 f. 6 mingettys are spawned with dev drvs ; all enter sleep state
- EXCEPT one
========
Part III
========
Note:
What is a getty? [RHL has agetty* [Alternate Linux getty]
mgetty* [Modem getty]
mingetty* [Minimal getty]
A getty is is a program that opens a tty port, prompts for a login name,
and runs the /bin/login command. It is normally invoked by init.
You will need to configure agetty or mgetty to listen on the serial ports,
because they are capable of responding to input on physical serial ports.
43 * init then puts the login daemon into sleep state, wakes up
mingetty which now takes over
To do it per-user:
=================
setterm -blength 0 [in per user .bash_profile]
or
xset b off [in GUI]
[bash -r, --noediting as args in /etc/passwd
7th field]
1. colorls.sh
2. glib2.sh
3. gnome-ssh-askpass.sh
4. krb5.sh
5. lam.sh
6. lang.sh
7. less.sh
8. mc.sh
9. pvm.sh
10. qt.sh
11. vim.sh
12. which-2.sh
13. xpvm.sh
57 .bash_history
58 .bash_logout
*****************************
Exercise
Q: When u press Alt+F2 and login in, which files are executed ?
A: /etc/issue
$HOME/.hushlogin iff not exists
=====================================================================
* mingetty checks for .hushlogin in $HOME
If $HOME/.hushlogin DOES NOT EXISTS then it does the foll :
- execs lastlog* -u $USER using /var/log/lastlog
- execs /etc/motd
- checks users mail, if any
=====================================================================
/etc/profile
/etc/inputrc
/etc/profile.d/*.sh [13 shell scripts executed]
/etc/bashrc
$HOME/.bash_profile
Misc: $HOME/.bash_history
$HOME/.bash_logout
$HOME/.bashrc
==============================
Miscellaneous Points to Note :
==============================
========================================
1. LILO to GRUB : Change your bootloader
========================================
a. # grub-install /dev/hda
If you re-install Win$, you must boot from a boot floppy and do a 'lilo -v'
========================================
2. GRUB to LILO : Change your bootloader
========================================
a. cp /etc/lilo.conf.anaconda /etc/lilo.conf
b. lilo -v [-t]
If you re-install Win$, no effect on Linux since MBR does not contain
code except for a small loader which loads the main grub in 2 stages :
=========================
3. To put a password in GRUB :
=========================
# grub-md5-crypt
>> vashi123
>> vashi123
Now copy / paste this readable but scrambled password in grub.conf
It is the md5 encrypted equivalent of 'vashi123'
==================
4. To uninstall Linux :
==================
==========================================================
5. LILO : To create a boot floppy if your boot loader is LILO
==========================================================
# uname -r
2.4.20-8
# mkbootdisk 2.4.20-8
Shorter version :
==========================================================
6. GRUB : To create a boot floppy if your boot loader is GRUB
Get a working floppy !
==========================================================
1. # mke2fs /dev/fd0
2. # mount /mnt/floppy
3. # cd /mnt/floppy
4. # mkdir -p boot/grub
5. # cd /boot/grub/
6. # cp stage1 /mnt/floppy/boot/grub/
7. # cp stage2 /mnt/floppy/boot/grub/
8. # cp grub.conf /mnt/floppy/boot/grub/
9. # grub --batch << EOT
> root (fd0)
> setup (fd0)
> quit
> EOT
The moment you press Enter, a Boot grub floppy is created.
Boot with it to test it!
===================================
7. To Change the splash screen in grub :
===================================
* /usr/bin/identify -v bear.jpg
* /usr/bin/convert
* /usr/bin/animate
* /usr/bin/composite
* /usr/bin/conjure
* /usr/bin/display
* /usr/bin/import
* /usr/bin/mogrify
* /usr/bin/montage
Consider bear.jpg
3. Copy it to /boot/grub/
# cp bear.xpm.gz /boot/grub/
4. Configure /boot/grub/grub.conf
splashimage=(hd0,11)/grub/bear.xpm.gz
5. reboot
==========
SOME HACKS
==========
1. # mv /sbin/init /usr/local/sbin/init
Four Steps :
l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
........................
l9:9:wait:/etc/rc.d/rc 9
B. Change RL from 3 to 9
id:9:initdefault:
D. Do this :
# cd /etc/rc.d/
# cp -a rc3.d rc9.d
********************************
********************************