Linux Kernel Analysis Experiment Three: Trace Analysis the boot process of Linux kernel

Source: Internet
Author: User

He Bong + Original works reproduced please specify the source + "Linux kernel analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000

I. Experimental process

1, open the shell, enter the start command, the kernel starts to enter the menu program, support three commands help, version and quit.

2. Then use GDB to trace the debug kernel, enter the command Qemu-kernel LINUX-3.18.6/ARCH/X86/BOOT/BZIMAGE-INITRD rootfs.img-s-S

3. Press and hold the Ctrl+alt key to open a new shell window and enter the following code.

    1. Gdb
    2. (gdb)file linux-3.18.6/vmlinux # Load symbol table before Targe remote in GDB interface
    3. (GDB) Target remote:1234 # Establish a connection between GDB and Gdbserver, press C to keep the Linux on qemu running
    4. (GDB) break Start_kernel # breakpoints can be set before target remote or after

Place the break at start and enter C to observe the QEMU

Enter list to see the code near the breakpoint.

View the kernel code for the linux-3.18.6. There are a lot of file directories here.

Where arch includes the various CPU architectures supported, here we only care about the x86 folder inside.

Others are like drivers for driver-related code. FS is the file system-related kernel code, IPC is process-related code, MM is the storage management code, NET is network-related kernel code and so on. 、

Init is the initialization-related module, which starts the operating system initialization of C code after Init/main.c/start_kernel, and finally executes the first user-state process init.

Many _init related functions can be seen in the Start_kernel function, involving various initialization operations related to operating system startup.

The init_task here is the equivalent of the NO. 0 process PCB. There are also sched_init (); Scheduling related initialization for the process. Trap_init (); For interrupt-related kernel code. Wait a minute.

Here see Start_kernel last sentence rest_init ().

This idle program is executed when the operating system is idle.

Summarize:

Shallow into the Xlinux kernel to learn the boot process.

Learned the operation of GDB using.

x86 the first action cs:eip=ffff:0000h of the CPU boot (converted to a physical address of 000ffff0h because the 16-bit CPU has 20 address lines), which is the location of the BIOS program. After the BIOS routine detects the hardware and completes the corresponding initialization, it looks for the bootable media, and after locating the bootloader into the specified memory area, the control is given to the boot program. The bootloader bootloader begins to be responsible for operating system initialization and then starts the operating system. The partition and directory where kernel, INITRD, and root are typically specified when the operating system is started. The kernel boot process includes start_kernel before and after, all of which are pre-initialized assembly instructions, followed by the OS initialization of the C code, and finally the first user-state process init. Generally in two-phase boot, first take advantage of the INITRD memory file system, and then switch to the hard disk file system to continue to boot.

Linux Kernel Analysis Experiment Three: Trace Analysis the boot process of Linux kernel

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.