Build a simple Linux system Menuos--start_kernel to the init process (20135304 Liu Xipeng)

Source: Internet
Author: User

build a simple Linux system Menuos--start_kernel to the INIT process Liu Xipeng 20135304

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

Introduction to Linux kernel code

Kernel source code three important directory

    • Arch occupies the largest amount of code, support different CPU source code, arch/x86 directory code is the focus of our attention
    • init, the kernel boot-related code is basically in the init directory, INIT/MAIN.C Start_kernel is the starting point of the entire kernel

    • The core code for the Linux kernel is located in the kernel directory

Readme

    • Describes what Linux is
    • What hardware Linux can run on
    • Document description
    • How to install kernel source code
    • Make Mrproper clean up the middle code.
    • Make allnoconfig all the options are turned off and can run quickly

Experimental process

Construct a simple Linux system menuos

CD linuxkernel/-kernel linux-3.18. 6/arch/x86/boot/bzimage-initrd rootfs.img

    • QEMU starts the virtual machine
    • Kernel indicates the kernel file name
    • INITRD indicates the root file system

kernel boot → load root file System (executable init is started)

How to use GDB to track the debug kernel

Qemu-kernel LINUX-3.18.6/ARCH/X86/BOOT/BZIMAGE-INITRD Rootfs.img-s-S

Notes on the-s and-s options:

-S Freeze CPU at startup (use ' C ' to start execution) freezes before CPU initialization  for creating a GDB server on the-gdb tcp::1234 port

The virtual machine is in a frozen state at this time

Open another Shell window
Set GDB Breakpoint

(gdb) file linux-3.18. 6/vmlinux # Targe remote before loading symbol table (GDB) in the GDB interface target remote:1234  # Establishes a connection between GDB and Gdbserver, Press C to allow the Linux on QEMU to continue running (GDB) break Start_kernel # Breakpoint settings can be before target remote, or after

The system restarts to the Start_kernel location.

System execution to Init

Analyze the execution process of Start_kernel
    • The Start_kernel function is the gateway to the Linux kernel.
    • Start_kernel () is the interface between the Assembly of the kernel and the C language, before which the kernel code is written in sinks, completing some of the most basic initialization and environment setup work.
    • No matter what part of the analysis kernel involves start_kernel, because almost all modules are called when they are initialized
    • Init_task is a global variable, which is a manually created PCB. Process No. 0, which is the final idle process
    • Trap_init () Initialization of some interrupt vectors

Kthreadd uses kernel threads to manage system resources and dispatch to the idle process when no process is required for the system to execute

Iv. Summary

The boot process for the entire kernel can be considered as rest_init()这 a process No. 0, in which process number start_kernel函数的尾部被调用。 1th is created, and kernel_init other kernel threads such as Kthreadd are created for other service classes. So the whole system starts up.

Build a simple Linux system Menuos--start_kernel to the init process (20135304 Liu Xipeng)

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.