Linux Startup Process

Source: Internet
Author: User

Let's start by pressing the computer power key.

(1) first, the motherboard BIOS power-on self-check. According to the textbook "Microcomputer principles", the CS register is set to 0 xFFFF, and other registers are cleared. Therefore, the CPU starts to execute from FFFF: 0000h, And the jump command is saved here, jump to the self-check program solidified in Rom. Therefore, the system hardware, including the memory, is self-checked.

When the BIOS detects that the hardware is normal and consistent with the CMOS settings, it checks the available boot devices according to the setup sequence of the boot devices in CMOS.

(2) If the disk is started, the BIOS first reads the MBR of the hard disk into the memory and checks the MBR end mark, if 0x55aa is used, valid MBR information is found (if 0x55aa is not used, check the next boot device), and the system boot program is found in the hard disk MBR area for execution.

MBR refers to the Master Boot Record, which is in the hard disk's three-dimensional address (cylindrical, Head, Sector) = (0, 0, 1 ). Generally, one sector of a hard disk is 512 bytes. The first 440 bytes in the MBR area are the code area, and the 1st-stage pilot code is saved, the main function is to check whether the hard disk partition table is correct and after completing the hardware self-check, hand the control to the system boot program on the hard disk, such as grub (Windows is NT-loader ).

The standard MBR Hard Disk Partition Table occupies 64 bytes. Each primary Partition Table occupies 16 bytes, it includes the bootable flag, file system format, the start and end of the partition head number, the sector number, and the total number of sectors. Therefore, a maximum of four primary partitions can be divided. To support more partitions, an extended partition and a logical partition can be further divided into multiple logical partitions. The entry of the extended partition occupies 16 bytes in the MBR area, that is, replacing one primary partition. The entry of the extended partition contains the logical Partition Table, which stores the entry of each logical partition. In summary, a maximum of one extended partition can be used only after the logical partition is divided.
+ Up to four extended partitions can be divided into N multiple logical partitions in a single extended partition (the upper limit seems to be 64, which is usually not enough ).

The end mark is used. If 0x55aa is used, the MBR information is valid.

(3) After the boot program in MBR gives control to grub, grub guides the Linux kernel and then starts the INIT process.

After grub completes the boot task, the CPU control is handed over to Linux, and the core image code of Linux is executed, starting the Linux Startup Process. This will use several files under ARCH/i386/boot/in the Linux source code tree.

Because the Linux Kernel provides a large number of drivers, the "makebzimage" option is often used in kernel compilation to generate the compressed kernel vmlinuz. During the Linux boot process, head. s under ARCH/i386/boot/compressed/decompress the kernel image vmlinuz to 0x100000.

Setup under ARCH/i386/boot. s. Copy the memory, disk, and other system parameters in the BIOS to the memory, so that these parameters are followed by the protected mode code, and then setup. S switches the system to the protection mode and jumps to the 0x100000 vmlinuz entry. The CPU jumps to start_kernel () in init/Main. C. This function calls a series of initialization functions to complete the kernel settings and build the Linux core environment. Start_kernel () finally calls Init (), and the system creates the first core thread.

The Core Thread Init () calls do_basic_setup (). This function loads and initializes peripherals and their drivers, and initializes the file system and the root file system. After Init (), open the/dev/console device and redirect stdin, stdout, and stderr to the console. Finally, the Core Thread Init () searches for the INIT program in the file system and uses the execve () System Call to load and execute the INIT program. Now the init () function is complete, and the kernel boot is complete.

(4) Init calls RC. sysinit and RC. RC. sysinit and RC return init after completing system initialization and Starting tasks of various services.

The INIT process number is 1, which is the starting point of all processes in the system. The INIT process reads the configuration file/etc/inittab, which specifies the default running level during system startup and the initialization script to be called by the INIT process.

The INIT process first runs/etc/rc. d/rc. sysinit. This script is an important script that must be run at each running level first to complete system initialization: Activate swap partitions, check disks, and load hardware modules.

The INIT process then runs the/etc/rc. d/RC Script with the running level as the parameter. If the current running level is 5: X11, the RC Script will execute/etc/rc. d/rc5.d/All RC startup scripts. These scripts are actually symbolic links pointing to/etc/rc. d/init. d. The rc startup script in/etc/rc. d/rc5.d/is usually a link file starting with K or S. For a start script starting with S, it will run with the start parameter. If a K-header link is found, the started daemon processes are stopped with the Stop parameter when they are in the running state (the file under/var/lock/subsys/is used as the flag, then run it again. This ensures that all related daemon will be restarted when init changes the running level.

At this time, the basic system environment has been set and various daemon processes have been started.

(5) Establish a terminal and log on to the system.

According to the/etc/inittab file, the next init can run the mingetty program in respawn mode to open 6 terminals at the level of 2, 3, 4, and 5, the mingetty program also displays a text logon interface.

Runlevel 5: The graphic logon interface is displayed in X11. After Successful Logon, enter the gnome window manager. The following describes how to log on in text mode.

In Linux, the Account Verification Program is login. login receives the username sent from mingetty as the username parameter. After analyzing the username, login searches for/etc/passwd and/etc/shadow to verify the password and set other information about the account, such as what is the main directory and what shell is used. If no main directory is specified, the root directory is used by default. If no shell is specified,/bin/bash is used by default.

After the login program is successful, the last logon information (recorded in/var/log/lastlog) is output to the corresponding terminal ), check whether the user has any new emails (in the/usr/spool/mail/user name directory ). Then, set various environment variables: For Bash, the system first finds and executes the/etc/profile script, then searches for the. bash_profile file in the user's main directory, and runs it if any. Other configuration files may be called in these two scripts. After all the configuration files are executed, various environment variables are also set, and the familiar CommandLine will appear.
Prompt.

The entire startup process ends.

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.