"Research mission" Linux system boot-up process

Source: Internet
Author: User

General overview

Load BIOS

    • A special one should generate a reset logic value on one pin of the CPU, and then set some registers (including CS and EIP) to a fixed value

    • Then execute the code found at the physical address of 0xFFFF FFF0, the hardware maps this address to a read-only, persistent memory chip, which is usually rom

    • And the assembly stored in the ROM is usually called the BIOS in the 80x86 body system.

The BIOS consists of two parts: The post code and the runtime service


Loading MBR

The first sector of the No. 0 trackon the hard disk is called the MBR, that is, the master boot record, which is the master boot recording, its size is 512 bytes, although the place is not big, but it is stored in the pre-boot information, partition table information.

when the system locates the MBR of the hard disk specified by the BIOS , it is copied to the physical memory where the 0x0000 7c00 address resides. In fact, the content copied to the physical memory is boot Loader, and specifically to your computer, that is LILO or grub (Grub is the original bootloader).

Extracting information from MBR

To see the contents of the MBR, use the following command

Reads the first 512 bytes of content #从/dev/sda and writes it to a Mbr.bin file

[[email protected] pam.d]# dd IF=/DEV/SDA of=mbr.bin bs=512 count=1

#以十六进制和ASCII码格式打印这个二进制文件的内容

[Email protected] pam.d]# Od-xa Mbr.bin

Load bootloader

in the embedded system, start the first step, the second step does not exist, and run directly from Bootloader .

Boot Loader is a small program that runs before the operating system kernel runs. Initialize the hardware device, set up a map of the memory space , and bring the system's hardware and software environment to a suitable state in order to prepare for the final call to the operating system kernel . The system reads the GRUB configuration information in memory ( typically menu.lst or grub.lst) and launches a different operating system according to this configuration information.

    • The bootloader starts in RAM from the address of 0x0009 0200, and the setup () function is linked here and then jumps to setup () to start execution, initializing the hardware device again (the BIOS is initialized)

    • Setup () ends up jumping to startup_32 (), which extracts the kernel, which is referred to in the fourth step, and jumps to 0x0010 0000.

    • Executes the second startup_32 () function, which is the same as the previous function name, but differs from the starting physical address, and the end of the function jumps to Start_kernel ().

    • Executes Start_kernel (), which completes the initialization of the Linux kernel. , almost every kernel component is initialized by this function.

Load kernel

based on the path of the kernel image set by grub (Bootloader gives the image path), the system reads the memory image and does the decompression operation . At this point, the screen will generally output "uncompressing Linux" prompt. When the decompression core is complete, the screen output "OK, booting the kernel".

The system places the extracted kernel in memory and calls the Start_kernel () function to start a series of initialization functions and initialize the various devices to complete the Linux core environment. At this point, theLinux kernel has been established , Linux-based programs should be able to run properly.

At this point, the Linux kernel has been built up.

Set the Run level

After the kernel is loaded, the first program to run is /sbin/init, which reads the/etc/inittab file and initializes it based on the file.

In fact, the main function of the/etc/inittab file is to set the Linux operating level , which is set in the form of ": Id:5:initdefault:", which indicates that Linux needs to run on level 5. Linux runs at the following levels:

0: Turn off the machine

1: Single-user mode

2: Multi-user mode with no network support

3: Multi-user mode with network support

4: reserved, not used

5: Multi-user mode with network support with X-window support

6: Reboot the system, that is, restart

Initializing system settings

After setting the operating level, the first user layer file that the Linux system executes is the /etc/rc.d/rc.sysinit script, which does a lot of work, including setting the path, setting the network configuration (/etc/ sysconfig/network), start swap partition, set/PROC, etc.

Booting the kernel module

Load the kernel modules according to the files in the /etc/modules.conf file or the /etc/modules.d directory.

Perform different levels of scripting

Depending on the runlevel, the system will run the appropriate script from RC0.D to RC6.D to perform the appropriate initialization and start the appropriate service.

Performing personalization Programs

Rc.local is the place where Linux is left to the user to personalize after all initialization work . You can put the things you want to set up and start up here.

Enter login status

Executive/bin/login

Grub is a system boot program, which is divided into two stages: the first stage : stored in the MBR, compiled with the Assembly, that is, the bootstrapper part of the MBR, features include : ① basic Hardware Device initialization (block all interrupts, Close processor internal instruction/data cache, etc.); ② prepares space for loading another part of Grub Stage2, ③ if from a solid state storage medium, copy grub Stage2 to ram space, ④ set stack, ⑤ jump to Stage2 C program entry point; Second stage : usually written in C, features include : ① initializes the hardware devices used in this phase, ② detects system memory mappings, ③ reads kernel and root file system images from Flash into RAM, ④ sets startup parameters for the kernel, and ⑤ calls the kernel. ----------Delimiter------------The second stage is usually saved in/boot/grub, when we start the system into the grub interface, we see the selection information, and if we compile the system kernel, we can choose to boot from a kernel. Also note the GRUB configuration file and the kernel in the/boot partition. As can be seen from the previous analysis , the first stage of grub needs to read the boot program into MBR, the second stage needs to read the system kernel and configuration file to/boot partition.


"Research mission" Linux system boot-up 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.