Linux system detailed startup process

Source: Internet
Author: User

    1. First stage: BOIS (Basic Input Output System) initialization, 1



      the BIOS is loaded first, and the BIOS program is used to load the CMOS (to save BIOS the hardware configuration and the user's settings for certain parameters (such as date, time, startup settings, etc.) chip, is a read-write parallel or serial flash chip on the motherboard, is the information. After acquiring the information in the CMOS, the BIOS starts the post, then performs the initialization of the hardware, sets up the PNP (Plug and Play, USB drive, etc.) devices, and then defines the sequence of devices that can be powered on. The next step is to read the data from the boot device (the bootloader in the MBR in the No. 0 sector within the first boot device)


      650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/8E/8A/wKiom1jD7BLyGBxQAADN21iIrVY146.jpg-wh_500x0-wm_ 3-wmp_4-s_2350451316.jpg "title=" bios.jpg "alt=" Wkiom1jd7blygbxqaadn21iirvy146.jpg-wh_50 "/>

Figure 1





2. Phase II: GRUB/GRUB2 start-up boot


Due to different operating systems, the format of the file system is not the same, so a boot management program is required to handle the kernel file loading. This management procedure bootloader in time, installs in the MBR! (MBR broadly refers to the entire sector, narrowly refers only to the boot program, on the hard disk 0 cylinder, 0 heads, 1 sectors; There are three main parts: the main boot program (446B), partition table (64B), hard disk identification (2B), Total 512B). The role of bootloader is to recognize the operating system's file format and load the kernel into memory execution (the read-in data has a setup program and a compressed kernel image in Zimage or bzimage). Because the MBR is too small, the boot tool often needs to read the data further from other places , which is called the second phase. This is usually an interface that can be interacted with. 3


(1) GRUB

In the second stage of booting, grub reads the configuration files in the/boot/grub/grub.conf, loads the appropriate kernel modules according to the parameters of the configuration file, and the kernel reloads the corresponding drivers to perform the necessary hardware initialization. Grub2 removed the concept of stage1,stage1_5 and Stage2 in Grub-legacy (that is, grub).

Stage1: This is the portion of Grub-legacy written to the MBR (corresponding to boot.img in GURB2). The function is to load the first sector of the stage1_5 (corresponding to the core.img in GRUB2) and prepare for the subsequent boot process.

Stage1_5: Is the part that writes to the reserved sector, corresponding to the core.img in the Grub2. (Note that the standard MBR is in the No. 0 sector, whereas the first partition recorded in the partitioned table is in 63 sectors, with 62 sectors in the middle being reserved sectors, and because stage1 (0 sectors) cannot directly recognize Stage2 (63 sectors), a stage1_ is added in the middle 5 (62 sectors) to transition boot! ) 2:


650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M01/8E/87/wKioL1jDrG_TqyJ1AABjuWOC1k4813.jpg-wh_500x0-wm_ 3-wmp_4-s_327699611.jpg "title=" sector. jpg "alt=" wkiol1jdrg_tqyj1aabjuwoc1k4813.jpg-wh_50 "/>

Figure 2


Stage2: That is the final stage of Grub-legacy. Directly to the user is a boot menu, which provides the name of the operating system, kernel parameters, boot partition and other content. From now on, it's time to actually start the Linux startup process, before it's all ready for work!


650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M02/8E/86/wKioL1jDpV3iZEvvAADqD4glPB0998.jpg-wh_500x0-wm_ 3-wmp_4-s_3639588260.jpg "title=" grub.jpg "alt=" Wkiol1jdpv3izevvaadqd4glpb0998.jpg-wh_50 "/>

Figure 3



(2) GRUB2

GRUB2 boot.img in the MBR or boot partition, boot.img reads the first sector of the core.img to read the sections behind the core.img, and once read is completed, Core.img reads the default configuration file and other required modules! (Centos7 is the GURB2 boot): 4:

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M01/8E/87/wKioL1jDwEOzwZ80AADPNr4CmMA358.jpg-wh_500x0-wm_ 3-wmp_4-s_954040168.jpg "title=" grub2.jpg "alt=" Wkiol1jdweozwz80aadpnr4cmma358.jpg-wh_50 "/>

Figure 4




3. Phase III: Kernel boot (vmlinuz, Initramfs) (Figure 6)


(1) Vmlinuz

Kernel classification: Monolithic kernel, module-type kernel

Monolithic kernel: A variety of hardware support, network protocol in the file System management are compiled into a single file.

Modular kernel: Allows the computer word to automatically load when using a certain function, to prevent the core bloated, is the standard construction in most cases.

Typically, kernel files are stored in compressed form and are not an executable kernel. Therefore, the primary task of kernel phase is self-extracting kernel image.

The system kernel image file (vmlinuz) is a bootable, compressible kernel that is typically bzimage(large kernel, greater than 512KB) or zimage (smaller kernel, less than 512KB) after compression.    Linux can use hard disk space as virtual memory, hence the name VM. Vmlinuz is an executable kernel file, and its decompression program is also in the kernel.  Kernel files are typically in the/boot/vmlinuz directory. Note that [Vmlinux is an uncompressed kernel, an elf file, which is the most primitive file that is compiled, cannot be used for direct loading, cannot be used to boot the kernel, but is an intermediate medium in the boot process]


650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M01/8E/88/wKioL1jD5Buh_W__AAC4_w5yVAE420.jpg-wh_500x0-wm_ 3-wmp_4-s_2492982197.jpg "title=" jieya.jpg "alt=" Wkiol1jd5buh_w__aac4_w5yvae420.jpg-wh_50 "/>

Figure 5



(2) Initramfs

initializing the Memory mirror disk (INITRAMFS) is called initializing the memory disk, providing the system with a series of modules that are not available for the kernel image, which is important for the correct boot of the system. He is often associated with file systems and storage devices, and also supports other features and hardware peripherals. Initramfs file was created with MKINITRD, this command is Redhat (CentOS) proprietary, the other version has the corresponding command! Once the bootloader is loaded into memory, the Initramfs file is decompressed and a root directory (virtual file system) is emulated in memory, which can provide an executable program to load the modules needed during the boot process, usually USB, RAID, LVM, SCSI and other file system on the disk interface driver!

#mkinitrd [--with= Module] initramfs-version number. IMG Version number

#mkinitrd [--with= Module] initramfs-$ (uname--r). IMG $ (UNAME-R)

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M00/8E/87/wKioL1jDtOTxHhDmAACygVxGNS4914.jpg-wh_500x0-wm_ 3-wmp_4-s_1211177338.jpg "title=" init.jpg "alt=" Wkiol1jdtotxhhdmaacygvxgns4914.jpg-wh_50 "/>

Figure 6



(3) Kernel initialization

After the kernel file is read by bootloader, it is extracted into memory, and the kernel function is used to check the hardware and load the driver, i.e. test and drive the peripheral devices (CPU, storage device, network card, sound card, etc.). At this point the Linux kernel will recheck the hardware with its own functionality, not necessarily the hardware information in the BIOS. That is, the kernel is only starting to take over the BIOS after the current operation. The root partition is then mounted in a read-only manner, followed by loading the initial process systemd (/USR/SBIN/SYSTEMD/SYSTEMD), where in CENTOS7 version the initial process is init (/usr/sbin/init)


650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/8E/8A/wKiom1jD59ix0Xd_AADDWGtMANg222.jpg-wh_500x0-wm_ 3-wmp_4-s_3988998021.jpg "title=" inittable.jpg "alt=" Wkiom1jd59ix0xd_aaddwgtmang222.jpg-wh_50 "/>

Figure 7





4. Stage four: Systemd (init)


After the kernel is loaded, the hardware is checked and the driver is loaded, the host hardware is ready, and the kernel starts the first process (/USR/SBIN/SYSTEMD/SYSTEMD or/etc/inittab). This is the first call to use a standard C library compiled program whose process number is always 1.

Init is responsible for triggering other necessary processes to bring the system into a usable state. Init's work is done according to the/etc/inittab file, including setting up the Getty process to accept user logins, setting up keyboards, word maps, networks, and more. Without these processes, the kernel does not make much sense even if it starts successfully. 8


650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/8E/88/wKioL1jD6oKDpnh1AACH4rfW_FQ892.jpg-wh_500x0-wm_ 3-wmp_4-s_1292955029.jpg "title=" getty.jpg "alt=" Wkiol1jd6okdpnh1aach4rfw_fq892.jpg-wh_50 "/>

Figure 8


REDHAT7 system, the/etc/inittab file is no longer used, change the file only have some explanatory information, as follows:

[Email protected] ~]# Cat/etc/inittab # inittab is no longer used when using systemd.## ADDING CONFIGURATION here would H AVE NO EFFECT on YOUR system.## ctrl-alt-delete are handled by/usr/lib/systemd/system/ctrl-alt-del.target## SYSTEMD uses ' Targets ' instead of runlevels. By default, there is both main targets:## multi-user.target:analogous to RunLevel 3# graphical.target:analogous to Runle Vel 5## to view current default target, run:## to set a default target, run:# systemctl set-default target.target#[[email Protected] ~]#







Reference documents:

[1] Zhang Tongguang.    Linux operating System (Rehl 7/centos 7). Beijing: Tsinghua University Press, 2014.

[2] brother Bird.    Brother Bird's Linux private dish (third edition). Beijing: People's post and Telecommunications press, 2015.

[3] Wu Guowei and so on.    Deep understanding of Linux driver design. Beijing: Tsinghua University Press, 2015.

[4] Ning.    The path to the Linux kernel's cultivation. Beijing: People's post and Telecommunications press, 2010.

This article is from the "11929788" blog, please be sure to keep this source http://11939788.blog.51cto.com/11929788/1905441

Linux system detailed startup process

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.