Linux start-up process detailed

Source: Internet
Author: User
Tags network function

The Linux system startup process can be briefly summed up, and this blog post will explain what you have done to each part after you understand the approximate boot sequence.


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/79/14/wKiom1aH3LPjh1VdAAO_YDKsBp0963.bmp "style=" float: Left; "title=" Boot.bmp "alt=" Wkiom1ah3lpjh1vdaao_ydksbp0963.bmp "/>

Depending on the color of the process, we can divide the system boot process into two large parts, blue indicates the process at the kernel level, and the red part is the initialization process for user space. We'll take a CentOS 5 as a basis to explain what the parts have done, and after mastering the CentOS boot process, let's look at the different parts of CentOS 6 and 7.

First, POST

POST (PowerOn Self testing) is the process of the system power-on-test, in which the self-test program is the BIOS (Basic Input Output System), the BIOS is a program that is cured in ROM, It mainly completes the detection system key hardware devices such as memory, graphics card, i/0, disk, keyboard and mouse are normal. If there is a video card, memory and other interfaces loose, will be error. After detection is normal, the BIOS reads the program that is written to the MBR (the bootseqence phase) to execute.

Next, give control to bootloader.

Second, bootsequence (BootLoader)

Bootsequence is the start order, in order to find the various bootable devices, the first device with a boot program is the device to be used to start the system;

The bootsequence phase is mainly done by the bootloader (bootloader).

BootLoader includes MBR and grub. Its job is to provide a menu that allows the user to select the system to be launched or a different kernel version, to load the user-selected kernel into a specific space in RAM, then unzip, expand, and then transfer control of the system to the kernel;

MBR(Master bootrecord, master boot record ), it exists on the hard disk 0 cylinder, 0 heads, 1 sectors, so it has a bytes.

Mainly consists of three parts:

1, the former 446 bytes storage is the bootloader program.

2, then the bytes storage is the partition table.

3, the last 2 bytes is the magic number, fixed to 0xaa55 or 0X55AA, depending on the processor type, if it is a small-end mode processor (such as the Intel series), the value is 0xaa55, if it is a big-endian mode processor (such as Motorola6800), then the value is 0X55AA.

GRUB(GRand Unified Bootloader) It is a same resource bootstrapper. In simple terms, it complements and expands the MBR. It has three steps to process:

1,stage1: Run the MBR stored in the bootloader program. Its task is to load the stage1_5 (which is not considered a stage1_5 under the disk partition/boot/grub/, because Stage1 does not recognize the file system) loaded into memory execution.

2.stage1_5: The sector behind the MBR, which allows the bootloader program in Stage1 to recognize the Stage2 file on the disk partition/boot/grub/and load the memory execution by providing a basic file system driver .

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/79/18/wKiom1aI2vfQcDfzAAATPuw_nnQ588.png "title=" Stage1 _5.png "alt=" Wkiom1ai2vfqcdfzaaatpuw_nnq588.png "/>

Note: If the file system type of the boot partition does not belong to one of the stage1_5, the additional file system drivers under/lib64/moudles/are loaded with RAMDisk.

RAMDisk: A memory-based virtual file system initialized by bootloader. Before the kernel boots, boot loader loads the Initrd file (initramfs-2.6.32-573.el6.x86_64.img) from the storage media into memory and then initializes a file system in memory.

3,stage2: This program is mainly to provide users with a relatively friendly boot menu, and then to load the same disk partition/boot/kernel files (such as vmlinuz-2.6.32-573.el6.x86_64).

Next, the control of the system is given to the kernel.

Third, kernel

After control is handed over to the kernel, the kernel does its own initialization, and the main tasks are:

1, detect all the hardware devices can be identified and complete the relevant configuration work, including CPU, I/O, storage devices and so on.

2, load the hardware driver;

The 2nd point here is that, due to the adaptability of different hardware, the kernel file contains only some basic device drivers, and some drivers must use RAMDisk or Ramfs (CentOS 7) to complete the driver loading. The RAMDisk has been initialized in the Boorloader phase, and the Initrd file is actually bootloader configured. The kernel can now access the Initrd file system and run the INIT program in the INITRD file system to load drivers that are not included in the kernel.

Of course, RAMDisk and Ramfs are not required, and if we edit a kernel by ourselves and edit all the drivers it needs into the kernel for only one computer, then RAMDisk and Ramfs are not required.

Ramfs is an evolutionary version of RAMDisk in CentOS 7. Because both RAMDisk and Ramfs need to be decompressed in memory,RAMDisk is a virtual disk, Ramfs is a virtual file system, and the virtual disk uses caching and buffering to speed up access to the disk, so both the memory and the virtual disk are cached and buffered, which is a double cache buffer. Ramfs is a memory-based file system that does not require caching and buffering to improve efficiency.

3. Mount the root file system in read-only mode (security considerations to prevent corruption of the root file system when the kernel is initialized).

4. After the root file system is mounted, the first application running user space:/sbin/init.

The kernel then gives control over the system to the/sbin/init program. As a result, the boot of the system is converted from kernel space to user space.

Iv./sbin/init Procedures

The /sbin/init program is the steward of the kernel, unless the program initiates a system call. Otherwise, everything in the system is managed by the/sbin/init program. And when the system starts, its workflow is

1. Set the default run level according to the definition of the/etc/inittab configuration file.    

operating level: a mechanism set up for the purpose of operating or maintaining the system

0 : Turn off the machine, shutdown

1 : Single-user mode ( Single user ), Root users, no certification, maintenance level;

2 : Multi-user mode (multiuser), which starts the network function but does not start NFS ; maintenance mode;

3 : Multi-user (full multiuser mode), fully functional mode, text interface;

4 : reserved level; not currently used for special purposes, but accustomed to 3 level function to use;

5 : Multi-user mode (X11), full function mode, graphical interface;

6 : Restart, reboot

2 . Run the System initialization script (/etc/rc.d/rc.sysinit)to complete the initialization of the system.

3, close the corresponding level of the need to stop the service (/etc/rc.d/rc[0~6].d/k*), start the corresponding level need to open the service (/etc/rc.d/rc[0~6].d/s*)

Here k* or s* are symbolic links, linked to/ETC/INIT.D under the corresponding service script file, by the INIT program (SYSTEMD program, CentOS 7) to unified management.

4, set the landing terminal, at this time if the graphical interface, you also need to start the graphics terminal.

At this point, the system starts to complete, the user can log in and use.


Appendix 1: Linux startup Flowchart Solution

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/79/19/wKiom1aI6H_DjFFPAAfDLogvSGI032.jpg "title=" Boot.jpg "alt=" wkiom1ai6h_djffpaafdlogvsgi032.jpg "/> Note: This picture comes from another blog: http://blog.chinaunix.net/ Uid-23069658-id-3142047.html


Appendix II: The Evolution of the BOOT init program for CentOS, from SYSV init (CentOS 5) to upstart (CentOS 6) to Systemd (CentOS 7). The detailed work mechanism of these three can refer to the blog Analysis of Linux initialization system (three parts)






This article is from the "Roadtoom" blog, make sure to keep this source http://flyalways.blog.51cto.com/7680670/1731093

Linux start-up process detailed

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.