Linux 编译debug内核

网上找了很多文章,实际操作一下,做个笔记:

0x01:下载内核源码

a.官方网站:https://www.kernel.org/
b.ftp服务器下载: http://ftp.sjtu.edu.cn/sites/ftp.kernel.org/pub/linux/kernel/

实验下载内核源码版本:5.3.1

0x02:编译带调试信息内核
解压内核代码,我这里下载linux 内核压缩包为linux-5.3.1.tar.xz
解压方式tar -zxvf linux-5.3.1.tar.gz

安装编译内核时需要的包

sudo apt install libncurses5-dev bison flex
sudo apt install libelf-dev libssl-dev

如果直接输入make menuconfig,则会默认使用源码x86目录下默认的config文件,文件路径 linux-5.3.1/arch/x86/configs,除了自己去配置config文件之外,还可以拷贝当前系统的config文件到源码目录

cd linux-5.3.1
cp /boot/config-xxxx-generic .config
make menuconfig
cd linux-5.3.1
export ARCH=x86_64 
make defconfig
make menuconfig

如果需要编译arm的内核我们需要指定ARCH类型,ARCH=arm64,还要指定编译交叉编译工具链;

Kernel hacking ---> Compile-time checks and compiler options ---> Compile the kernel with debug info ---> yes
Kernel hacking ---> Compile-time checks and compiler options ---> Provide GDB scripts for kernel debugging ---> yes
Kernel hacking ---> Memory Debugging ---> KASan: runtime memory debugger ---> yes
General setup ---> Configure standard kernel features ---> yes
General setup ---> Configure standard kernel features ---> Load all symbols for debugging/ksymoops ---> yes
General setup ---> Configure standard kernel features ---> Include all symbols in kallsyms ---> yes
General setup -> Compiler optimization level (Optimize for performance) ---> Optimize for size
Processor type and features  ---> [ ] Randomize the address of the kernel image (KASLR)

配置完成后会在代码路径生成.config配置文件,如果默认编译选项,我记得可以直接copy本机的.config文件到代码目录;

cat /proc/cpuinfo --> 查看cpu有多少个核
make -j4 --> 数字代表的是用来编译内核的cpu核数,可以自己指定,指定的cpu核数越多,编译的速度就越快;

编译完成后:
bzImage:内核镜像 --> linux-5.3.1/arch/x86/boot/bzImage
vmlinux:编译内核时生成的调试文件 --> linux-5.3.1/vmlinux

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值