Linux boot process

Source: Internet
Author: User

The boot process for Linux systems is divided into three phases.

Phase 1: boot-> post-> int19-> BIOS-> MBRWhen the user powers on the computer, the computer will perform a series of checks on the system hardware configuration. This process is called post (power on self test), that is, the power-on self-check process. After the system test is successful, the interrupt vectors of the BIOS interrupt handler are assembled into a memory of 1024 bytes. Among these interrupt vectors, the initial Bootstrap program is assembled with the interrupt type of 19h. After the interrupt vector ends, the CPU execution type is 19h. Its function is to execute the BIOS system initialization program, which is called Disk Auto-lifting interrupt or reboot interrupt (reboot interrupt ), when you press CTRL + ALT + DEL, the system will be interrupted on the 19h and reboot the system. The CPU executes the initial boot program interrupted on the 19h to read the boot program bootsect. s that loads the operating system from the boot disk. The initialization boot program searches for the MBR of the corresponding disk according to the boot sequence set in the CMOs. If the boot program is found, the boot program in the MBR is read to the memory at 0000: 7c00, run the Bootstrap program to transfer all kernel code to the memory. Stage 2: MBr-> lilo-> active partitions guide LinuxThe initial boot program reads lilo from the MBR into the memory and executes it. Lilo loads all linux kernels into the memory. In addition to lilo boot, Linux can also use grub and other boot programs to boot. Lilo functions are completed by three main programs: the first is to write executable code of the Linux kernel or other operating systems into the memory boot program, called the boot loader; the second load writes the executable code of the boot loader program to the boot partition and backs up the original boot loader. the executable file is/sbin/Lilo; the third is the/etc/Lilo that stores the Lilo configuration information. conf and other configuration files. All three files are required for Lilo startup. After the boot program successfully completes the boot task, Linux takes control of the CPU from their hands, and then the CPU begins to execute the Linux core image code and starts the Linux Startup Process. This involves some files under "arch/i386/Boot" in the Linux source code tree. Bootsect. S is the source code for generating the Boot Sector. After loading, it directly jumps to the program entry of setup. S. Setup. the main function of S is to copy system parameters (including memory, disks, etc., returned by the BIOS) to the special memory so that the code in the protected mode of these parameters can be read in the future. Setup. s also includes the code in video. s to detect and set the display and display modes. Finally, setup. s converts the system to the protection mode and jumps to 0x100000. This memory address stores the decompressed kernel. Because the kernel provided by RedHat contains a large number of drivers and functions, makebzimage is used in kernel compilation, to generate a compressed kernel, the kernel is often named vmlinuz in RedHat. In the initial Linux boot, head in "arch/i386/boot/compress/" is used. s uses Misc. run the decompress_kernel () function defined in C to decompress the kernel vmlinuz to 0x100000. When the CPU jumps to 0x10000, startup_32 in "arch/i386/kernel/head. s" will be executed. It is also the entrance to vmlinux and then jumps to start_kernel. Start_kernel () is the definition function in "init/Main. c". start_kernel () calls a series of initialization functions to complete the setting of the kernel itself. The start_kernel () function does a lot of work to build a basic Linux core environment. If start_kernel () is successfully executed, the basic Linux core environment is established. At the end of start_kernel (), by calling the init () function, the system creates the first core thread and starts the INIT process. The Core Thread Init () is mainly used to initialize peripherals, including calling do_basic_setup () to load and initialize peripherals and their drivers. When the do_basic_setup () function returns Init (), the init () function opens the/dev/console device and redirects the three standard input/output files stdin, stdout, and stderr to the console. Finally, search for the INIT program in the file system (or the program specified by the init = command line parameter) and use the execve () system to call and load the INIT program. At this point, the init () function is complete, and the kernel boot is basically complete. Next, run init. The INIT process number is 1, which is the starting point of all processes in the system. After Linux completes kernel boot, it starts to run the INIT program. The INIT program needs to read the system running level set in the/etc/inittab configuration file. inittab is an unexecutable text file consisting of several lines of commands. Then run/etc/rc. d/RC. sysinit, while RC. sysinit is a bash shell script mainly used for system initialization, RC. sysinit is an important script to run at every running level. It performs the following tasks: Activating swap partitions, checking disks, loading hardware modules, and other tasks that require priority. After the RC. sysinit program is executed, init is returned to start the running-level daemon. Generally, the "/etc/rc. d/RC" program is executed. For the daemon that will run at each running level, you can use the system service in chkconfig or setup to set the source line. After the RC program is executed, init is returned and the terminal is created. Now the progress system environment has been set and various daemon processes have been started. Stage 3: Hardware Detection-> startup service-> login LoginAfter the above work is completed, the Linux system starts to check the hardware, start the corresponding service, and then log on to the system. For text login, Linux first uses the account verification program login to analyze the user name. After the user name is analyzed, login will search 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 to use. 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 login information (recorded in/var/log/lastlog) is output to the corresponding terminal, and the user is checked for new emails. Then set various environment variables. After various environment variables are set, a shell command line prompt is displayed, and the entire Linux 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.