Detailed Linux system startup process and system initialization

  

First, the Linux system startup process

About the Linux system startup process we can divide into the following steps:

POST power up Self-test-->BIOS(Boot Sequence)-->Load MBR (bootloader) on the corresponding boot-->Master boot settings load its BootLoader-->Kernel initialization-->initrd—>/etc The /init process loads /etc/inittab, and its process flow chart is as follows:


Second, detailed boot process

(1),

  1. POST power-on self-test: Computer
    When the host turns on the power, it will hear a drop, and the system starts to start the self-test (POST-power on self
  2. test) ), this process is mainly to detect computer hardware devices such as: CPU, memory, motherboard, graphics card, CMOS and other devices are faulty
  3. In the case of hardware failure, it will be based on two situations: for serious The fault (fatal fault) is stopped. At this time, since various initialization operations have not been completed,
  4. can not give any prompt or signal For non-critical faults, a prompt or audible alarm signal is given, waiting for the user to handle it. If there is no fault, POST completes its own relay task of
  5. and hands over the tail work to the BIOS for processing.

    (2),

    1. BIOS: The first place to read after the computer power-on self-test is BIOS (Basic Input Output System)
    2. , the BIOS records the chipset and related settings of the motherboard, such as the communication frequency of the CPU and interface devices, the search order of the boot device, the size of the hard disk and
    3. type, system time, The external bus, the I/O address of various interface devices, and the IRQ interrupt information that has been communicated with the CPU, so if you want to start successfully,
    4. First read the BIOS settings.

      (3),

      1. According to the system startup process set by the BIOS, if the test passes, it will start to support on the first device according to the Boot Sequence. Start
      2. program, our boot device mainly includes hard disk, USB, SD, etc. We generally use the hard disk, and then read the first device is the hard disk, the first
      3. Read the master boot record (MBR) of the hard disk, and then the system can start the core recognition work according to the
      4. boot loader installed in the boot area. [Insert here: MBR program just finds the 446-byte Boot Loader that is only the front
      5. in the hard disk partition] and then looks up the relevant configuration and definition.

        (4),

        1. Boot Loader Loading Grub Programs

        2. In the process, it started with Grub’s boot, Grub Divided into two stages:

        3. stage1: mainly boot loader

        4. stage 1.5: transition

        5. < Li>stage2: mainly /boot/grub


          The above we can find the Linux kernel VMLnuz, grub, initrd are in the /boot directory


          In /boot/grub/we have seen the familiar stage1, stage2 and grub tools configuration file grub.conf, then what is defined in grub.conf? ?


          (5), Kernel

          1. According to the definition in Grub, after the grub is read, the following work is handed over to the kernel. The kernel is mainly to complete the system hardware detection and hardware driver initial
          2. , and mount the root file system (root switch) by reading and writing, then there is a "first chicken or first" The file of the egg is ”, specifically what
          3. that?

          4. In order to access the real root file system (rootfs), you must load the device in the root file system, then the root file system is not mounted,
          5. To mount the root file system and load the driver in the root file system, what should I do? In order to solve this problem, this is the use of the initrd file.
          6. For the sake of kernel initialization, do a brief summary:
          7. Probe hardware->Load driver (initrd)->mount root filesystem->gtfsf /sbin/init)

            (6),

            1. The work related to kernel space has been completed, the task of kernel space starts to transfer to user space, and the kernel space passes through The indirect initrd (micro
            2. linux) is excessive to /sbin/init in user space, so gurb starts to boot the kernel to initrd.

            3. initrd: A virtual file system with lib, bin, sbin, usr, proc, sys, var, dev, boot, etc.
            4. Actually You will find that the directory inside is a bit like true/right, so we call it the virtual root file system, the role is to associate the kernel with the real root file system
            5. , let the kernel go to initrd Load the driver required by the root file system, mount the root file system in read-write mode, and let the
            6. the first process init.


              The following we look at the contents of the init script:





Copyright © Windows knowledge All Rights Reserved