{"id":7084,"date":"2017-10-11T18:33:31","date_gmt":"2017-10-11T10:33:31","guid":{"rendered":"http:\/\/rmohan.com\/?p=7084"},"modified":"2017-10-11T18:33:31","modified_gmt":"2017-10-11T10:33:31","slug":"linux-boot-process","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7084","title":{"rendered":"Linux Boot Process"},"content":{"rendered":"<p>***************<br \/>\nSummary<br \/>\n=======<\/p>\n<p>A) START &#8211; BIOS  (Basic Input Output System) = when BIOS load in RAM Called BOOT STARPPING &#8211;  CMOS =  Called this process KERNAL LANDING &#8211;<br \/>\n    MBR in Hard Disk &#8211; BOOTLOADER &#8211; KERNEL &#8211; INITRD IMAGE &#8211; Inittab = Upto this process called  USER LANDING<\/p>\n<p>B) There are two tyeps of boot loader in linux    <\/p>\n<p>       a) LILO<br \/>\n                 i) 1st stage<br \/>\n                  ii) 2nd stage<\/p>\n<p>       b) GRUB<br \/>\n                 i) 1st stage<br \/>\n                  ii) 1.5 stage(This stage is optional)<br \/>\n                 iii) 2nd stage            <\/p>\n<p> Scratch \\ start<br \/>\n============<br \/>\nA) Power on by USER<\/p>\n<p>B) Power goes into SMPS.<\/p>\n<p>C) Power goes into MOTHERBOARD.<\/p>\n<p>D) Power goes then into CPU&#8217;s single pin.<\/p>\n<p>E) Then CPU awakes BIOS.<\/p>\n<p>F) Bios goes into RAM and start POST (power on self test) &#8212;>means BIOS will<br \/>\n    check all hardware and periferels. This step is called BOOTSTRAPPING.<\/p>\n<p>G) Then Bios goes into CMOS (Complementary metal.oxide.semiconductor) to check<br \/>\n    the which device load in RAM. We can change the CMOS. CMOS is samll program<br \/>\n    which take the information from Bios. CMOS battery supply power to CMOS<br \/>\n    program. Therefore always change the CMOS battery after every 6 months.<br \/>\n    Bios read the CMOS program for load the device.<\/p>\n<p>H) BIOS load first sector \/ first track \/ 0 cylinder of harddisk ie. MBR(master boot record) into RAM.     <\/p>\n<p>    a) MBR size is 512 MB. It divided into three parts:-<br \/>\n    1) Bootsector(446 bytes),partition table(64 bytes),magic number(2 bytes)<br \/>\n        Where boot sector contains boot loader (LILO or GRUB for linux and NTLDR<br \/>\n        for windows)<br \/>\n    2) Partion table contains 4 programs of 16 bytes.So we can create only 4<br \/>\n        partition in a harddisk,ie four  primary partition and last primary will<br \/>\n        be extended by logical partition<br \/>\n    3) Magic number of 2 bytes contais 0 or 1.If 0 means no and 1 means yes.<br \/>\n        If bootsector and partition table in MBR contains errors then magic<br \/>\n        number will be 0 otherwise 1.<\/p>\n<p>##############################################################################<br \/>\n               MBR(master Boot Record) First secter of harddisk=512 bytes<br \/>\n               ********************************************<br \/>\n             446 bytes &#8211; Boot sector &#8211;<br \/>\n                      LILO or GRUB for linux and NTLDR for windows<br \/>\n         ===========================================================================        <\/p>\n<p>     64 bytes &#8211; Partition table &#8211;<br \/>\n              1st primary partition 16 bytes<br \/>\n              2nd primary partition 16 bytes<br \/>\n             3rd primary partition 16 bytes<br \/>\n              4th primary partition 16 bytes \/ extended partition can  be subdivided into logical partitions<br \/>\n         ===========================================================================<br \/>\n             2 bytes &#8211; Magic number &#8211;<br \/>\n                           If bootsector and partition table in MBR contains errors  |<br \/>\n                 then magic number will be 0 otherwise 1.   <\/p>\n<p>#################################################################################<\/p>\n<p>I) Bios first check whether magic number is yes or no in MBR<br \/>\n   If yes it will go for active partition in partition table else displays<br \/>\n   error as boot failure. Active partition denoted by * in partition table<br \/>\n   of linux and in windows C drive by default.<\/p>\n<p>J) Then goes into first sector of active partition and whatever finds in first<br \/>\n    sector of active partition loads in RAM. But its same MBR are there. So<br \/>\n    BIOS goes to boot sector of MBR. IN boot sector, there is boot-loader<br \/>\n    LILO or GRUB for linux and TLDR for windows. Bios load LILO\/GRUB into RAM<br \/>\n    for linux and ntldr for windows. NTLDR load windows.<\/p>\n<p>K) In linux ANACONDA INSTALLER load LILO\/GRUB in MBR while the time of<br \/>\n    installation. LILO\/GRUB is powerfull than ntldr. In dual boot first install<br \/>\n    windows then install linux.<\/p>\n<p>L) Bios load  LILO\/GRUB into RAM. This is called the FIRST STAGE OF BOOT<br \/>\n    PROCESS. The purpose of first stage to load Second Stage ie boot.b.<\/p>\n<p>M) LILO have a Map Code file. In this file have a address of &#8216;boot.b&#8217; in CHS<br \/>\n    format. LILO can not read this format. Therefore call the Bios to read<br \/>\n    this file. If you change the path of LILO in configuration file then you<br \/>\n    need to re-read LILO conf file. Using this command &#8216;\/$ lilo -v&#8217;<\/p>\n<p>N) Bios read map code and load BOOT.B file in RAM. This step called SECOND<br \/>\n    STAGE OF BOOT PROCESS.<\/p>\n<p>O) Map and Message these two file locate in the Boot.b file. Once again boot.b<br \/>\n    can&#8217;t read these two files, therefore boot.b file again call the Bios for<br \/>\n    read this two files. Bios read this files and load into RAM. Message file<br \/>\n    show the splash screen to select the OS.<\/p>\n<p>           ##########################################<br \/>\n             Prompt message<br \/>\n            ************<br \/>\n        Timeout (in seconds)<br \/>\n        Default OS (if you not select any os)<\/p>\n<p>    =============================================<br \/>\n         \/boot\/boot.b (2nd stage of boot loading)<br \/>\n    =============================================<br \/>\n         \/boot\/map              |  \/boot\/message<br \/>\n        \/boot\/boot.0300    |  \/boot\/boot.0800<br \/>\n    =============================================<\/p>\n<p>          ###########################################<\/p>\n<p>P) After slecet the linux os boot.b load the Linux Kernal in RAM. Kernal<br \/>\n    located in \/boot\/vmlinuz-2.4.20-8, in comparc&#8217;d format. At the loading time<br \/>\n    LILO un-comparc&#8217;d it and load into RAM.<br \/>\n    This steps called KERNEL LANDING.<\/p>\n<p>Q) Once kernel load into RAM then kernel himself load the INITRD IMAGE in RAM.<br \/>\n    Initrd image also in comparc&#8217;d format. Initrd image have a linuxrc script.<br \/>\n    Initrd image run the linuxrc script.<\/p>\n<p>R) Linuxrc script load ext3.o filesystem, jbd.o harddisk driver and others<br \/>\n    *.o driver. Linuxrc script mount &#8216;\/&#8217; as a read only partition, it is call<\/p>\n<p>S) Init &#8211; System Daemon this script run by linuxrc script<br \/>\n    (located at \/sbin\/init )<\/p>\n<p>       a) Inittab this is a script file at \/etc\/inittab<\/p>\n<p>     1) check default runlevel<\/p>\n<p>             2) RC.SYSINIT this is a important file for boot<br \/>\n         processing. This file read only one time at the<br \/>\n          booting time and located at \/etc\/rc.d\/rc.sysinit.<br \/>\n           (as a sub-shell ). This script called &#8216;systemv&#8217;.<\/p>\n<p>               i) Network &#8211; reload the \/etc\/sysconfig\/network this file<br \/>\n                      Set the hostname, this file run command $ hostname,<br \/>\n                      if hostname found then set it, else set the default<br \/>\n                      hostname i.e. &#8216;localhost&#8217;<\/p>\n<p>              ii) mounts &#8216;\/proc&#8217; filesystem (command mount -n -t proc \/proc \/proc)<\/p>\n<p>              iii) \/etc\/init.d\/functions (same env)<br \/>\n                      After finish the proc mounting inittab run this file.<br \/>\n                      This cmd set around 23 functions.<\/p>\n<p>            iv) global  UMASK<br \/>\n             v) global PATH<br \/>\n             vi) defines 17 shell functions<br \/>\n                    1) success<br \/>\n                      2) failure<br \/>\n                      3) passed<br \/>\n                     4) warning<br \/>\n                               5) echo_success<br \/>\n                     6) echo_failure<br \/>\n                     7) echo_passed<br \/>\n                                 8) echo_warning<br \/>\n                                  9) killproc<br \/>\n                                 10) pidofproc<br \/>\n                                11) pidfileofproc<br \/>\n                                 12) action<br \/>\n                                13) checkpid<br \/>\n                                 14) confirm<br \/>\n                                 15) status<br \/>\n                                 16) strstr<br \/>\n                                 17) daemon<br \/>\n              vii) \/etc\/redhat-release<br \/>\n                         This cmnd display redhat version<br \/>\n                         which install your system.<\/p>\n<p>            viii) Then display interactive mode to<br \/>\n                        customize start. Press &#8216;I&#8217; option to<br \/>\n                            boot manually.<\/p>\n<p>             ix) Set Localtime \/etc\/localtime<br \/>\n                                          &#8216;hwclock&#8217; &#038; &#8216;date&#8217; cmnd change<br \/>\n                                          \/etc\/localtime &#038; \/etc\/adjtime file.<\/p>\n<p>                    x) \/proc -to check kernel parameters<\/p>\n<p>                                         xi) \/etc\/sysctl.conf -for kernal tunning<\/p>\n<p>                             xii) Keyboard Mapping<\/p>\n<p>                    xiii) FASTBOOT &#8211; if we create a blank<br \/>\n                             file as a &#8216;fastboot&#8217; in &#8216;\/&#8217; then<br \/>\n                             fsck not process<\/p>\n<p>             xiv) \/etc\/sysconfig\/readonly-root<br \/>\n                             &#8211; rwtab file, all file system<br \/>\n                            mounted as a read only<\/p>\n<p>            xv) \/etc\/rwtab.d\/* &#8211; some exceptional<br \/>\n                               files in read write mode<\/p>\n<p>            xvi) FSCK &#8211; goto fstab and check the<br \/>\n                              parameter in 5th column if there are<br \/>\n                               &#8216;1&#8217; then run fsck cmnd, else check<br \/>\n                               next line.<\/p>\n<p>            xvii) Mounting tmpfs &#8211; \/dev\/shm shared<br \/>\n                                application memory.<\/p>\n<p>            xviii) Read \/etc\/fstab file and remounts<br \/>\n                                 &#8216;\/&#8217; read-write mode and all others<br \/>\n                                   partition.<\/p>\n<p>            xix) Quota on.<\/p>\n<p>            xx) Enableing SWAP partition.<\/p>\n<p>            xxi) \/bin\/dmesg &#8211; \/var\/log\/dmesg<br \/>\n                                 collect hardware info from<br \/>\n                                             BIOS and display.                <\/p>\n<p>      b) RC  scripts &#8211; \/etc\/rc.d\/rc ( as a subshell )<br \/>\n          RC manage the which services started and which not started.<br \/>\n          This script read any time.<\/p>\n<p>           i) checks runlevel ( function )<\/p>\n<p>           ii) finding previous runlevel<\/p>\n<p>           iii) \/etc\/init.d\/functions (same env)<\/p>\n<p>           iv) checks user confirmation mode and<br \/>\n                               interactive mode \/ startup. Setting new runlevel<\/p>\n<p>           v) \/etc\/rc.d\/rc3.d\/K* (K &#8211; means stop)<br \/>\n                This is used for stop. However here are 5 functions<br \/>\n             1) STOP<br \/>\n              2) START<br \/>\n              3) RESTART<br \/>\n              4) STATUS<br \/>\n              5) CONDRESTART<\/p>\n<p>          vi) \/etc\/rc.d\/rc3.d\/S* (S &#8211; means start)<br \/>\n                    This is used for start only. Same as above. However<br \/>\n                     some files are in this directory, those are symblink<br \/>\n                     with some files that located in &#8216;\/etc\/init.d\/&#8217;. These<br \/>\n                     files called Init Script file. These files<br \/>\n                      run by \/etc\/init.d\/function cmd<\/p>\n<p>        vii) \/usr\/bin\/rhgb-client functions,used only stop<br \/>\n                   ( start<br \/>\n                          stop<br \/>\n                          restart<br \/>\n                          status<br \/>\n                          condrestart )<\/p>\n<p>              viii) \/etc\/rc.d\/rc.local this is a last file<br \/>\n                 run by rc script. If you want to run some cmnd<br \/>\n                 automatic then you can enter those cmnd or scirpt<br \/>\n                  in this file.<\/p>\n<p>    c) Now part ofthe \/sbin\/init call \/etc\/inittab file. inittab read<br \/>\n            \/sbin\/shutdown -t3 -r now<br \/>\n            poweroff considerations &#8211; \/sbin\/shutdown -f -h +2<br \/>\n           poweron considerations &#8211; \/sbin\/shutdown -c<br \/>\n            power ok wait<br \/>\n            Now inttab read following line in his file<br \/>\n           1:2345:respawn:\/sbin\/mingetty tty1<br \/>\n            IF runlevel 5 then &#8211;  \/etc\/X11\/predfm -nodaemon<\/p>\n<p>I) Inittab call MINGETTY<br \/>\n            a) loads \/dev\/tty1<br \/>\n            b) Reads \/etc\/issue file<br \/>\n            c) \/bin\/login<br \/>\n                  1) \/usr\/bin\/passwd<br \/>\n                                  i)PAM (Plugabel Authantication Module) security.<br \/>\n                            ii) \/etc\/passwd<br \/>\n                            iii) \/etc\/shadow<br \/>\n                             iv) \/etc\/group<br \/>\n                             v) \/etc\/gshadow<\/p>\n<p>     d) puts login daemon in sleep state<\/p>\n<p>     e) root\/.hushlogin exists ? Ja! mail,motd,lastlog NOT RUN!<\/p>\n<p>     f) \/etc\/motd (Message of the day)<\/p>\n<p>              g) lastlog* using \/var\/log\/lastlog<\/p>\n<p>     h) Checks user&#8217;s mail &#8211; \/var\/spool\/mail\/root<\/p>\n<p>     i) wakes the \/bin\/login process which forks off as<br \/>\n        independent application daemon &#038; mingetty goes to Zombie state.<\/p>\n<p>              2) login calls \/bin\/bash<br \/>\n                             puts login to sleep state<\/p>\n<p>        3) \/etc\/profile (global sets HOSTNAME, HISTSIZE, PATH etc)<br \/>\n                 a) \/etc\/inputrc (sets keyboard mappings)<br \/>\n                 b) \/etc\/termcap (sets term. capabilities)<br \/>\n                 c) \/etc\/profile.d\/*.sh ( 13 files )<br \/>\n                                                 customize *.sh files<br \/>\n                                      ( colorls.sh<br \/>\n                                                      vim.sh<br \/>\n                                                    glib2.sh<br \/>\n                                                         gnome-ssh-askpass.sh<br \/>\n                                krb5.sh<br \/>\n                                                         lam.sh<br \/>\n                                                         lang.sh<br \/>\n                                                         less.sh<br \/>\n                                                         mc.sh<br \/>\n                                                         pvm.sh<br \/>\n                                                         qt.sh<br \/>\n                                                         vim.sh<br \/>\n                                                         which-2.sh<br \/>\n                                                         xpvm.sh )<\/p>\n<p>J) \/etc\/bash.rc &#8211; global shell<\/p>\n<p>         a) umask &#8211; permission set<br \/>\n             1) root -0 &#8211; 0022<br \/>\n              2) above uid 99 (user) &#8211; 0022<\/p>\n<p>          b) PS1 &#8211; define veriable (roota@localhost#). we can change &#8216;#&#8217; to &#8216;$&#8217;<br \/>\n                 i.e. &#8216;root@localohost$&#8217;<\/p>\n<p>K) Users profile<br \/>\n     a)  \/root\/.bash_profile<br \/>\n     b)  \/root\/.bashrc<br \/>\n     c)  \/root\/.bash_history<br \/>\n     d)  \/root\/.bash_logout<\/p>\n<p>    ========================<br \/>\n    END OF THE BOOT PROCESS.<br \/>\n    ========================<\/p>\n","protected":false},"excerpt":{"rendered":"<p>*************** Summary =======<\/p>\n<p>A) START &#8211; BIOS (Basic Input Output System) = when BIOS load in RAM Called BOOT STARPPING &#8211; CMOS = Called this process KERNAL LANDING &#8211; MBR in Hard Disk &#8211; BOOTLOADER &#8211; KERNEL &#8211; INITRD IMAGE &#8211; Inittab = Upto this process called USER LANDING<\/p>\n<p>B) There are two tyeps of [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7084"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7084"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7084\/revisions"}],"predecessor-version":[{"id":7085,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7084\/revisions\/7085"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7084"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}