Diagram Linux boot process

Source: Internet
Author: User


Overview

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvwuvzvufor0vo/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">

Figure 1 Linux system process big view

First Stage boot loader

The master boot loader in the MBR is a 512-byte image, which includes the program code and a small partition table (see Figure 2). The first 446 bytes are the master boot loader, which includes the running code and the error message text. The next 64 bytes are the partition table, which includes 4 partitions of records (the size of each record is 16 bytes).

The MBR ends with a byte (0xaa55) of two special digits. This number is used to check the validity of the MBR.

Figure 2 MBR Anatomy

Second Stage boot loader

The secondary boot loader (the second-stage boot loader) can be more visually called the kernel loader.

The task at this stage is to load the Linux kernel and the optional initial RAM disk .

GRUB Stage Boot Loader

/boot/grubThe folder includes thestage1stage1.5Andstage2Boot loader. And very many other loading programs (for example, Cr-rom uses aiso9660_stage_1_5)。

About GRUB. The very good thing is that it includes knowledge about the Linux file system. GRUB does not use bare sectors like LILO. Instead, the Linux kernel can be loaded from the ext2 or ext3 file system. It does this by converting the two-phase boot loader into a three-stage boot loader.

Phase 1 (MBR) guides a phase 1.5 boot loader that understands the special file system that includes the Linux kernel image.

Examples of this include reiserfs_stage1_5 (to be loaded from the Reiser log file system) or e2fs_stage1_5 (to be loaded from the ext2 or ext3 file system). When the boot loader for phase 1.5 is loaded and executed, the boot loader for phase 2 is able to load.

When phase 2 is loaded, GRUB will be able to display a list of available cores on request (/etc/grub.confare defined in the. There are several soft symbolic links at the same time/etc/grub/menu.lstAnd/etc/grub.conf)。 We were able to select the kernel and even change the additional kernel parameters.

In addition, we are able to use a command line shell to perform advanced manual control of the boot process.

After the second stage of the boot loader is loaded into memory, the file system can be queried. and load the default kernel image and initrd image into memory . When these image files are ready, the boot loader for phase 2 will be able to invoke the kernel image.

Kernel

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvwuvzvufor0vo/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">

Figure 3 Linux Kernel i386 boot function flow

by callingstart_kernel。 A series of initialization functions are called to set interrupts, run further memory configurations, and load the initial RAM disk. Finally, to invoke thekernel_thread(Inarch/i386/kernel/process.c) to start theinitFunction. This is the first user-space process (user-space). At last. Start an empty task. Now the scheduler is able to take over control (calledcpu_idleLater). By enabling interrupts, the preemptive scheduler can periodically take over control to provide multitasking capabilities.

During the kernel boot process, the initial RAM disk (initrd) is loaded into memory by the Stage 2 boot loader, which is copied into RAM and mounted on the system. This oneinitrdis used as a temporary root file system in RAM and allows the kernel to fully boot without mounting any physical disk. Because the modules that are required to interact with the peripheral devices may beinitrd, so the kernel can be small, but it still needs to support a large number of possible hardware configurations. After the kernel boots, it is possible to formally equip the root filesystem (bypivot_root): This willinitrdThe root file system is unloaded and the real root filesystem is mounted.

Decompress_kernel output

The function decompress_kernel is where we usually see the decompression message:

Uncompressing Linux ... Ok, booting the kernel.

initrdfunction allows us to create a small Linux kernel. Contains drivers that are compiled as a loaded module. These loaded modules provide the kernel with a way to access the file system on disk and disk, and provide drivers for other hardware. Because the root file system is one on the diskFile SystemSoinitrdThe function provides a startup method to gain access to the disk and mount the real root filesystem. In an embedded environment without a hard drive,initrdCan be the root filesystem at last, or it can be mounted on a network file system (NFS) to mount the last root file system

Init

Once the kernel is booted and initialized, the kernel is able to launch its first user-space application.

This is the first call to a program compiled using the standard C library. Until then, no standard C application has been run.

On a desktop Linux system, the first program to start is typically/sbin/init。 But that's not certain. Very few embedded systems will need to useinitThe rich initialization functionality provided by the/etc/inittabConfigured).

In very many cases, we were able to invoke a simple shell script to launch the required embedded application.



Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

Diagram Linux boot 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.