简介
环境
Linux Distribution: Ubuntu 14.04.5 TLS
编译内核
下载3.18.6版本内核源代码。
# wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.18.6.tar.xz
# xz –d linux-3.18.6.tar.xz
#tar –xvf linux-3.18.6.tar# cd linux-3.18.6
编译选项
不同的架构有不同的默认文件,比如x86平台,可以在arch/x86/configs找到相关文件:i386_defconfig。通过执行make i386_defconfig 即可基于这个文件生成.config文件,在此基础上可以再运行make menuconfig 来进行个别的调整。更多的细节请参考:Documentationkbuildkconfig.txt。 总之,无论怎么配置,最终都是为了生成.config文件。这些宏最终将影响Makefile中参与编译的文件。
代码的编译选项配置很多,这里主要做如下两处配置:
让系统内核在32位架构中运行 //只是为了演示,非必须
开启”Compile the kernel with debug info”选项 //如果要让内核可调试,这个选项必选
# makei386_defconfig //32位架构
#make menuconfig // 调整编译选项
注意:默认make menuconfig会 错如下,因为最小系统不支持图形显示。
# makemenuconfig
HOSTCC scripts/kconfig/mconf.o
Infile included from scripts/kconfig/mconf.c:23:0:
scripts/kconfig/lxdialog/dialog.h:38:20: fatal error: curses.h: No such fileor directory
#include CURSES_LOC^compilation terminated.
解决方法:
# apt-get install libncurses5-dev -y
在内核编译选项中,开启如下”Compile the kernel with debug info”
Kernel hacking —>
Compile-time checks and compiler options —>
[ ] Compile the kernel with debug info
示意图如下,利用键盘选中debug选项,然后敲”Y”勾选:
到此为止,gdb调试Linux内核代码的基本环境已经搭建完成,可以利用断点来调试启动启动中的细节。后面将介绍如何构建initramfs文件系统,能让qemu运行的Linux系统更像“完整的系统”。
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!