Tuesday, December 2, 2014

Linux System Boot Procedure

I was awared the Linux boot process is a very fundamental question during the system infrastructure interview. I surf the internet but can't find the answer I feel reasonable for me. I know there has different version of Linux kernels that might be caused the differential. However, here I would like to share whatever I familiar boot process and it references RHEL6 most. I think it helps me to understand the OS fundamental concept and easier for me to follow the logic in my following research experiments.

Linux System Main Actors - ref boot sequence:


  • System BIOS (basic I/O system)
  • MBR (master boot record, located in the 1st sector of the bootable disk /dev/hda or dev/sda)
  • GRUB (GRand Unified Bootloader, config file in /boot/grub/grub.conf)
  • initramfs Initial ramfs, initial ram base file system.
It is a cpio archive of the initial file system that gets loaded into memory during the Linux startup processinitramfs needs to contain all of the device drivers and tools needed to mount the real root filesystem
  • initrd (initial ramdisk) is a scheme for loading a temporary root file system into memory in the boot process of the Linux kernel. 
initrd and initramfs refer to two different methods of achieving this. Both are commonly used to make preparations before the real root file system can be mounted.
  • Linux Kernel
The Linux kernel locate between bare metal (H/W) and O/S server ( User Apps ). It includes VFS(Virtual File System), IPC (Inter-Process Communication), Process Scheduler, Memory manager ( or Virtual Memory Manager), Dispatcher, Network Interface, Device Drivers ... etc.
  • /sbin/init lanuches bootup script from /etc/
  • Runlevel (/etc/rc.d/rc*.d/, you would see programs that start with S and K.
a. Programs starts with S are used during startup. S for startup.
b. Programs starts with K are used during shutdown. K for kill.
    When the Linux system is booting up, you might see various services getting started. For example, it might say “starting sendmail …. OK”. Those are the runlevel programs, executed from the run level directory as defined by your run level. )

    Linux System Boot Process in General - ref boot sequence:

    1. BIOS
    2. MBR located in the 1st sector of the bootable disk /dev/hda or dev/sda
    3. GRUB config file in /boot/grub/grub.conf
    4. Kernel:
            4.1 Init
            /etc/inittab file then execute runlevel program
            eg: grep initdefault /etc/inittab
            
            4.2 Runlevel: - showing message 
    When the Linux system is booting, see various services 
            getting started.
            e.g. it might say “starting sendmail …. OK”. 


    Linux System Boot Process in Detail - ref boot sequence:

    1. System BIOS performs three task
    • Power-On Self Test(POST)
    • Initial H/W setup and configuration
    • Loads option ROM from add-in card (SCSI, SAN HBA, RAID)
    • Selects boot device and executes MBR (master boot record, located in the 1st sector of the bootable disk /dev/hda or dev/sda)
    2. First stage GRUB in MBR(445 bytes); it loads:
    • stage1.5 GRUB using int13 BIOS calls, stage1.5 GRUB provides fs(filesystem) drivers and then loads stage2 GRUB
    3. Second stage GRUB 
    • Reads and uses configuration file or displays GRUB command prompt
    • Loads initial ram disk (usually specified)
    • Loads, decompresses, and executes selected Linux kernel from hard drive with command line arguments
    4. Linux Kernel
    • Initializes and configures H/W using drivers statistically compiled into the kernel
    • Decompresses the initramfs image and mount
    • Runs init script from initramfs image
    • init script loads kernel modules and performs task necessary to mount the real root fs(filesystem) including loading any required kernel modules stored in the initramfs image
    • Mounts the root partition passed to the kernel by the boot loader using the root=kernel command-line option(usually read only) as the root partition, replacing the initrd
    • Execut /sbin/init
    PS: for RHEL only:
    Upstart is async. replacement for the traditional init daemon. It is installed using sysvinit runlevel comptatibility mode so that it is mostly a drop-in replacement. Configuration is in the /etc/inittab and /etc/init/* files


    In sum, I know it looks complicated, let me try to see whether I can make the concept easier for understanding in the coming future.

    Share Movie Quote

    I may not know where I'm going, but I'm on my way. - (Movie: The Motorcycle Diaries), 2004

    No comments:

    Post a Comment