BOOTPROCESS TREE

Linux Boot Process Tree V1.0
======================
By Multazim Abdul Rashid Deshmukh

Power on
|
SMPS (Switched Mode Power Supply)-Generates power for all hardware devices in PC
|
CPU RESETS – Program Counter of CPU points to Address of BIOS
|
BIOS from ROM loaded into RAM {boot strapping}
|
BIOS do POST – checks all hardware devices are working properly
|                         |
If Yes                     If not
|                         |
—————– |             boot process stops. Gives Beep codes
|
|
BIOS loads CMOS program into RAM–checks for 1st boot device (say HDD)
|
|
Cylinder 0 is read from backwards
BIOS reaches first 512 bytes of cylinder 0
|
|
MBR loads into RAM (from cylinder 0 sector 1 of HDD)
|        MBR has 3 parts: ——————————————–
| Boot Sector | Partition Table | Magic No   |
|                        |    |        |     |           |     |      |
|                        | 446 bytes   | 64 bytes        |    2 bytes |
|                          ——————————————–
|
Magic no is checked ————————————–|
|                                                      |
|                                         If it says no (other than 0x55AA)
If it says ok (hex form-0x55 AA)                    BIOS gives Message
Means Boot sector & Partition Table          “Non-bootable disk” or “No-System”
are written properly
|
|
BIOS checks for Active Partition in Partition Table
Goes to BS in AP
|
|
LILO Byte code from Boot sector loads into RAM-1st stage of boot loading. LILO byte code is /etc/lilo.conf file in binary form placed by anaconda.
|                                                         |
|                              During installation anaconda does 5 things
|                                                  |
|                            1) creates /etc/lilo.conf and puts a binry
|                               bytecode of it in bootsector.
|                            2) puts an exe at 0x228 for redirecting BIOS
|                               to lilo bytecode in dual boot system.
|                            3) puts CHS nos of /boot/boot.b, /boot/message
|                               /boot/map, /boot/initrd-***.img in bootsector
|                            4) Writes Partition table in MBR.
|                            5) checks sanity of BS & PT and writes ok i.e.
|                               0x55AA in magic no.
|
|—|
|–>LILO byte code gives CHS no. of /boot/boot.b to BIOS,
|   BIOS do int 13h fn8
|
|–>BIOS loads Binary file /boot/boot.b{2nd stage of boot loading}
|
|–> boot.b gives CHS no. of /boot/message to BIOS
|    BIOS do int 13h fn2
|
|–> Bios loads /boot/message –> splash screen is displayed
|
|->OS Labels will be shown
|->after timeout default OS will boot
|
|————————————|———-|
|                                                |
If it is linux then                            if it is windows then
|                                    Control goes to ntldr
|———–|
|
|–> boot.b gives CHS no. of /boot/map to BIOS
|    BIOS do int 13h fn2
|
|–> Bios loads /boot/map -> map file contains CHS no. and name of kernel
|    i.e. vmlinuz-****
|
|–> boot.b gives CHS no. of kernel to BIOS
|    BIOS do int 13h fn2
|
|–> BIOS loads kernel into RAM –now kernel takes control
|
|–>kernel gives CHS no. of initrd-***.img to BIOS
|   BIOS do int 13h fn2
|
|–>initrd is extracted into memory
|  |
|  |-> to see contents to /boot/initrd-***.img,run following cmnds:
|
|      # cp /boot/initrd-2.6.18-194.el5.img /tmp/
|      # cd /tmp
|      # mv initrd-2.6.18-194.el5.img initrd-2.6.18-194.el5.img.gz
|      # gunzip initrd-2.6.18-194.el5.img.gz
|      # mkdir funny
|      # cd funny
|      # cpio -id < /tmp/initrd-2.6.18-194.el5.img
|      # ll
|      # tree
|
|-> content of initrd file varies depending on Linux version
|   On Centos 5.5 I got following list:
|    .
|    |– bin
|    |   |– dmraid
|    |   |– insmod
|    |   |– kpartx
|    |   |– modprobe -> /sbin/nash
|    |   `– nash    —–> this is the mini shell
|    |– dev
|    |   |– console
|    |   |– mapper
|    |   |– null
|    |   |– ptmx
|    |   |– ram -> ram1
|    |   |– ram0
|    |   |– ram1
|    |   |– rtc
|    |   |– systty
|    |   |– tty
|    |   |– tty0
|    |   |– tty1
|    |   |– tty10
|    |   |– tty11
|    |   |– tty12
|    |   |– tty2
|    |   |– tty3
|    |   |– tty4
|    |   |– tty5
|    |   |– tty6
|    |   |– tty7
|    |   |– tty8
|    |   |– tty9
|    |   |– ttyS0
|    |   |– ttyS1
|    |   |– ttyS2
|    |   |– ttyS3
|    |   `– zero
|    |– etc
|    |– init –> this is an executable i.e. linuxrc script as in
|     |           Old versions of linux e.g. RH9. Now renamed.
|    |– lib
|    |   |– ata_piix.ko
|    |   |– dm-log.ko
|    |   |– dm-mem-cache.ko
|    |   |– dm-message.ko
|    |   |– dm-mod.ko
|    |   |– dm-raid45.ko
|    |   |– dm-region_hash.ko
|    |   |– ehci-hcd.ko
|    |   |– ext3.ko   ————-|
|    |   |– firmware               |–> important modules
|    |   |– jbd.ko    ————-|
|    |   |– libata.ko
|    |   |– mptbase.ko
|    |   |– mptscsih.ko
|    |   |– mptspi.ko
|    |   |– ohci-hcd.ko
|    |   |– scsi_mod.ko
|    |   |– scsi_transport_spi.ko
|    |   |– sd_mod.ko
|    |   `– uhci-hcd.ko
|    |– proc
|    |– sbin -> bin
|    |– sys
|    `– sysroot
|
|
— Four files are very important: /bin/nash, ext3.ko, jbd.ko and
|   init script (linuxrc script)
|
|   1) nash – Nash is a Minimal shell, it takes low memory. It is
|      used to run linuxrc script.
|   2) ext3.ko – kernel needs a driver file called ‘ext3.ko’ for
|      filesystems without which you cannot mount any partition.
|   3) jbd.ko – It’s a HDD disk driver file.
|   4) linuxrc (init) – It’s a Script file having commands using
|      ext3.ko and jbd.ko and function to ro mount / partition.
|      Go through init script.
|
|
|–> after linuxrc script is run,now kernel land is ready.
|
init      |
|——–| –> now kernel calls init daemon i.e. /sbin/init
|
|–>/etc/inittab is loaded by init into memory and executed.
|
|———-> default runlevel
|—-|—–> /etc/rc.d/rc.sysinit {as a sub-shell}
|    |
|    |–> HOSTNAME, HOSTTYPE is set
|    |–> /etc/sysconfig/network –> networking is enabled.
|    |–> mount –n –t proc /proc /proc
|    |–> mount –n –t sysfs /sys /sys >/dev/null 2>&1
|    |–> /etc/init.d/functions {same env}
|    |       |
|    |        |–> global umask
|    |       |–> global PATH
|    |       |–> defines 27 shell functions
|    |           to get the below list, run command:
|    |           cat /etc/init.d/functions | grep \(\)
|    |             success()  ————–|
|    |               failure()            |
|    |             passed()            |
|    |             warning()            |
|    |             echo_success()        |
|    |               echo_failure()        |
|    |                echo_passed()        |
|    |               echo_warning()        |–These 17 functions were
|    |             Killproc()            |  present in RH9 as well.
|    |             pidofproc()            |  rest 10 were added in
|    |             Pidfileofproc()        |  new versions of RHEL.
|    |             action()            |
|    |             Checkpid()            |
|    |             confirm()            |
|    |             Status()            |
|    |             strstr()            |
|    |             Daemon() —————-|
|    |                fstab_decode_str()
|    |                __readlink()
|    |                __umount_loop()
|    |             __umount_loopback_loop()
|    |                   __pids_var_run()
|    |             __pids_pidof()
|    |             update_boot_stage()
|    |             get_numeric_dev()
|    |                resolve_dm_name()
|    |                is_ignored_file()
|    |
|    |–> /etc/redhat-release
|    |–> press I to enter into interactive mode
|    |–> /etc/sysconfig/clock – sets system clock
|    |–> /sbin/start_udev – initializes device drivers
|    |–> /etc/sysconfig/i18n – set language
|    |–> /etc/sysctl.conf – Configure kernel parameters
|    |–> /etc/sysconfig/keyboard – set keyboard mapping
|    |–> /proc/acpi – Initialize ACPI bits
|    |–> /etc/mdadm.conf – RAID setup
|    |–> Device mapper & related initialization
|    |–> Setting up LVM:
|    |    /sbin/lvm.static vgchange –a y ignorelocking failure
|    |–> /fastboot – if present fast booting occurs skipping fsck
|    |–> /forcefsck – if present fsck is forcefully done even if not
|    |     mentioned in fstab
|    |–> /.autofsck – /etc/sysconfig/autofsck
|    |–> /etc/sysconfig/readonly-root –if present / is mounted as
|    |    read-only
|    |–> /etc/fstab – persistently mount filesystems
|    |–> /etc/rwtab – exception to readonly-root, you can give rw
|    |    permission to certain dirs even if you have mounted whole
|    |    filesystem as readonly.
|    |–> /etc/mtab – create this file and keep info of all mounted FS.
|    |–> /sbin/quotacheck
|    |–> Remounting root filesystem in rw mode:
|    |    mount -n -o remount,rw /
|    |–> mount –a: Mount all other filesystems (except NFS &
|    |    /proc -> already mounted)
|    |–> /sbin/quotaon – Enabling local filesystem quotas
|    |–> rm -f /fastboot /fsckoptions /forcefsck /.autofsck
|    |    /forcequotacheck /halt \ /poweroff /.suspended &> /dev/null
|    |–> enabling swaps: swapon -a –e
|    |–> dmesg -s 131072 > /var/log/dmesg
|
|
|
|—->/etc/rc.d/rc {as a sub shell}
|    |
|    |–> checks present and previous runlevel
|    |–> set runlevel – /sbin/runlevel
|    |–> calls /etc/init.d/functions {in same shell}
|    |–> checks user confirmation mode
|    |–> checks if /etc/rc.d/rc$runlevel.d exists?
|    |–> /etc/rc.d/rc$runlevel.d/K* – first run kill scripts
|    |–> /etc/rc.d/rc$runlevel.d/S* – then run start scripts
|    |–> all scripts in /etc/rc.d/rc$runlevel.d call
|    |    /etc/init.d/functions in same shell. Also these scripts
|    |    have 5 functions defined in them i.e start, stop, restart,
|    |    condrestart, status. Kill scripts use only stop function
|    |    while S* scripts use only start function.
|    |
|     |–> /etc/rc.d/rc.local – if you want to run any script before
|            login then put it here.
|
|————> shutdown CAD magic keys are set
|           /sbin/shutdown -t3 -r now

