Linux kernel Analysis Note Three constructs a simple Linux system menuos--by Wangyue

Source: Internet
Author: User

I. Summary of knowledge points (i) Introduction to Linux source code
    • The code in the Arch/x86 directory is our focus
    • Kernel boot related code is in the init directory
    • The Start_kernel function is equivalent to the main function of a normal C program
    • The core code for Linux is in the kernel directory.
    • arch/support for different CPU source code
    • documentations/Document Storage
    • init/Kernel boot-related code
    • kenerl/Process scheduling related code
    • ipc/Inter-process communication
    • lib/Common Library files
    • mm/Memory management-related code
(ii) Construction of a simple Linux system
    • Start the MENUOS system
~/LinuxKernel/qemu -kernel linux-3.18.6/arch/x86/boot/bzImage -initrd rootfs.img

(iii) Tracking the startup process of debugging the Linux kernel

1. How to use GDB to track the debug kernel

    • Debug kernel with GDB trace
 qemu-kernel linux-3.18.6/arch/x86/boot/bzimage-initrd rootfs.img-s-S 
# description of the-s and-s options:-S Freeze CPU at startup (use ' C ' to start execution)
-s shorthand for-gdb tcp::1234 if you do not want to use 1234 port, you can use-gdb tcp:xxxx to replace -s option

    • Open another Shell window

      gdb(gdb)file linux-3.18.6/vmlinux # 在gdb界面中targe remote之前加载符号表(gdb)target remote:1234 # 建立gdb和gdbserver之间的连接,按c 让qemu上的Linux继续运行(gdb)break start_kernel # 断点的设置可以在target remote之前,也可以在之后

2. Simple analysis of Start_kernel

    • Init_task The final idle process of the pcb,0 process, which was created manually
    • There are many parts to be initialized with Start_kernel
    • Trap_init () Initializes a number of interrupt vectors to manage hardware interrupts
    • Rest_init () Kernel_init There is a run_init_process this is the Linux system in the 1th process, is the first user-state process, the default is a program under the root directory, if the root directory does not have this process, The system will look for other default processes as number 1th processes.

    • Rest Init () is a No. 0 process, which persists at the start of the Start_kernel kernel, and the process No. 0 creates the 1th process Kernel_init, and then creates some other kernel threads for the service class such as Kthreadd. So the whole system starts up.

by Wangyue "Original works reproduced please specify the source" 1. Linux kernel Analysis MOOC course http://mooc.study.163.com/course/USTC-1000029000

2. "Linux kernel symbol table" http://blog.chinaunix.net/uid-21633169-id-1823329.html

Linux kernel Analysis Note Three constructs a simple Linux system menuos--by Wangyue

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.