Construction of the Linux kernel networking code debugging environment MenuOS system

Construction of the Linux kernel networking code debugging environment MenuOS system

Installation, compile linux kernel

Step 1: Download configured to compile 32

#如果想编译为64位,请直接从步骤二开始。

mkdir LinuxKernel  #创建一个项目目录
cd LinuxKernel
wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.0.1.tar.xz  #下载linux-5.0.1的内核,当然也可以下载其他版本的,就是有点慢。
xz -d linux-3.18.6.tar.xz    #解压
tar -xvf linux-3.18.6.tar
cd linux-3.18.6     #生成32位x86的配置文件
make i386_defconfig

Step 2: Configure compilation need debug information

#步骤二可以在这步做,也可以在后面做,如果不编译为32位的,想要编译为64位的,直接忽略步骤一,从步骤二开始,但是后面需要更改一些qemu命令的格式,要都按照64位来做,后面我大概提一下,但是具体细节我没做,所以有什么坑我也不知道。

make menuconfig

#执行make menuconfig之后,会跳出一个图形化界面,就在图形化界面中完成以下操作,如果没有跳出,或者报错,自行解决界面大小适应问题:安装vmware tool,或者在设置中调整分辨率。

1:选择 Kernel hacking
2:选择 Compile-time checks and compiler options
3:选择 【】Compile the kernel with debug info 
4:按Y  前面就多了一个 [*] Compile the kernel with debug info 
5:选择 save
6:按 esc,直到退出图形化界面

Step 3: Compile

make

It began the long wait until the compilation is completed.

Step 4: Upgrading the kernel

#可以忽略此步骤!!!!因为这个步骤是老师上课讲的的,但是我做的时候,机子在reboot的时候总是错,所以后面就跳过了。
#欢迎大佬指出问题

uname -a
sudo make modules_install  # ⚠️安装前通过系统快照备份系统,以防出现故障前功尽弃
sudo make install
sudo update-grub
reboot
uname -a

Production root file system

Step 1: QEMU virtual machine load the kernel

cd ~/LinuxKernel/
sudo apt install qemu  # 安装qemu命令
qemu-system-i386 -kernel  linux-5.0.1/arch/x86/boot/bzImage #这条命令可以不用执行,因为后面构造menuOS的makefile中是包含了这条命令的

Step 2: construction MenuOS

下载menu系统,并在LinuxKernel目录下建一个子目录rootfs,当作menuOS的根目录

git clone https://github.com/mengning/menu.git

mkdir rootfs

Step 2.1: mounting libc6-dev-i386 and modifications Makefile

method one

#修改menu目录下 Makefile的qemu 那条命令

cd menu

sudo apt-get install libc6-dev-i386

vim Makefile

qemu -kernel ../linux-3.18.6/arch/x86/boot/bzImage -initrd ../rootfs.img  #修改前

qemu-system-i386 -kernel  ../linux-5.0.1/arch/x86/boot/bzImage  -initrd ../rootfs.img #修改后

The explanation: qemu-system-i386 -kernel ../linux-5.0.1/arch/x86/boot/bzImage qemu virtual machine is loaded kernel linux-5.0.1

Second way

#如果不想使用qemu-system-i386,仍然想使用qemu命令,就改为如下,然后执行一个软链接

qemu -kernel ../linux-5.0.1/arch/x86/boot/bzImage -initrd ../rootfs.img

sudo ln -s /usr/bin/qemu-system-i386  /usr/bin/qemu

My approach is the way two

Step 2.2 initialization root directory

the latter will start linux looking ⼀ one of the applications in the root of Contents when running a medium to provide init at the root of Contents is ⼀ selectable ⽅ case

#在menu目录下执行一下命令
make rootfs

The result should be like this

Enter, and then execute the command help command to view the current menuOS system built in, other commands can be, but quit command is invalid, hh.

gdb debugging

Before performing the gdb debugger, make menuconfig ensure that steps have been executed, or the kernel to the system without debugging information.

Step 1: Start the gdb server

1 关闭 之前打开的menuOS系统界面
2 执行 qemu -kernel ../linux-5.0.1/arch/x86/boot/bzImage -initrd ../rootfs.img -append  nokaslr -s -S

Why and teachers are not the same? em I do not know why, may teacher to command only for teache machine, anyway, I was wrong pile.

Step 2 gdb gdb server connected to the client

#打开另一个终端

gdb
file ~/LinuxKernel/linux-5.0.1/vmlinux
break start_kernel
target remote:1234
c
list

Figure

Play a few more breakpoints to see the kernel boot process, the specific details of the study and then study.

Construction of the Linux kernel networking code debugging environment MenuOS

Reference laboratory building teacher: https://www.shiyanlou.com/courses/1198

Step 1: The server TCP network communication program integrated into the system MenuOS

cd ~/LinuxKernel  
git clone https://github.com/mengning/linuxnet.git
cd linuxnet/lab2
make
cd ../../menu/
make rootfs #改一下Makefile

Step 2: client TCP network communication program integrated into the system MenuOS

cd ~/LinuxKernel  
git clone https://github.com/mengning/linuxnet.git
cd linuxnet/lab3
make rootfs  #修改Makefile

The results are shown: menuOS below has more replyhi, and hello command, look detail later.

Guess you like

Origin www.cnblogs.com/Alexkk/p/11997737.html