Chapter III MenuOS construction
Construct a simple Linux kernel
The first step in building a Linux system MenuOS
cd LinuxKernel/
qemu -kernel linux-3.18.6/arch/x86/boot/bzImage -initrd rootfs.img
Note: QEMU emulation kernel; bzImage is vnLinux after gzip compressed file is compressed kernel image; initrd root file system is memory; rootfs filesystem is compiled.
Run results shown in Figure:
The second step, to start the process of tracking the Linux kernel debugger (gdb using tracking)
Enter the following command to start the kernel:
qemu -kernel linux-3.18.6/arch/x86/boot/bzImage -initrd rootfs.img -S -s
Note:
- -s: Create a gdb-server on port 1234, to set a breakpoint may be used to trace core after;
- -S: the CPU initialization before freeze up.
Start effect as shown below:
Start entering the following gdb load the kernel, to establish a connection
file linux-3.18.6/vmlinux //在gdb界面中target remote之前加载符号表 target remote:1234 //用1234这个端口进行连接
Enter the following commands set a breakpoint at the gdb, start_kernel
break start_kernel //可在target remote之前,也可在之后
The effect is as:
View strat_kernel Code:
Analysis: strat_kernel is where it starts, for complete hardware system initialization, the code for the C runtime environment settings.
Among them, the more important init_task PCB is manually created, it is the process descriptor, 0 process, that is the final idle process.
Enter the following command () to set a breakpoint in the rest_init gdb
break rest_init
View rest_init () Code:
Analysis: By rest_init () New kernel_init and kthreadd kernel threads
Note:
- init_task (0 process) is not the only process that generated by the fork way;
- All kernel threads are directly or indirectly a kthreadd parent process.
Summarize the process of creation
- init_task () (PID 0) converted by calling cpu_idle () IDLE process , running in kernel space;
- init_task () created kernel_init () (1 kernel thread) by calling do_execve can be converted to user mode 1 process the init , this is the first user mode kernel boot process;
- init_task () created kthreadd () (No. 2 kernel threads) is always running in the kernel, it is responsible for all scheduling and management of kernel threads.
The whole process as shown: