Linux startup process under X86

Source: Internet
Author: User

Brief introduction

1. System power-on reset stage

2, BIOS boot, self-test

3. Loading MBR Master boot program

4. Load GRU Secondary boot program

5. Load operating system kernel

6, the first process running the operating system init

The first step, the system power-on reset phase

After the system is power-up or reset, based on the 80x86 feature, the CPU will clear all the data in memory and verify the memory. If there is no error, all of the 1,IP registers in the CS register are all set to 0, that is, cs=ffff[0]h, and Ip=0000[0]h. [Cs]:[ip] points to the BIOS entry, which enters the BIOS boot process.

During the system power-up boot process, only one CPU (bsp--boot CPU) is actually responsible for booting, while the other CPUs (ap--non-booting CPUs) are in an interrupt-blocking state waiting for the operating system to activate.

Second step, BIOS (Basic input/output system, base input and output systems) boot, self-test

The BIOS calls bootloader to load the kernel image of the operating system into the system RAM.

The X86 computer starts with a BIOS power-on self-test after booting, detects the computer's hardware devices, and then searches the active and bootable devices in the order of the CMOS settings.

The boot device can be a floppy disk, an optical drive, a USB device, and a hard disk setting is a device on the network.

(1), when the power of the PC is turned on, the CPU of the 80x86 architecture will automatically enter the real mode and automatically execute the program code from address 0xffff0000 (cs:0xffff,ip:0x0000), which is usually the address of the BIOS.
(2), the first post of the BIOS (power on the self test is a power-on after the test), detect some of the system's key devices are present and can work properly, such as memory and video cards and other devices. At this point the video card has not been initialized, if some fatal errors are found, such as no memory or memory problems (this time only check 640K of conventional memory), the BIOS will directly control the speaker voice to report errors, the length and frequency of the sound represents the wrong type.
(3), and then the physical address 0 begins to initialize the interrupt vector (Note: This BIOS interrupt vector is very important, many behind the hard disk and so on the interaction is done through this interrupt vector).

Third step, loading MBR (master boot record, master boot recording)

The BIOS will start the first sector of the device (the first sector of the No. 0 track is called the MBR is the master boot record, its size is 512 bytes, which contains pre-boot information written in assembly language, partition table information, magic number 0X55AA), read into the memory absolute address 0x7c00 Place, and jump to this address and execute. In fact, the content that is copied to the physical memory 0x7c00 is the boot Loader, which is bootsect for the older kernel to boot without grub. s program, and for now the majority of PCs using Grub boot, is LILO or grub.

The main bootloader's task is to find and load the secondary boot loader (GRUB) saved on the hard disk partition, which finds the active partition through the partitioned table and then reads the active partition's secondary boot loader from the device into memory and runs it into the second phase of the bootloader.

Fourth step, load grub (multiple OS boot manager)

Also known as the secondary boot loader, this phase of the task is to load the Linux kernel. Once the boot loader is loaded into memory, the grub graphical interface is displayed, in which the user can select the operating system to be loaded and their kernel via the UP and DOWN ARROW keys

GRUB is the abbreviation for Grand Unified bootloader, which is a multi-os boot manager.

Grub is now the mainstream boot for Linux, and of course now grub is not just a boot Linux system, it can boot to almost any system like Winodows, Mac OS, BSD, etc.

Some of the relevant configuration files for grub are stored in the/boot/grub directory.

Grub is the default bootstrapper for many of the current Linux releases. On embedded systems, the most common bootloader are u-boot. Such bootloader are generally located at the front of the MBR. On Linux systems, bootloader can also be written to the partition where the file system resides. For example, the GRUB program is very powerful. After the gurb is run, the environment required to set the kernel to run is initialized. Then load the kernel image.

Grub Disk Boot whole process:

(1) Stage1, Grub reads the first 512 bytes of the primary boot record of the disk MBR.

(2) stage1.5, identify a variety of file system formats, the purpose is to grub can recognize the file system.

(3) Stage2, Load System boot menu (/BOOT/GRUB/MENU.LST or grub.lst), load kernel Vmlinuz and RAM disk INITRD.

Configuration of Grub:

Grub configuration is mainly done by modifying the grub.conf file in the/boot/grub/directory, and the user can open the file for editing via VI or by using the file Editing tool in the graphical interface.

(1) Default option

(2) Timeout option

(3) splashimage option

(4) Hiddenmenu option

(5) Title option

(6) root (hdx,y)

(7) kernel option

Fifth step, load the operating system kernel

Boot grub to load the operating system kernel, Linux system kernel is stored in the/boot directory

Kernel image file Vmlinuz: An executable file containing a static link to the Linux kernel, traditionally known as Vmlinux, is called a bootable kernel image. Vmlinuz is a compressed file of Vmlinux. Its composition includes:

When the user chooses to start the Linux operating system, grub reads the Linux kernel image from the partition on which the/boot/resides, and then loads the kernel image into memory and gives control to the Linux kernel, based on the information set in the/boot/grub.conf configuration file. Once the Linux kernel has gained control, it will continue to boot the system as follows.

(1) The kernel image first detects the hardware devices in the system, including memory, CPU, hard disk, etc., and initializes and configures the devices.

(2) The kernel image is compressed, and then it needs to decompress itself and load the necessary device drivers.

(3) Initialize the virtual devices associated with the file system, such as LVM or software RAID.

(4) Mount the root file system (/) and mount the root file system to the root directory.

(5) After the boot is completed, the Linux kernel loads the INIT program in its process space and gives the controller to the INIT process, which continues the next system boot work by the INIT process.

Sixth step, run the first process on the operating system init

The init process is the starting point for all processes in the Linux system, and after the kernel is booted, the INIT process is loaded and its process number is 1. After the init process starts, the operating system is initialized and the Autorun program is started at a specific runlevel (Runlevel). Users can customize the services that need to run automatically at system startup by changing the relevant profile or by using the Graphical Configuration tool service configuration.

I. Introduction to THE INIT process

The kernel image starts the init process after the boot is complete. The execution file corresponding to the init process is/sbin/init, which is the initiator and controller of all processes in the system, and all processes are derived from it. If there is a problem with the INIT process, other processes in the system will be affected as well.

1. As the parent process reference object for all processes

2. Run different levels of programs

II. boot process of the INIT process

When the init process gains control, it first executes the/etc/rc.d/rc.sysinit script, configures the environment variables according to the code in the script, configures the network, enables swap, checks and mounts the file system, performs the steps necessary for other system initialization, and so on.

Linux startup process under X86

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.