Compile build debug the Linux kernel networking code system environment MenuOS
The operation command given reference, divided into the following steps:
Installation compile the kernel depends
sudo apt install build-essential flex bison libssl-dev libelf-dev libncurses-dev
- Download and compile the kernel
Download the kernel
wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.0.1.tar.xz
xD -d Linux-5.0.1.tar.xz
the tar -xvf 5.0.1-Linux .tar # unzip the downloaded zip file
cd linux-5.0.1 # unzip into the folder, ready to compile the kernel
Here had a little problem, that is the official website download speed is too slow .... suggestions directly to the official website, copy the link to the right address, and then use Thunder download, pro-test download speeds up to 6M / s
Compile the kernel
make i386_defconfig # accordance with the default kernel configuration file to generate
the make menuconfig
the make or make -j #j as the number of CPU cores
After entering these two commands will enter a visual interface for configuring the kernel, as follows:
(1) Enter Select Kernel hacking
(2) Select Compile-time checks and compiler options carriage
(3) Select Compile the kernel with debug info press the spacebar, and then save directly to the default cursor left to save the last exit
- Production root file virtual machine
Install qemu
sudo apt install qemu
qemu-system-i386 -kernel linux-5.0.1/arch/x86/boot/bzImage #qemu加载linux内核构建MenuOS
git clone https://github.com/mengning/menu.git
sudo apt-get install libc6-dev-i386 #安装libc6-dev-i386
qemu -kernel linux-5.0.1/arch/x86/boot/bzImage -initrd rootfs.img #创建系统镜像 (linux-5.0.1目录下)
make rootfs #初始化(menu目录下)
- 构建gdb调试环境
在qemu中启动gdb server
qemu -kernel linux-5.0.1/arch/x86/boot/bzImage -initrd rootfs.img -append nokaslr -s -S
建立gdb server和gdb之间的连接
不要关闭当前正处于黑屏状态的gdb server,打开一个新终端,输入gdb
cd linux-5.0.1
file vmlinux #加载符号表
break start_kernel #在内核函数处设置断点
target remote:1234 #建立gdb和gdb server之间的连接
c #回车让qemu上的Linux继续运行
list #查看之前设置的断点
- 将TCP网络程序集成到MenuOS中运行
集成服务端
git clone https://github.com/mengning/linuxnet.git
cd linuxnet/lab2
make
cd ..Integrated Client
lab3 cd
gedit Makefile # modify the Linux version is 5.0.1-Linux
the make rootfs
- Experimental Reference: https://github.com/mengning/net/tree/master/lab3
- Zhang Heng