Detailed description of the linux system startup process and system initialization

Source: Internet
Author: User

I. linux Startup Process

The linux Startup Process can be divided into the following steps:

POST power-on self-check --> BIOS (Boot Sequence) --> load the MBR on the corresponding Boot (bootloader) --> the main boot settings load its BootLoader --> Kernel initialization --> initrd->/etc/init process load/etc/inittab. The process flow chart is as follows:

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" image 148 "border =" 0 "alt =" image 148 "src =" http://img1.51cto.com/attachment/201305/2/6466723_1367538867faIU.png "width =" 870 "height =" 602 "/>

Ii. Detailed Startup Process Analysis

(1,

 
 
  1. POST power-on self-check: when the computer host powers on, it will then hear a drop, the system starts the power-on self-check POST-power on self

  2. Test). In this process, it is mainly used to detect the faulty storage of computer hardware devices such as CPU, memory, motherboard, video card, and CMOS.

  3. In the case of hardware faults, there are two possible reasons: serious faults (fatal faults) are shut down. At this time, various initialization operations have not been completed,

  4. No prompts or signals are provided. If there is no serious fault, a prompt or sound alarm signal is provided, waiting for the user to handle it .)

  5. To the BIOS.

(2,

 
 
  1. BIOS: BIOSBasic Input Output System (Basic Input Output System) is the first place to be read after self-check is completed)

  2. The BIOS records the chip set and related settings of the motherboard, such as the communication frequency between the CPU and the interface device, the search sequence of the boot device, and the size of the hard disk.

  3. Type, system time, external bus, I/O address of various interface devices, IRQ interrupt information that has been communicated with the CPU, so to start smoothly,

  4. First, read the BIOS settings.

(3,

 
 
  1. Start the Boot on the first device according to the system Boot process set by BIOS. If the detection succeeds, start the Boot Sequence according to the Boot Sequence.

  2. Program, our boot device mainly includes hard disk, USB, SD, etc. We usually use hard disk, and then read the first device is the hard disk, the first

  3. To read the MBRMaster Boot Record of the hard disk), and then the system can install

  4. Boot Loader) to start Core identification. In this example, the MBR program finds only the front of the hard disk partition.

  5. 446 bytes of Boot Loader] and then find the relevant configuration and definition.

(4,

 
 
  1. Boot Loader loads Grub Program

  2. In this process, Grub is mainly started with Grub guidance. Grub is divided into two phases:

  3. Stage1: Mainly Boot loader

  4. Stage 1.5: Transition

  5. Stage2: Mainly/boot/grub

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" image 149 "border =" 0 "alt =" image 149 "src =" http://www.bkjia.com/uploads/allimg/131227/1T0321632-1.png "width =" 734 "height =" 224 "/>

We can see that the linux kernel VMLnuz, grub, and initrd are all in the/boot directory.

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" image 150 "border =" 0 "alt =" image 150 "src =" http://www.bkjia.com/uploads/allimg/131227/1T032C37-2.png "width =" 765 "height =" 235 "/>

In/boot/grub/, we can see the familiar stage1, stage2 and grub tool configuration files grub. conf. What are defined in grub. conf ??

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" image 151 "border =" 0 "alt =" image 151 "src =" http://www.bkjia.com/uploads/allimg/131227/1T032O29-3.png "width =" 736 "height =" 430 "/>

Kernel and Kernel


 
 
  1. According to the definition in Grub, after reading grub, submit the following work to the kernel. Kernel is mainly used to test the system hardware and initialize the hardware driver.

  2. And mount the root file system root switch in read/write mode), then here there is a "first chicken or first egg file", what is it?

  3. So?

  4. To access the real root file system rootfs), you must load the device in the root file system. At this time, the root file system is not mounted,

  5. What should I do if I need to mount the root file system and load the driver in the root file system? To solve this problem, the initrd file is used.

  6. In this section, the content of the kernel initialization task is summarized as follows:

  7. Test hardware-> load driver initrd)-> mount the root file system-> rootfs (/sbin/init)

Average,

 
 
  1. At this point, the related work of the kernel space has been completed. The task of the kernel space begins to be transferred to the user space.

  2. Linux) to the user space/sbin/init excessive, so gurb started to guide the kernel to initrd.

  3. Initrd: A Virtual File System with directories such as lib, bin, sbin, usr, proc, sys, var, dev, and boot,

  4. In fact, you will find the directory inside is a bit like true/right, so we call it a virtual root file system, which is used to convert the kernel and the real root file system

  5. Establish associations so that the kernel can load the driver required by the root file system in initrd, mount the root file system in read/write mode, and run

  6. Init is the first process among users.

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" image 152 "border =" 0 "alt =" image 152 "src =" http://www.bkjia.com/uploads/allimg/131227/1T0325E8-4.png "width =" 739 "height =" 348 "/>

Let's take a look at the content in the init script:

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" image 153 "border =" 0 "alt =" image 153 "src =" http://www.bkjia.com/uploads/allimg/131227/1T0321392-5.png "width =" 737 "height =" 385 "/>


