Linux system Boot

Source: Internet
Author: User

In this article, we press the power button briefly to be able to log in to the system, during which time the system and computer hardware work together. As a summary of their own knowledge, it is possible to linux0, master please skip.

In general, Linux startup can be divided into three stages: the BIOS phase, the system boot phase, the system startup phase.

First, the BIOS phase

The BIOS (basic input and output system) is a program that is cured in the computer ROM. This is before the installation of the computer has been cured well.

The computer has some knowledge of the students should know that the computer is by the CPU, memory, hard disk, display and so on plus an iron box package up, and the computer is executed by the CPU instructions to execute and direct the other hardware together to complete the normal execution of the computer.

When we press the computer to start the button. The power component of the computer is powering up the CPU and other hardware, and then the CPU starts executing the first instruction. The address of the first instruction is the one where the BIOS is located. That is, the BIOS is the first program that is executed in the computer, before the operating system (LINUX,WINDOWS,OSX, etc.). Again this "address", the CPU's instruction address is identified by the CPU two registers (CS:IP), and the CPU hardware logic is designed to power up after CS is all F, the IP is full 0, so this "address" is 0xffff0 (calculation method: CSx16 + IP)

The main function of the BIOS is to detect whether the basic hardware of the computer meets the execution requirements, and to initialize the hardware status, interrupt vector table, interrupt service program, etc. The first sector (MBR) of the bootable media (which is now the hard disk) is loaded into memory based on the hardware information obtained, and the control is transferred to the program, which is the second phase of execution.

Second, the system guidance stage

MBR is a 512-byte size mapping, specific information can be tested (image from the Linux Boot Process Insider):


Bootloader: Boot Program

Partition table: Hard disk partition information

Magic number:mbr identification, the normal value is: 0xaa55


In fact, the bootloader here is not all of the boot program, but only a small part of the bootloader (because the MBR space is too small to fit the entire bootstrapper) we call the first stage boot program. The main task is to load the remainder of the boot program, which is called the second-stage boot program.

The main function of the second stage boot program is to load the operating system and transfer control to the kernel.

The common boot program has lilo,grub and so on.

Iii. system implementation Start-up phase

The Linux kernel code is now very large. After compiling, generally there are still about 5 m, so they are compressed by bzimage way. Early code runs in a sequence that looks at the Linux boot Process insider and Linux boot process overview.

At the time of writing, the kernel has 3.17 version number, in the new version number:

1, the kernel code entry is arch\x86\boot\header. S, this assembly code is converted to protected mode (32-bit) by calling the main function in MAIN.C under the same folder as the actual mode (16-bit).

2. Protected_mode_jump (Boot_params.hdr.code32_start, (u32) &boot_params + (DS () << 4)); The call to the function jumps to the Run at the startup_32 label in the X86/boot/compressed/head_32.s. This code calls the Decompress_kernel function to extract the kernel (bzimage) image file.

The specific jump process can be tested: Linux kernel boot processes

3, and jump to the startup_32 label in X86/kernel/head_32.s to run. This code calls the I386_start_kernel function, and I386_start_kernel calls the main function Start_kernel of the Linux kernel.

Note: The 64-bit has a corresponding HEAD_64.S assembly code. The process is very similar.

4. To compare Linux to an application, Start_kernel is the main function of Linux. The preceding code is just a preparation for Linux execution.

In this function, we begin the familiar actions of initializing the kernel modules. Like lock mechanism. Initialization of process scheduling, file systems, and so on.

Last Call Kernel_thread (Kernel_init, NULL, CLONE_FS | Clone_sighand) to run the first process "init" process under the Linux system.

The initialization of the 5,linux application layer is completed by the INIT call initiation script, and finally the process of invoking a login is able to display our login interface. The most common init here is sysvinit, Upstart, Systemd.


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

Linux system Boot

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.