Linux boot process analysis and grub boot program

Source: Internet
Author: User

Linux boot process analysis and grub boot program

Boot is simple for each of us. But what process does it take to start the entire boot process?

Generally, the Linux boot process follows the following steps:

1. Load BIOS hardware information, perform self-check, and obtain the first startup device according to the settings.

2. read and execute the Boot Loader (grub) of the MBR in the startup device)

3. When bootloader loads the kernel, the kernel detects the hardware and loads the driver.

4. Start the INIT program in the kernel

5. system initialization: (/etc/init/RCs. conf exec/etc/rc. d/rc. sysinit)

6. Locate the/etc/inittab file in init and determine the default running level of the system (/etc/init/RCs. conf exec telinit $ runlevel)

7. The runlevel event that triggers the response (/etc/init/rc. conf exec/etc/rc. d/RC $ runlevel)

8. The scripts in/etc/rcX. D are started in the pre-set priority order (essentially the service)

9. finally run/etc/rc. d/rc. Local (custom Boot Program)

10. Load the terminal or X-Window Interface

 

MBR and bootloader

After the BIOS self-check is completed, the boot loader in MBR will be executed. We know that MBR is generally installed in the primary Boot Sector of the hard disk (0 cylinder, 0 head, 1 sector), a total of 512 bytes, the following is a MBR composition diagram:

Boot Loader

It can be seen that boot loader occupies 446 bytes in MBR, and its main function is to load the system kernel from the file system to the primary memory for execution. It can be seen that a premise for boot loader to guide the system is that it can identify the file system on the operating system. Since MBr has only one boot loader, and there may be multiple operating systems on the hard disk, what if the boot loader in MBR can only recognize one operating system?

To enable multiple boot operations, we need to know in advance that the boot program can not only be installed in MBR, but also in the super block on the file system partition. In addition, the Bootstrap program can do the following:

1) directly load the core to the memory for execution

2) transfer control to another Loader

Here, you may understand how multiple startup is implemented. If we have two operating systems: Windows and Linux, Windows is installed in/dev/sda1, and Linux is installed in/dev/sda2. Boot programs are also installed in their superblocks. The boot program in MBR is the grub program that can identify the two operating systems at the same time.

Then, grub of MBR can do the following:

1) directly load the/dev/sda2/boot/vmlinux core to start

2) Transfer the control to the boot loader in the super block of/dev/sda2 for management.

3) Transfer the control to the boot loader in the super block of/dev/sda1 (Windows) for management.

Note:: In Linux, you can choose to install the boot loader in MBR or super block. In Windows, the boot loader is installed in both MBR and super block by default, windows boot loader does not have the control transfer function by default. This is why we first install windows and then install linux when installing multiple systems. If Windows is installed later, then its boot loader will overwrite the boot loader in MBR.

Important:The purpose of the boot loader is to load the kernel.

 

Grub pilot process

The boot program is very powerful and involves many configuration files. However, we can see that MBR has a maximum of 512 bytes, so where are the configuration files?

In fact, the bootstrap loader is usually executed in two phases:

Stage1: it is the main program that directs the loader, essentially MBR.

Stege2: it is the configuration file related to the boot loader. Generally, the configuration files are placed under/boot.

 

Understand the files under/boot

Put the startup-related files under/boot.

Vimlinuz:This is the most important Kernel File;

Config-2.6.32-71.el6.i686:The configuration file of the system knerl, Which is saved after the kernel is compiled;

GRUB:Bootstrap related directory

Initramfs-2.6.32-71.el6.i686.img:In the virtual file system, your related files replace the previous initrd files and are used to load some core modules.

System. map-2.6.32-71.el6.i686:Table of variables in the System Kernel

Symvers-2.6.32-71.el6.i686.gz:Module Symbol Information

 

Understand the grub. conf file under/boot/GRUB

This file is the configuration file that the boot program needs to find before loading the kernel. The configuration file format is as follows:

Default = 0

Timeout = 5

Splashimage = (hd0, 0)/GRUB/splash.xpm.gz

Hiddenmenu

Title cenos (vimlinuz-2.6.32-71.el6.i686)

Kernel/vimlinuz-2.6.32-71.el6.i686roroot = UUID = be033dfc-63e2-491e-ae9e-2c884c6fead5

Initrd initramfs-2.6.32-71.el6.i686.img

 

Default indicates the default mounted kernel, 0 indicates the first title, 1 indicates the second, and so on.

Timeou = 5 indicates that if hiddenmenu is set, it will wait for 5 seconds. If no key is pressed, the default kernel will be loaded.

Splashimage is the selected background image.

Below is the main loaded core image file.

Note: When we fail to boot normally due to a grub error, we can manually load the core, for example, go to the grubshell interface after the boot. The procedure is as follows:

First, find the location of/boot/GRUB:

Find/boot/GRUB

Suppose it is (hd0, 0)

Then specify the/boot Zone

Root (hd0, 0)

Load the driver

Kernel/vimlinuz-2.6.32-71.el6.i686roroot = UUID = be033dfc-63e2-491e-ae9e-2c884c6fead5

Initrd initramfs-2.6.32-71.el6.i686.img

Finally, start

Boot

In this way, the system can be started normally.

 

The hard disk partition Representation Method in GRUB:

Grub requires that all device names be included in (). The hard disk is represented by HD, And the floppy disk is represented by FD. Second, the device is numbered from 0, and the same is true for the partition. the device and the partition are separated by commas. If no partition is specified, it indicates MBR.

First

(Hd0) (hd0, 0) (hd0, 1 )........

Second

(Hd1) (hd1, 0) (hd1, 1 )........

.

.

.

.

 

 

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.