进入 kernel hacking,勾选 Kernel debugging,Compile-time checks and compiler options–>Compile the kernel with debug info,Compile the kernel with frame pointers 和 KGDB
编译
1
../make-3.80/make bzImage
编译时遇到的问题
问题1
1
fatal error: linux/compiler-gcc5.h: No such file or directory
解决:
1
拷贝一个自己目录下的compiler-gcc4.h到compiler-gcc5.h
问题2
1
implicit declaration of function 'tty_port_users'
解决:
将所提示的该函数extern关键字去掉
编译成功
编译成功之后提示如下:
1 2 3 4 5
Root device is (0, 78) Setup is 13688 bytes (padded to 13824 bytes). System is 3961 kB CRC e70b803a Kernel: arch/x86/boot/bzImage is ready (#1)
vmlinux 在源码根目录下,bzImage 在arch/x86/boot/下
制作镜像
获取busybox
1 2
wget https://busybox.net/downloads/busybox-1.27.2.tar.bz2 tar -jxvf busybox-1.27.2.tar.bz2
配置busybox
1 2
cd busybox-1.27.2 make menuconfig
勾选 Busybox Settings -> Build Options -> Build Busybox as a static binary
编译并安装busybox
1 2
make make install
打包镜像
编译完成后源码目录下会有一个_install 文件夹
1 2 3 4
cd _install mkdir -pv {bin,sbin,etc,proc,sys,usr/{bin,sbin}} mkdir etc/init.d touch etc/init.d/init
编辑 etc/inittab 文件,加入以下内容(这一步可以省略)
1 2 3 4 5 6
::sysinit:/etc/init.d/rcS ::askfirst:/bin/ash ::ctrlaltdel:/sbin/reboot ::shutdown:/sbin/swapoff -a ::shutdown:/bin/umount -a -r ::restart:/sbin/init
Please press Enter to activate this console. [ 3.379764] async/1 used greatest stack depth: 5064 bytes left /bin/ash: can't access tty; job control turned off / # ls bin etc proc sbin usr