First, let's take a look at the entire Linux boot process to understand these details.
Linux is very helpful:
First, press the switch on and start the process.
1. Power-on self-check and post
2. Check your hardware devices one by one based on the boot sequence set by boot sequence to find available
Boot Loader. After finding it, load the bootloader to the memory,
3. boot the first 446 bytes of the bootloader to boot the kernel of the Linux system to the memory, and then decompress the kernel,
At this time, the bootloader completes its task and exits,
4. Before the bootloader exits, the control is handed over to the kernel. The kernel starts system initialization,
Identify the basic hardware and load the driver,
5. Load the/sbin/INIT process, which is the first process in the system and the grandfather of all processes.
6. This process is executed under the definition of/etc/inittab,
7. Print the logon prompt after the INIT process is loaded,
Of course, this is just a rough introduction to the general process of starting the system,
Next we will explain each step,
Bootloader: two powerful
1. Lilo (Linux Loader), which can guide multiple Linux systems, but it has a defect that it cannot
Bootstrap a partition other than 1024 Cylinders
2. Grub (Grand uniied bootloader) is very powerful. It can not only guide Linux, but also
Boot Windows, or even boot Unix. It does not have Lilo defects and can drive any partition of a large hard disk.
And grub itself does not need to be installed in MBR,
It can even be installed in the boot sector of a partition. However, grub must be unique if it is not in MBR.
Grub is usually installed in MBR, but the problem arises again. We know that
It contains only 446 bytes to store bootloader, and how does grub implement such a powerful function in such a small space?
, It is obviously a little difficult, so our grub does not limit itself to these 446 bytes, but puts itself
It is divided into N segments, which are mainly divided into two segments. The first segment is where the 446 bytes are placed in the bootloader. The purpose is
Start the second paragraph and do nothing else,
Stage1: boot stage2
Stage2: it is located on the disk partition, and the space on the disk partition is large. Generally, it not only provides you with pilot operations
The system can also provide users with a graphical interface. The picture is more than 446 bytes.
All are in the directory where the kernel is located,/boot/grub, so the first stage is to boot the second stage,
The second stage is under the/boot/GRUB directory. In this stage, there is also a configuration file named grub. conf, while the second stage
The phase is run at the control of the configuration file.
In fact, grub is in three phases, and there is another compaction Phase 5. Let's take a look at it at/boot/grub.
These kernel 5 are actually different file systems, which means that the second stage is likely to be in different file systems,
Therefore, this is mainly used to load a specific file system, or to drive a specific file system.
In this directory, there is a red-style splash.xpm.gz file, which is the system choice when you start the system.
If you think it is ugly, you can change it to the image you like.
Simple
Let's summarize grub's functions:
1. allows you to select an operating system
2. After you select an operating system, you can also pass a parameter to the kernel of the operating system.
In other words, grub also has the editing function. In the editing mode, you can directly pass parameters to the kernel.
3. the encryption protection function is to set a password for your kernel.
Prevent your kernel from accepting parameters passed by anyone except you
Next, let's take a look at the kernel loading process.
Generally, the kernel is an independent partition on our system, which is directly mounted to the/boot directory.
That is to say, in general, the kernel is here, there is a file called vmlinuz-2.6.18-el5 is us
Is only one of the versions, followed by the main version number, minor version number and other information, this kernel
It is usually very small. On the one hand, it is because of compression, on the other hand, it is because many functions and drivers are made into modules.
Outside the kernel, our kernel files are stored in the boot directory.
Our grub is also in this directory, so we can see that this boot directory is very important, this partition
The entire Startup file of the operating system is stored in this directory,
Grub needs to load the kernel to start the system. to load the kernel, you need to find it in this partition.
Some drivers need to be loaded, and some additional files need to be located in this partition. Grub itself is located in this
Partition, and all the boot processes of grub are dependent on
The 446-byte boot program, which can load in addition to a basic disk partition
Some programs have no meaning, and other programs without additional functions cannot be loaded,
Therefore, the device where the partition is located cannot be a soft RAID device or an LVM device, because
These devices require a driver, but they cannot store so much content in the 446 bytes. They can be used at most.
Raid 1, because it is an image disk, as long as one of them is enough, it is generally recommended that
The partition is placed on a basic disk partition, which is why it is partitioned independently.
There is also an initrd file in this directory, which is not the same as our kernel except for the start.
The rest are basically the same. Decompress this package and you will find that it is a complete Linux system, so it is used to virtualize
Linux and the file system, let the kernel load up, and then provide a driver that allows the kernel to read the real root partition,
Therefore, after the kernel is installed in, it will immediately read the file, expand it, read the driver, and then read the real
File system, then the kernel completes initialization, and then runs the next program
Kernel:
1. Perform hardware testing.
2. driver initialization
3. Load the root file system in read-only mode
4. Install and start the INIT process
After the kernel task is completed, the permission is granted to the INIT process.
This program is/sbin/init. The work of this process is completed under the control of inittab,
The format is mainly four segments separated by colons:
Section 1: purely indicating Information
Section 2: runlevel. Operation level, mainly used to define the third-stage action
Section 3: Action, used to define how to start this process
Section 4: Process
After completing the preceding steps, execute mingetty and print a login. After the system is started, mingetty is basically finished.