Preliminary analysis of Linux operating system startup process

Source: Internet
Author: User

Start the BIOS program

When the power key is pressed, the BIOS (Basic nput Output System) is run by the flash memory on the motherboard. The BIOS program will decompress itself into the system's memory and then read the information stored in the CMOS (complementary Metal Oxide Semiconductor) (e.g. system time, boot device sequence, etc.) to configure the system. Simultaneous self-test (post:power-on. Detects if there is a problem with the hardware of the system, and the BIOS will load the boot loader program in the MBR (Master boot Record: Primary boot sector) of the first boot device after the self-test passes.

One point to note is that the BIOS load bootloader is loaded by the INT 13 interrupt function of the hardware. That is, after the BIOS has read to the disk, this channel through the INT 13 to read the boot loader program in the first sector of the disk!

Here are a few of the BIOS programs:

  

Figure 1.1:bios Basic Configuration interface of the program

Figure 1.2:bios Interface for program to adjust device boot order

Start the bootloader program

There are a variety of bootloader under Linux, such as early default using Lilo and the current mainstream grub. Below is the current Linux system above the mainstream grub to explain what bootloader mainly do?

When Grub starts, it automatically reads the/boot/grub/grub.conf configuration file and executes the GRUB command in it! Figure 2.1 is a grub.conf configuration file above the centos6.5! The GRUB command is the part of the red box, which is divided into three parts:

Figure 2.1

1. Set the boot partition (Root command), the parameter passed to this command is partition, this command will parse and mount the partition, and then read the contents of the/Boot folder. As shown in 2.2, after executing the command, you will be able to read out the contents of the Boot folder!

Figure 2.2

2. Select the boot kernel file and set the kernel parameters (Kernel command)

3. Load the Initrd file and set the virtual file system. (INITRD command)

In particular, this INITRD file, which is actually a virtual file system (Initial RAM Disk). In a Linux system, some disk drivers are not compiled in the kernel, but are packaged into modules that are stored under the/lib/modules directory, and the drivers that load the disk are required after the kernel is booted. But/lib/modules has not been mounted, then there is a contradiction! In order to solve this contradiction, the concept of virtual file system is produced. We can say that the initrd file is loaded into memory (for fear of affecting the file system on disk, when the root mount is mounted in a read-only manner), virtual out of a root filesystem, then read the disk driver in the virtual root file system, and then mount the real root directory from the new one.

As shown in 2.3, these files are the extracted contents of the Initrd file.

Figure 2.3

Load system kernel and hardware drivers

After the GRUB program finishes running the above three commands, the kernel file (vmlinuz-$ (uname-r)) is unzipped into memory to start running! At this point, the kernel will re-detect the hardware and load the driver again! After the check is complete, the kernel calls the INIT program and creates the first process of the system!

Init process initialization of the system

After the INIT program is started, it will first read the/etc/inittab file to get the operating level (runlevel) of the OS. What is the level of operation, Linux under the system according to have network and X window to

The system is divided into seven levels of operation. Their contents are shown in 3.1:

Figure 3.1

This is a description of the pattern in the Linux/etc/inittab file.

Mode 0 represents the shutdown state, Mode 1 represents single-user mode (Maintenance mode), Mode 2 represents a multi-user command-line mode, but there is no network. Mode 3 represents a multi-user command-line mode that contains a network. Mode 4 is a system-reserved feature. Mode 5 represents the graphical interface mode. Mode 6 represents the state of the system restart.

Corresponds to each run level,/etc directory under the separate set of different directories, 3.2 is shown:

Figure 3.2

When the system runs a certain level, it runs the script file within the corresponding directory (/etc/rc[run level].D). The RC here represents the Run command, which is the order to run at the beginning, and the. D stands for directory, which represents the meaning of directories!

The Inittab file has the ability to set the boot level of the system, and there are other features, 3.3:

Figure 3.3

This is a description of the other configurations in the Inittab file above CentOS6.5.

In summary, after the INIT program has obtained the system's operational level, it will continue to perform the following functions:

Initialize the system (execute/etc/init/rcs.conf This script file or run some custom run-level programs via/etc/init/rc.conf)

Load system service items (run script files in/etc/rc[run level].d/)

Set the CTRL + ALT + DEL key function

Run the Mingetty to set up six corresponding terminals

Run terminal and accept user Login

When the initialization of the system is complete, the system will call the Mingetty function to set up the terminal and wait for the user to log in! Its concrete flow is this, the INIT process first fork a child process, and then this child process to exec a Getty program. Getty program will try to open a terminal, if it is successful, then go to the screen to display the login word, when the user typed the user name, the task of the Getty program is complete! It then invokes the login program in an exec manner. The login program reads the user name and user password, and then reads the shadow file to verify that the user's password is correct. If the password is incorrect, login exits by calling exit, at which point the init process re-fork to repeat the above steps.

If the password authentication succeeds, then the login program will set up some environment (such as setting working directory, setting UID and GID, user name, etc.) to run the system. Once these system environments are set up, the login program invokes the shell program via exec, which executes and reads some startup scripts (such as/ETC/BASHRC, etc.). After reading these startup scripts, the shell prints out the prompt and waits for the user to type the command! Our system is now up and running!

Preliminary analysis of Linux operating system startup 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.