The origin of the UNIX directory structure
Linux Start-up process
Linux Boot Process Insider
Embedded system Boot Loader Technology Insider
1. Simple Dictation
1.开机BIOS自检2.MBR引导3.grub引导菜单4.加载内核kernel5.启动init进程6.读取inittab文件,执行rc.sysinit,rc等脚本7.启动mingetty,进入系统登陆界面
2, simple illustration
3, complex plots
Introduction of Linux system boot-up process
4, detailed description
Reference
开机BIOS自检阶段读取MBR信息进入grub引导菜单加载kernal内核init进程加载inittab文件init进程执行rc.sysinit脚本程序启动内核模块执行不同运级别的脚本程序执行/etc/rc.d/rc.local脚本执行 /bin/login 程序,启动 mingetty mingetty,进入登录状态
Start the first step-load the BIOS
When you turn on the computer, the computer loads the BIOS information first, 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 boot sequence information, hard disk information, memory information, clock information, PNP features, and so on. After that, the computer has a spectrum and knows which hardware device to read. After the BIOS has given control of the system to the first sector of the hard disk, Linux has started to control the system.
Start the second step-read MBR
The first sector of the No. 0 track on the hard disk is called the MBR, which is the master boot record, which is the main boot recording, it is 512 bytes in size, but it contains pre-boot information and partition table information. Can be divided into two parts: the first part is the boot (pre-boot) area, accounting for 446 bytes, the second part is divided into partitioned table (PARTITION pable), a total of 66 bytes, recording the partition information of the hard disk. One of the functions of the Preboot zone is to find the partition marked Active (active) and read the boot area of the active partition into memory.
When the system locates the MBR of the hard disk specified by the BIOS, it is copied to the physical memory where the 0X7C00 address resides. Actually the content that is copied to the physical memory is boot Loader, and specifically to your computer, that is LILO or grub.
Start the third step--boot Loader
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 the memory space, so as to bring the system's hardware and software environment to a suitable state, in order to finally call the operating system kernel ready to do everything. Typically, Bootl Oade: is implemented heavily on hardware, with different boot Loader for systems with different architectures.
Linux boot sector content is written in assembly language program, its source code in Arch/i386/boot (different system CPU has its own boot directory), there are 4 program files:
◎bootsect.S,引导扇区的主程序,汇编后的代码不超过512字节,即一个扇区的 大 小◎setup.S, 引导辅助程序◎edd.S,辅助程序的一部分,用于支持BIOS增强磁盘设备服务◎video.S,辅助程序的另一部分,用于引导时的屏幕显示
There are several Boot loader, where grub, Lilo, and spfdisk are common loader, which is explained in grub as an example.
The system reads the GRUB configuration information in memory (typically menu.lst or grub.lst) and launches a different operating system according to this configuration information.
Start step fourth-load the kernel
Based on the path of the kernel image set by grub, the system reads the memory image and does the decompression operation. At this point, the screen will generally output "uncompressing Linux" prompt. When the decompression core is complete, the screen output "OK, booting the kernel".
The system places the extracted kernel in memory and calls the Start_kernel () function to start a series of initialization functions and initialize the 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 generic executable program, and the system has done only a few initialization operations that allow the kernel program to perform minimally, and the real kernel initialization process starts here. The function start_kerenl () will invoke a series of initialization functions to complete various aspects of the kernel itself, in order to eventually build a basic and complete Linux core environment.
The following operations are primarily performed in Start_kernel ():
(1) Prints the current kernel version information on the screen. (2) Execute Setup_arch () to set the system structure. (3) Execute Sched_init () to initialize the scheduling mechanism of the system. Initialize the Runqueque on each available CPU first, and then initialize the No. 0 process (whose task struct and system empty m stack is already allocated in startup_32 ()) as the system Idle process, which is the process that occupies the CPU when the system is idle. (4) Execute Parse_early_param () and Parsees_args () to parse the system startup parameters. (5) Execute trap_in ItQ, first set up the system interrupt vector table. Trap Gate number 0-19 is used for CPU exception handling, then initializes the system call vector, and finally calls Cpu_init () to complete the initialization of the CPU to support the process scheduling mechanism, including setting the flag Register, Task register, initialization program debug related registers and so on. (6) Executing rcu_init (), initializing the read-copy update mutex mechanism in the system. (7) Execute the INIT_IRQ () function, initialize the interrupt for the peripheral, and complete the final initialization process for IDT. (8) Execute 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) Execute Kmem_cache_init (), complete the initialization of the universal slab buffer management mechanism. (11) Execute Fork_init () to calculate the number of processes (threads) that the physical memory capacity of the current system 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) perform proc_root_init () WL number, initialize the virtual file system/proc.
At the end of Start_kenrel (), the kernel creates the first system kernel thread (that is, process 1th) through Kenrel_thread (), which executes the init () function in the kernel and is responsible for the next phase of the startup task. The last call to the Cpues_idle () function: Entering the main loop of the system will always execute the instruction in the Default_idle () function, the halt instruction of the CPU, until other processes in the ready queue need to be dispatched to perform other functions. At this point, the only process in the system that is in a ready state is the init process (kernel thread) created by Kerne_hread (), so the kernel does not enter the Default_idle () function, but instead moves to the init () function to continue the boot process.
Start the fifth Step-user layer Init sets the operating level according to the Inittab file
After the kernel is loaded, the first program to run is/sbin/init, which reads the/etc/inittab file and initializes it based on the file.
In fact, the main function of the/etc/inittab file is to set the Linux operating level, which is set in the form of ": Id:5:initdefault:", which indicates that Linux needs to run on level 5. Linux runs at the following levels:
0:关机1:单用户模式2:无网络支持的多用户模式3:有网络支持的多用户模式4:保留,未使用5:有网络支持有X-Window支持的多用户模式6:重新引导系统,即重启
Start the sixth step--init process Execution Rc.sysinit
After setting the operating level, the Linux system executes the first user layer file is the/etc/rc.d/rc.sysinit script, it does a lot of work, including setting path, setting the network configuration (/etc/sysconfig/network), Start swap partitions, set/proc, and so on. If you are interested, you can check the Rc.sysinit file in/etc/rc.d.
The final completion state of the thread init is to enable the normal user program to be executed normally, so as to really complete the system environment for the application to run. Its main operations are:
(1) Executes the function Do_basic_setup (), which initializes the external device completely.
(2) Build the system's virtual file system directory tree, hook up the system as the root directory of the device (its specific file system has been registered in the previous step).
(3) Turn on the device/dev/console and copy two times through the connection of the function sys_dup (), so that the file number 0,1, 2 all point to the console. These three file connections are commonly referred to as "standard input" stdin, "standard output" stdout and "standard error message" StdErr These three standard I/O channels.
(4) After all the above is ready, the system begins to enter the initialization stage of the user layer. The kernel uses the system call EXECVE () to load the corresponding user-level initialization program of the T-Sub, and then tries to load the program "/SBIN/INITL", "/etc/init", "/bin/init", and "/bin/sh" in turn. As long as one of the program loads succeeds, the system starts the initialization of the user layer without going back to the init () function segment. At this point, the init () function ends and the boot portion of the Linux kernel ends.
Start the seventh step--Start the kernel module
The kernel modules are loaded according to the files in the/etc/modules.conf file or the/ETC/MODULES.D directory.
Start step eighth-execute scripts with different runlevel
Depending on the runlevel, the system will run the appropriate script from RC0.D to RC6.D to perform the appropriate initialization and start the appropriate service.
Start Nineth Step--Execute/etc/rc.d/rc.local
If you open this file, there is a word, read it, you will be the role of this command at a glance:
# This script will be executed *after* all the other init scripts.# You can put your own initialization stuff in here if you don’t# want to do the full Sys V style init stuff.
Rc.local is the place where Linux is left to the user to personalize after all initialization work. You can put the things you want to set up and start up here.
Start Tenth Step--Execute/bin/login program, enter login status
At this time, the system has entered the waiting for the user input username and password, you can already use your own account login system.
[Svc]linux START process and level