Linux system startup process

Source: Internet
Author: User

Start process Overview

As an example of a Linux host set up by our PC, when we press power, the computer hardware will actively read the BIOS to load the hardware information and the hardware system self-test, then the system will actively read the first bootable device (BIOS setting), at this point can be read into the boot loader. The boot loader can specify which kernel file to use to boot, and actually load the kernel into memory to decompress and execute, at which point the kernel can be active in memory, and detect all hardware information and load the appropriate driver to enable the host to start running, wait until the kernel detects the hardware and loads the driver, Our operating system began to run on the PC. Once the host system is running, Linux calls the external program to start preparing the software execution environment and actually loads all the software programs that are required to run the system. So the system's startup process is streamlined as follows:

    1. Load BIOS hardware information with self-test and get the first bootable device based on setup
    2. Read and execute the boot looder (that is, the GRUB program) of the MBR within the first boot device
    3. Kernel kernel is loaded based on boot loader settings, and the kernel starts to detect hardware and load drivers
    4. After the hardware driver succeeds, kernel will invoke init (root process prior to CentOS 6, Centos7 root process is systemd) and get the Run level (runlevel) information.
    5. Init executes the/etc/rc.d/rc.sysinit file to prepare the operating environment for software execution
    6. Init performs the start of each service of Run-level
    7. Init executes the/rc.d/rc.local file.
    8. Init executes the terminal emulator Mingetty to start the login process and finally waits for the user to log in.
Start the process the first major item--Start the hardware device

From the above overview of the process, it is not difficult to find that the system's start-up process can be summarized as two major items:
One: Start the hardware Device
Second: Setting the operating environment

First, to start the hardware device, we need to go through the BIOS self-test, boot loader and kernel loading.
biso self-Test
We want to start the whole system first to let the system to load the BIOS (basic Input output system), and through the BIOS program to load the CMOS information, and through the CMOS setting values to obtain the host hardware configuration information, and then the BIOS will post, Start the initialization of hardware detection, start the device data read, and start the MBR and related tasks.
boot loader
The BIOS specifies the startup device during the loading process to allow us to read the operating system kernel files on the disk, but different operating systems have different file system formats, so we need a boot loader to handle kernel file loading issues. This bootloader is bootloader, stored in the first sector of the boot device, which is what we call the MBR (master boot partition), through boot loader, we can load the kernel. But here is a problem, on a multi-OS machine, each system kernel load, need to use their own loader boot, and the system of the MBR only one, then how can we install the Windows System and Linux system on a host computer at the same time?
In fact, each partition on the disk is left on a boot sector (boot sector) to provide the operating system installation boot loader. So if you have a multiple operating system, then each operating system will install a boot loader in its own boot sector, as shown in:

But the problem is still unresolved, how to make the operating system through its own boot loader to load the kernel? This depends on our boot loader. Boot loader has three main functions: 1, provide boot menu, 2, load kernel file, 3, transfer to other loader. So we can directly use the menu options provided by boot loader, select the operating system to install, that is, choose its corresponding boot loader, to load the corresponding kernel.
Knowing the function of boot loader, we became very good at understanding the role of boot loader in the startup process, but in fact, because the boot loader function too much, and the MBR to the boot loader 446B of space, which is completely enough, So Linux is running the boot loader program with the configuration load in three stages (stage) to run:
Stage1: Run the boot loader main program (this part exists in the first 446 of the MBR) to identify the file system type of the system to be started.
Stage1_5: According to the file system type identified by 1, load the corresponding file system driver, stage1_5 file system driver

Stage2: Loads all configuration files and related environment parameter information. Read the grub.conf configuration file and load the driver. The contents of the grub.conf configuration file are as follows:


Kernel load phase
Under boot loader, successfully read the grub.conf file and start loading the kernel
Grub.conf: The important settings in the configuration file are as follows:
Title: Define the names of each operating system
Root: Represents the location where the kernel files are stored, where the partition location is specified, not the root directory.
Kernel: The name of the kernel and some core parameters at startup. Because the root directory needs to be mounted during startup, you need to specify the partition where the root is located. RHGB indicates a color display, and quiet indicates a silent mode load kernel.
INITRD (CentOS 5): A pseudo-system that allows the kernel to load kernel programs on this virtual root system to load devices such as hard drives.
After the grub.conf file is read, the kernel driver starts to load. The system is now ready to start.

Second item--Setting the operating environment

After the kernel, hardware, and driver information is loaded, the kernel will call the user control's first execution program/sbin/init,init program main function is to prepare the software operating environment, including the system's host name, network configuration, file system format and other services to start the management. All of these operations are defined by the Initi configuration file.
Configuration file for Init

  • CENTOS5: Because of the Sysvinit mode adopted by CENTOS5, it is characterized by a service program that starts the user space, usually through scripting, the dependent services will be started serially, which results in a very slow start-up process for centos5. Its configuration file is:/etc/inittab
  • CETOS6: The use of upstart, which is characterized by the protection process between the communication relies on d-bus, so can basically achieve similar parallel start; Profile::/etc/inittab,/etc/init/*.conf
  • CENTOS7: The use of SYSTREMD mode, which is characterized by a service only when the first access to the real start up, so the CENTOS7 system boot process is very fast, its configuration file is:/usr/lib/systemd/*
    Processing process for Init
    Init is executed sequentially from the top-down read Inittab file (centos5), according to the execution flow of the Inittab configuration file as follows:
    1. First get the default RunLevel, where the default level is 5
    2. Initialization of the system using/etc/rc.d/rc.sysinit
    3. Yo because of the 5 level, so only 13:3:WAIT:/ETC/RC.D/RC 5, the other is ignored

      4. Configure the [Ctrl]+[alt]+[del] key combination function
      5. Configuration of the continuous electrical system PF,PR two mechanisms
      6. Start a MINGETTY6 terminal

      System initialization/Process
      After the default level is obtained, INIT initializes the system based on what is defined in/etc/rc.d/rc.sysinit, and the main things/etc/rc.d/rc.sysinit do are the following:
  • Set the hostname according to the settings in the configuration file
  • Print Text Welcome message
  • Activating SELinux and Udev
  • Mount Swap Devices
  • Detect root unity and re-mount in read-write mode
  • Setting the system clock
  • Set the value of the kernel parameter according to the/etc/sysctl.conf file
  • Activating LVM and RAID devices
  • Load additional device drivers
  • Cleanup operations
    After the initialization system is complete, we need to open a series of services to meet the functions required by our system, such as SSHD, DHCP and other services. Here is the ID:5:WIAT:/ETC/RC.D/RC 5 configuration obtained in the Initta, in fact, through the/etc/rc.d/rc3.d/under the link file to determine how to start and close the service; all the files that begin with S are passed the start parameter to start, All beginning with K will be stopped by the stop parameter.
    Open Terminal
    After all the system-related services have been started, Linux will then start the terminal. Our system has been fully activated!

Linux system startup process

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.