20135201 Li Chenxi "Linux kernel Analysis" constructs a simple Linux system OS for the third time

Source: Internet
Author: User

Li Chenxi no reprint "Linux kernel Analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000

The third week constructs a simple Linux system menuos

Introduction of Linux Kernel source code

    1. Three magic weapon and two swords:

Three magic weapons: Stored program computer, function call stack, end-of-break

Two swords of the operating system: Interrupt context Switching (save field and recovery site), process context switch

2.linuxIntroduction to Kernel source code the code under the Arch/x86 directory is a key concern

Init directory: Kernel boot-related code is basically in the init directory

The Start_kernel function in INIT/MAIN.C is equivalent to the main function of a normal C program.

FS Directory: File system filesystem

IPC Directory: interprocess communication

Kernel directory: Linux kernel core code in the kernel directory

Two. Construct a simple Linux system

Experimental process

1. Open the shell input using the lab building's virtual machine

cd LinuxKernel/qemu -kernel linux-3.18.6/arch/x86/boot/bzImage -initrd rootfs.img


2.启动kernel




3.启动gdb调试




4.用水平分割另外打开一个shell窗口之后,进行调试

设置断点(break)

设置完断点之后,输入c命令continue继续执行,函数会停在断点处
输入list指令之后,可以详细地查看断点附近的代码,输入list指令之后,可以详细地查看函数停留的位置








2. Simple analysis of Start_kernel

Init_task is created manually, the No. 0 process is the final idle process

Regardless of which part of the analysis kernel will be involved in Start_kernel

Dispatched to the idle process when no process is required for the system to execute

Three. Summary

1. summarize the kernel boot process

Kernelthread is number No. 0 process, it created 1th process kernelinit, and some of its service kernel threads, so that the entire system and started up. Then the INIT process will start some more processes.

Daosh One, lifetime two, Ishing (front 0, 1 and 23 processes), Sansheng everything (1th process is the ancestor of all user-state processes, and the 2nd process is the ancestor of all kernel threads)

2. starting with restInit, Linux begins to produce a process because the Inittask is statically manufactured, Pid=0, which attempts to move from the earliest assembly code to the startkernel are incorporated into the context of the inittask process . in the Restinit function, the kernel will generate the first real process (pid=1) with the following code, which is Kernelthread (kernelinit, NULL, CLONEFS | Clone_sighand); "Process # NO. 0 creates process number 1th"

3. Generally two-phase start, first take advantage of the INITRD memory file system, and then switch to the hard disk file system to continue to boot.

There are two main features of the INITRD file:

1, provide the boot required but the kernel file (ie Vmlinuz) does not provide the driver module (modules)

2, responsible for loading the root file system on the hard disk and executing the/SBIN/INIT program, which will continue the boot process















20135201 Li Chenxi "Linux kernel Analysis" constructs a simple Linux system OS for the third time

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.