The boot process refers to the whole process of powering up the computer until Linux displays the user's login screen. Analyzing the Linux boot process is also a great way to get a good idea of how Linux works.
Start the first step-load the BIOS
When you turn on the computer, the computer first loads the BIOS information, and the BIOS information is so important that the computer must find it at the very beginning. This is because the BIOS contains information about the CPU, device startup sequence information, hard disk information, memory information, clock information, PNP features, and so on. After that, the computer is in the heart of the spectrum, know should go to read which hardware device. After the BIOS has given control of the system to the first sector of the hard disk, Linux is in control of the system.
Start Step Two--read the MBR
The first sector on the No. 0 track on the hard drive is called the MBR, which is the master boot record, the master boot log, which has a size of 512 bytes, but contains pre boot information and partitioned table information. Can be divided into two parts: the first part of the boot (pre-boot) area, accounting for 446 bytes; The second part is divided into partition table (PARTITION pable), a total of 66 bytes, recording the partition information of the hard disk. One of the effects of the pre-boot zone is to locate the partition marked as active (active) and read the boot area of the active partition into memory.
When the system finds the MBR of the hard disk specified by the BIOS, it copies it to the physical memory of the 0X7C00 address. Actually copied to the physical memory content is the boot Loader, and specifically to your computer, that is LILO or grub.
Start step three--boot Loader
The Boot Loader is a small program that runs before the operating system kernel runs. Through this small program, we can initialize the hardware device, set up a map of memory space, so that the system's hardware and software environment to a suitable state, so as to finally call the operating system kernel to do everything ready. Typically, Bootl Oade: is heavily dependent on hardware, and different system architectures have different boot Loader.
Linux boot sector content is written in assembly language program, its source code in the Arch/i386/boot (different system CPU has its respective boot directory), there are 4 program files:
Bootsect. S, the main program of the boot sector, the compiled code does not exceed 512 bytes, that is, the size of a sector
Setup. S, booting the auxiliary program
Edd. S, part of the helper program, to support the BIOS Enhancement disk device service
Video. S, another part of the auxiliary program, for the screen display when booting
There are several types of Boot loader, of which grub, Lilo, and spfdisk are common loader, and here's a case of grub.
The system reads the GRUB configuration information in memory (typically menu.lst or grub.lst) and starts a different operating system according to this configuration information.
Starting step fourth-loading the kernel
Based on the path of the kernel image that is set by grub, the system reads the memory image and does a decompression operation. At this point, the screen will generally output the "uncompressing Linux" prompts. When the decompression kernel is complete, the screen output "OK, booting the kernel".
The system puts the extracted kernel in memory and calls the Start_kernel () function to start a series of initialization functions and initialize various devices to complete the Linux core environment. At this point, the Linux kernel has been established, Linux based programs should be able to run properly.
Start_kenrel () is defined in INIT/MAIN.C, which is similar to the main () function in a general executable program, where the system has previously done just some initialization that allows the kernel program to perform at a minimum, and the real kernel initialization process begins here. function start_kerenl () will invoke a series of initialization functions to complete all aspects of the kernel itself, in order to eventually establish a basic and complete Linux core environment.
The following actions are mainly performed in Start_kernel ():
(1) Print out the current kernel version information on the screen.
(2) perform setup_arch () and set up the system structure.
(3) executing sched_init () to initialize the scheduling mechanism of the system. Initialize the Runqueque on each available CPU, and then initialize the No. 0 process (whose task struct and system empty m stack have already been allocated in startup_32 ()) as the system idle process, that is, the process that occupies the CPU when the system is idle.
(4) perform parse_early_param () and Parsees_args () to resolve system startup parameters.
(5) Execute trap_in ItQ, set up the system interrupt vector table first. The trap door of number 0-19 is used for CPU exception handling, then initializes the system call vector, and finally calls the Cpu_init () to perfect the initialization of the CPU to support the process scheduling mechanism, including set flag bit registers, task registers, initialization program debugging related registers, and so on.
(6) Execute Rcu_init (), initialize the read-copy update mutex mechanism in the system.
(7) executes the INIT_IRQ () function, initializes the interrupt for the peripheral, completes the final initialization process to the IDT.
(8) perform init_timers (), Softirq_init () and Time_init () functions, respectively, the timer mechanism of the initial system, the soft interrupt mechanism, and the system date and time.
(9) Execute the Mem_init () function, initialize the page data structure descriptor of the physical memory pages, and complete the creation of the physical memory management mechanism.
(10) executing kmem_cache_init (), completes the initialization work to the general slab buffer management mechanism.
(11) Perform fork_init () to calculate the number of processes (threads) that the current system's physical memory capacity can allow to create.
(12) Executive Proc_caches_init (), Bufer_init (), Unnamed_dev_init (), Vfs_caches_init (), Signals_init () Such functions establish a dedicated slab buffer queue for various management mechanisms.
(13) executes the proc_root_init () WL number, initializes the virtual file system/Proc.
At the end of Start_kenrel (), the kernel creates the first system kernel thread (the 1th process) through Kenrel_thread (), which executes the init () function in the kernel and is responsible for the next stage of the startup task. Finally, call the Cpues_idle () function: Enter the system main loop body port the instructions in the Default_idle () function, that is, the CPU's halt instruction, will be executed by default until other processes in the ready queue need to be scheduled before they are moved to perform other functions. At this point, the only process in the system that has a ready state is the init process (kernel thread) created by Kerne_hread (), so the kernel does not enter the Default_idle () function, but rather the init () function to continue the START process.
This article URL address: http://www.bianceng.cn/OS/Linux/201410/45416.htm