|————> power failure considerations
|           /sbin/shutdown -f -h +2

|————> power restore considerations
|           /sbin/shutdown –c
|
|
|
|————> 6 mingettys are spawned by init with tty* device drivers
|            All enter sleep state except one
|            1:2345: respawn: /sbin/mingetty tty1

|————> IF default runlevel is 5 then
|           /etc/X11/predfm –nodaemon (brings graphical login)
|
|——–>first mingetty
|       |–> loads /dev/tty1
|       |–> displays /etc/issue
|       |–> calls /bin/login – enter Username/login
|           |–> /usr/bin/passwd – enter password
|                    |
|                    |–>PAM for authentication ———–
|          PAM uses passwd,group,shadow files from /etc dir|
|                          |                               |
|                          |                               |
|                      Valid user                      invalid user
|                          |                               |
|                          |              prompts that login/passwd
|–> puts login daemon in sleep state             is incorrect
|
|
|–>if $USER/.hushlogin exists ? DO NOT RUN mail,motd,lastlog!
|    |
|    Else –> /etc/motd – message  of the day put by you
|        |–> lastlog* using /var/log/lastlog
|        |–> Checks user’s mail – /var/spool/mail/$USER
|
|– init then wakes /bin/login process
|   mingetty then goes into zombie state and is killed by init
|   Login then loads /bin/bash as a monitored child process
|   /bin/bash takes over and login goes into sleep state
|
|
|–> /bin/bash
|
|–> /etc/profile {sets HOSTNAME, HISTSIZE, PATH etc}
|             |–> /etc/inputrc {sets keyboard mappings,
\            |    terminal Characteristics}
\            |–> /etc/termcap {sets terminal capabilities}
\            |–> /etc/profile.d/*.sh {14 files}
\___             /              {
|           /               colorls.sh
|          /                cvs.sh
|———–|———/                 glib2.sh
|           |                           gnome-ssh-askpass.sh
\|/          |                           kde.sh
if you want to run any      |                          krb5-devel.sh
script after login then  |                        krb5-workstation.sh
put it here.          |                          lang.sh
|                        less.sh
|                           mc.sh
|                           mpi-selector.sh
|                           qt.sh
|                           vim.sh
|                           which-2.sh
|                        }
|
|
|
|
|
|–> /etc/bashrc (set umask and system wide variables)
|
Local settings      |— |–> .bash_profile—-|
For a particular <–|    |–> .bashrc          |___ present under
User                  |    |–> .bash_history    |    /home/$UNAME
|— |–> .bash_logout—–|

Finally, the bash shell login prompt appears.

**************

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s