Announcement

Collapse
No announcement yet.

Linux Boot Process

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Linux Boot Process

    Boot process

    The boot sequence in a Linux server startup begins with the BIOS initialization that points to the GRUB boot loader located on the appropriate master boot record MBR. The GRUB initializes the Linux Kernel which starts init, the first Linux process. The init process initializes and moves the system into a specific runlevel where the Linux Services are started.

    BIOS -> MBR -> Grub -> Kernel -> Init (the first process, /etc/inittab -> starts /etc/rc.sysinit and /etc/rcX.d ). On the runlevel startup /etc/rcX.d first the scripts that begin with K are executed in order to kill the services that not are expected to be running on this runlevel . After this the scripts that begin with S are executed to start the services that form this runlevel. In both cases the order is provided by the numbers that form the script name.
    .
    Grub boot loader

    The default boot loader for Red Hat Linux is GRUB, the first part of it is installed in the MBR of the first drive and initiated by the BIOS. During the system installation GRUB is installed on the MBR of the first disk where the boot partition resides normally. If for some reason you need to reinstall grub you can use the grub-install command :

    $ grub-install /dev/sda --> Be careful, this command can break your system !!!

    Once GRUB is started by the BIOS, the boot loader mounts the boot partition, loads the Linux Kernel that starts the init process. The sequence of this process can be seen on the /etc/grub.conf file:

    $ cat /etc/grub.conf
    ...
    title Red Hat Enterprise Linux Server (2.6.18-92.el5)
    #Mount /boot partition
    root (hd0,0)
    #Kernel loading
    kernel /vmlinuz-2.6.18-92.el5 ro root=/dev/VolGroup00/LogVol00Root rhgb quiet
    #Initial RAM loading
    initrd /initrd-2.6.18-92.el5.img
    Kernel and drivers loading

    The way that uses GRUB to load the Linux Kernel can be customized directly at the console typing "e" following the instructions of the GRUB graphical menu showed at startup or directly modifying the file /etc/grub.conf:

    kernel /vmlinuz-2.6.18-53.el5 ro root=/dev/VolGroup01/LogVol00 rhgb quiet s
    Single user mode "s" that provides a root shell without root password check. Very useful for root password recovery.

    kernel /vmlinuz-2.6.18-53.el5 ro root=/dev/VolGroup01/LogVol00 rhgb quiet emergency
    Emergency mode provides a maintenance root shell after root password check.

    kernel /vmlinuz-2.6.18-53.el5 ro root=/dev/VolGroup01/LogVol00 rhgb quiet init=/bin/sh
    With this configuration you can startup the system skipping the init process. It provides a root shell after root password check.

    kernel /vmlinuz-2.6.18-53.el5 ro root=/dev/VolGroup01/LogVol00 rhgb quiet 5
    Graphical mode startup, the default behaviour.

    kernel /vmlinuz-2.6.18-53.el5 ro root=/dev/VolGroup01/LogVol00 rhgb quiet selinux=0
    SElinux can be disabled at kernel boot time with this configuration.

    Before the kernel is started a RAM disk is initialized and used to load drivers and modules. This step is performed by GRUB in the initrd directive:

    initrd /initrd-2.6.18-53.el5.img

    All the users that have access to the server console can gain root access to the server using single user mode. In order to protect who can modify GRUB, the boot loader process can be password protected with a password generated with grub-md5-crypt and placing it at /etc/grub.conf file. Once done when the user at the console trays to modify the mode in which the system is booted, a password confirmation is asked.
    Init process

    Once GRUB have loaded the Kernel and drivers, Linux hands over boot responsibilities to the Kernel which starts loading the rest of the system calling the First process: init. The init process runs /etc/rc.d/rc.sysinit, which starts network configuration, partitions mounts, system clock, etc. The init process then finds which runlevel it should be searching at the initdefault directive in /etc/inittab.

    Code:
    $ cat /etc/initab
    
    # Default runlevel. The runlevels used are:
    # 0 - halt (Do NOT set initdefault to this)
    # 1 - Single user mode
    # 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
    # 3 - Full multiuser mode
    # 4 - unused
    # 5 - X11
    # 6 - reboot (Do NOT set initdefault to this)
    #
    id:5:initdefault:
    The default runlevel is 5, so init will look in /etc/rc.d/rc5.d and run each "kill" script to stop the services that are not supposed to operate on the runlevel and "start" script to start services that must be running. Scripts are run in numeric order. After the services are stopped and started according to runlevel, the init process executes the virtual console: a command line where you can log into to start using Linux. All this processes are controlled on the /etc/init/*.conf files :

    Code:
    $ cat /etc/init/rc.conf
    
    # rc - System V runlevel compatibility
    #
    # This task runs the old sysv-rc runlevel scripts. It
    # is usually started by the telinit compatibility wrapper.
    
    start on runlevel [0123456]
    stop on runlevel [!$RUNLEVEL]
    task
    export RUNLEVEL
    console output
    exec /etc/rc.d/rc $RUNLEVEL
    Starts/kills services depending on RUNLEVEL.
    Code:
    $ cat /etc/init/control-alt-delete.conf
    
    # control-alt-delete - emergency keypress handling
    #
    # This task is run whenever the Control-Alt-Delete key combination is
    # pressed. Usually used to shut down the machine.
    
    start on control-alt-delete
    exec /sbin/shutdown -r now "Control-Alt-Delete pressed"
    Configure Ctrl+Alt+Del key combination to shutdown the system at console.

    $ cat /etc/init/tty.conf

    # tty - getty
    #
    # This service maintains a getty on the sepcified device.

    stop on runlevel [016]
    respawn
    instance $TTY
    exec /sbin/mingetty $TTY

    Starts virtual consoles at the end of the boot sequence.
    Code:
    $ cat /etc/init/prefdm.conf
    
    # prefdm - preferred display manager
    #
    # Starts gdm/xdm/etc by preference
    
    start on stopped rc RUNLEVEL=5
    stop on starting rc RUNLEVEL=[!5]
    console output
    respawn
    respawn limit 10 120
    exec /etc/X11/prefdm -nodaemon
    Starts display manager in RUNLEVEL=5

    Note: Previous versions of Red Hat used 'System V Init' as init service, where all init directives were located on /etc/inittab file. Red Hat 6 init system uses the 'Upstart init' daemon which reads the configuration files from /etc/init/ directory.
    Last edited by kuldeep; 02-23-2015, 11:58 PM.
Working...
X