Linux boot up

Source: Internet
Author: User

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/9C/76/wKiom1lwlyfAICp0AAIqEwMYP1Y027.jpg-wh_500x0-wm_ 3-wmp_4-s_695537357.jpg "title=" 4.jpg "width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:750px; height:500px; "alt=" Wkiom1lwlyfaicp0aaiqewmyp1y027.jpg-wh_50 "/>

A simple description of the Linux boot process:

1, Press the power supply

2, Blos self-test, check CPU, hard disk, memory, motherboard and other hardware

3, Enter the MBR master boot area and boot the system into

4. load The Grub menu and select the System kernel.

5, loading the kernel

6, run boot the first process init.

7. Read The/etc/inittab list and select the system runlevel.

8, run /etc/rc.d/rc.sysinit, Initialize system service, set host name,IP address, etc.

9, loading /etc/rc.d/rc3.d related services and software

Load The Mingettyand enter the login screen.


Linux boot- up process specific analysis:

the boot process refers to the power supply from the computer until LINUX Displays the entire process of user login screen. Analyzing The Linux boot process is also a great way to get an insight into the workings of the Linux core.

start the first step-- Load 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 gives control of the system to the first sector of the hard disk, it begins to be controlled by Linux .

start the second step-- Read MBR

hard plate 0 The first sector of the track is called the Mbr master boot record 512 bytes, but it contains pre-boot information, partition table information. Can be divided into two parts: the first part of the Guide ( pre-boot 446 bytes; The second part is partitioned table ( partitionpable active

System found After 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 BootLoader, 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. In general,Bootl Oade: is implemented heavily on hardware, and systems with different architectures have different BootLoader.

Linux Boot Sector content is written in assembly language program, its source code in the Arch/i386/boot ( different system CPU has its own boot directory ), there are 4 program Files :

Bootsect. S, the main program of the boot sector, the compiled code does not exceed the size of the bytes, that is, a sector of large small

Setup. S, boot Assist program

edd. S, part of the auxiliary program, to support the BIOS Enhanced disk device service

video. S, Another part of the auxiliary program for the screen display at boot time

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. Atthis 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 previously done only a few initialization operations that allow the kernel program to perform minimally. The real kernel initialization process starts here. The function start_kerenl () will invoke a series of initialization functions to complete the various aspects of the kernel itself, in order to eventually build a complete base Linux core environment.

The following operations are primarily performed in Start_kernel ():

(1) print out the current kernel version information on the screen.

(2) execute setup_arch () toset the system structure.

(3) execute sched_init () toinitialize the scheduling mechanism of the system. First , the Runqueque on each available CPU is initialized ; then initialize process number 0 ( its task struct and system empty M stack are already assigned in startup_32 ()) as the system idle process, which is the process that occupies the CPU when the system is idle .

(4) executes parse_early_param () and Parsees_args () to resolve system startup parameters.

(5) Execute trap_in itQ, set up the system interrupt vector table first. 0- the trap door for CPU exception handling ; then initialize the system call vectors ; finally call Cpu_init () to improve the initialization of the CPU to support the process scheduling mechanism, including setting the flag Register, Task register, initialization program debugging related registers and so on.

(6) executes rcu_init (), initializing the read-copy Update mutex mechanism in the system .

(7) executes the INIT_IRQ () function, initializes the interrupt for the peripheral, and completes the final initialization process for IDT.

(8) executes the 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) executes the Mem_init () function, initializes the page data structure descriptor for The physical memory pages , and completes the creation of the physical memory management mechanism.

(10) executes kmem_cache_init (), completing the initialization of the universal slab buffer management mechanism.

(11) executes fork_init () to calculate the number of processes ( threads ) that thephysical 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) executes the Proc_root_init () Wl number, initializing the virtual file system /proc .

in theStart_kenrel ()At the end of the kernel throughKenrel_thread ()Create the first system kernel thread(that1Number Process)that the thread is executing in the kernel.Init ()function, which is responsible for the next stage of the startup task. Last CallCpues_idle ()function:enters the system main loop body port default will always be executedDefault_idle ()the instructions in the function, i.e.Cpuof theHaltdirective until other processes in the ready queue need to be dispatched to perform other functions. At this point, the only memory in the system The process in the ready state is theKerne_hread ()created byInitProcess(Kernel Threads), so the kernel does not enterDefault_idle ()function instead of turningInit ()function to continue the startup 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 operating level of Linux , 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: Turn off the machine

1: Single-user mode

2: Multi-user mode with no network support

3: Multi-user mode with network support

4: Reserved, not used

5: Multi-user mode withnetwork support with X-window support

6: Reboot the system, that is, restart

Start step Sixth-init Process Execution Rc.sysinit

After setting the run level,the first user layer file that the Linux system executes is the/etc/rc.d/rc.sysinit script, which does a lot of work, including setting the PATH , Set Network configuration (/etc/sysconfig/network), start swap partition, set /proc, and so on.

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 document 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 standards I/O channel.

(4) after all the above is ready, the system begins to enter the initialization stage of the user layer. Kernel through the system call Execve () load The corresponding user layer initialization program, and then try to load the sequence "/sbin/initl", "/etc/init", "/bin/init" , and "/bin/sh. 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. To Thisend, the init () function ends, andthe 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.loca

If you open this file, there is a word, read it, you will be the role of this command at a glance:

# This script is executed *after* all theother init scripts.

# can put your own initialization stuff in HEREif you don ' t

# want to does 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 the 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.


This article from "Write a blog Money" blog, please be sure to keep this source http://dadonggg.blog.51cto.com/12672150/1949510

Linux boot up

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.