Thursday, October 11, 2007

The Magical Linux Boot Sequence

Its been a long time,i wrote anything abt Linux itself in detail….
Today I want to suppress my hunger by highlighting the BOOT sequence of Linux OS from scratch…..till the Login promp appears…

1)On a very basic level BIOS(Basic Input/Output System) which is the interface between the Hardware and Software provides the basic set of instruction used by any flavor of OS through CMOS(Complementary Metal Oxide Semiconductor).The CMOS which is about 64 bytes grabs and stores the hardware peripheral configuration permanently powered by a small battery located in Motherboard.
It’s the magic of this battery that CMOS retains the setting like date,time etc.. even when PC is turned off .Thus BIOS Has performed the POST(Power On Self Test) and now it looks for peripherals and a device to BOOT from.
Remember , BIOS reads and execute the first physical sector (about 512 bytes )of the chosen boot device.

2)Now appear the BOOT Loader Components
Boot Loader is responsible for loading and starting Linux or any other OS successfully.

But how is Boot loader invoked... tats the question ?
Answer : Certainly in below two possible ways :

1)BIOS passes the control to IPL(Initial Program Loader) installed within the in MBR(Master Boot Record).
2)BIOS passes the control to another Boot Loader (like ntldr of Xp ,LILO of Suse) ,which passes the control to IPL installed in boot partition ( /boot of abt 514MB ).


Remember IPL must not exceed the space of 446bytes

3)Hence IPL for GRUB is the First stage of Linux whose vital function is to locate and load a SECOND STAGE boot Loader (the blue splash screen)which actually do the most of the work to boot the system…

4)The Grub Boot Screen
A graphical Splash screen can be accessed by pressing enter key when GRUB starts up from First Boot Loader.This screen has got bootable image stanzas which can also be edited temporarily .Here we can also set Grub Password at Grub Command Line.

5) Now GRUB reads the Grub configuration file i.e. /boot/grub/grub.conf….available on the only fs which GRUB can understand i.e ext2/ext3, FAT,minix,FFS and reiserfs.If this file is missing Boot Loader will leave us alone with GRUB command Line which
a)can be used to write temporary boot commands from scratch..
b)View contents of files on fs,
c)perform diagnostic tests
d)experiment with GRUB configurations if file is available…

6)NOW The Kernel(http://kernelcoder.blogspot.com/) initialization files generate some output which scrolls in microseconds…i.e Device drivers compiled into the kernel are called …and locate their corresponding devices. Successful locations of device logs output to the kernel message buffer.(/var/log/dmesg).But essential drivers for ext3 fs, LVM, Software RAID and SCSI controller supports comes in modules and Kernel gets these modules from /lib/modules/$(uname) path. BUT Linux kernel still has to mount the root fs???????????????

Hhhhahahahahahah Big Question ..answer to this will be available in my next BLOG

I will welcome guesses , answers and comments …


7)After all drivers are located and loaded successfully the kernel mount the root fs ro.

8)INIT ----The first Process with (PID)process ID =1 is then loaded and control is now handed over to INIT .
Init reads /etc/inittab .which defines the default runlevel to pop into.
And further child processes can be run further.

9)But who initializes the intended runlevel ?
Answer ….
The file /etc/rc.d/rc has the responsibility to run or initialize the default runlevel specified in /etc/inittab and also acknowledge to start/stop the services with change in the runlevel.
Moreover, Each runlevel has its own corresponding directory with its scripts to run the daemon programs in background.But /etc/rc.d/rc.sysinit has many countless tasks to perform before any runlevel could be started.
/etc/rc/rcX.d
And then Symbolic links in corresponding run level directories call the /etc/rc.d/init.d scripts with start and stop argument.
Now Custom scripts are always run from /etc/rc.d/rc.local before getting Login Prompt

10)By default , init process respawns the mingetty services defined in /etc/inittab for each 6 VC. And the First VC /dev/tty7 is reserved for X server(gdm).The contents displayed by each VC is defined by expandable content in /etc/issue.
The mingetty and getty services are run for mentioned terminals.They read their configuration file /etc/mingettydefs.

11) As per gettydefs file getty process determines the speed of Terminal and Login Prompt with username appears. As we Login with authentic password…the username and passwd are matched with /etc/passwd and /etc/shadow. If match is successful then ,the init run the process mentioned at the of field of /etc/passwd .And we get the bash shell in Linux and bourne in UNIX ….About Xp Login, I donnt know…..God knows…..or may be U.

That’s it guys hope u might have true eclectic blend of fun, excitement ,anxiety and Mindblowing Power booster capsules.

Do leave your valuable comments and modifications if applicable…….

Thanking You

Nitin (kevin)

1 comment:

JC said...

bravo... just like professionals ;)