650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" image 154 "border =" 0 "alt =" image 154 "src =" http://www.bkjia.com/uploads/allimg/131227/1T03210B-6.png "width =" 751 "height =" 332 "/>

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" image 155 "border =" 0 "alt =" image 155 "src =" http://www.bkjia.com/uploads/allimg/131227/1T03210S-7.png "width =" 753 "height =" 362 "/>

From the above script content, we can see the main work of the init process:


 
 
  1. Mount: Mount/proc,/sys/dev in initrd to the corresponding directory in the current primary partition.

  2. Create directory:/dev/mapper

  3. Create block or character special files using mknod

  4. Mounting related modules

  5. Create a root device

  6. Mount/sysroot

  7. Final root Switch

After the initialization and init operations are completed, the/etc/inittab file in the system is started to initialize the system. Next we will introduce the details in the inittab configuration file.

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" image 156 "border =" 0 "alt =" image 156 "src =" http://www.bkjia.com/uploads/allimg/131227/1T0323044-8.png "width =" 784 "height =" 394 "/>

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" image 157 "border =" 0 "alt =" image 157 "src =" http://www.bkjia.com/uploads/allimg/131227/1T032M15-9.png "width =" 775 "height =" 399 "/>


Definition of each level:

Default running level

 
 
  1. 0: halt // Shutdown

  2. 1: single user mode // single user maintenance mode)

  3. 2: multi user mode, without NFS // NFS function is not supported

  4. 3: multi user mode, text mode // character Interface

  5. 4: reserved // retained by the System

  6. 5: multi user mode, graphic mode // graphical interface

  7. 6: reboot // restart

/Etc/inittab format and syntax (:)

 
 
  1. [Option]: [runlevel]: [Behavior]: [command]

  2. Behavior:

  3. Initdefault: indicates the default running level.

  4. Sysinit: indicates the system initialization operation option.

  5. Ctrlaltdel: indicates the restart settings.

  6. Wait: indicates that the following operations can be performed only after the last command is executed.

  7. Respawn: indicates that the following fields can be regenerated without limit (reboot)

  8. Command Options

  9. Some commands, but usually scripts


The initialization script defined in inittab is rc. sysinit --/etc/rc. d/rc. sysinit.

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" image 158 "border =" 0 "alt =" image 158 "src =" http://www.bkjia.com/uploads/allimg/131227/1T0324b3-10.png "width =" 764 "height =" 287 "/>

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" image 159 "border =" 0 "alt =" image 159 "src =" http://www.bkjia.com/uploads/allimg/131227/1T032E61-11.png "width =" 768 "height =" 190 "/>



 
 
  1. As shown in: the rc. sysinit script defines some definitions with system initialization.

  2. Set Host Name

  3. Detect and mount other file systems in/etc/fstab

  4. Start swap Partition

  5. Set Kernel Parameters in/etc/sysctl. conf

  6. Load key ing --> function of each key on the keyboard

  7. Then run the related service script at the system running level:/etc/rc. d/init. d/script and/etc/rc. d/rc # d

650) this. width = 650; "style =" border-right-0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px "title =" image 161 "border =" 0 "alt =" image 161 "src =" http://www.bkjia.com/uploads/allimg/131227/1T0324949-12.png "width =" 754 "height =" 234 "/>


 
 
  1. Rc0-rc6 directory script:

  2. K * ## stop all files starting with K

  3. S * ## as long as all files starting with S execute start

  4. 0-99 (execution order, the smaller the number, the first execution)

  5. User-Defined boot Startup Program (/etc/rc. d/rc. local)

  6. You can write some execution commands or scripts to/etc/rc. d/rc. local as needed. It can be loaded when it is started.

Iii. Summary

The general content of system initialization is summarized as follows:


 
 
  1. Hardware initialization, image interface startup initialization if the default startup basics are set)

  2. Initialize host RAID settings, device er, and related initialization,

  3. Checks the root file system and mounts it in read-only mode.

  4. Activate udev and selinux

  5. Set the Kernel Parameter/etc/sysctl. conf

  6. Set system clock

  7. Enable swap partition and set Host Name

  8. Load keyboard ing

  9. Activate RAID and LVM logical volumes

  10. Mount additional file systems/etc/fstab

  11. Finally, call login according to the mingetty program to log on to the user-> log on to the user to complete the system startup)

  12. The main scripts and directories during system startup include:

  13. Boot

  14. /Grub

  15. /Boot/grub. conf

  16. /Boot/initrd + kernel version

  17. Mount the/proc // sys // dev/directory in the/initrd file and switch the root

  18. /Etc/inittab script

  19. /Etc/rc. d/rc. sysinit script, etc.


These important scripts and directories include other important directories, files, and scripts. From this article, we can have a detailed understanding of the linux system startup and initialization process, and then we can DIY a micro linux system according to the linux system startup process and the commands used, we will post a blog post about the "DIY micro-linux System" in the next two to three days. At that time, we will discuss more details about the components of the linux system.

Information !!!


The content I summarized is not rigorous enough. I hope you can correct me ~~~

This article is from the "Chris On the way" blog, please be sure to keep this source http://chrinux.blog.51cto.com/6466723/1192004

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.