kernel入门
自己的环境是16.04,出入kernel记录下,大佬勿喷。。
环境编译
下载kernel源代码:https://www.kernel.org/
按照必要的依赖
sudo apt-get update
sudo apt-get install build-essential libncurses5-dev
编译kernel源码
make menuconfig #遵循sakura大佬博客
#修改一些参数
进入kernel hacking
勾选以下项目
Kernel debugging
Compile-time checks and compiler options —> Compile the kernel with debug info和Compile the kernel with frame pointers
KGDB
(大部分是开着的,似乎后面几个选项有没开的
接着就是
make bzImage
编译的时间略有点长
Setup is 17244 bytes (padded to 17408 bytes).
System is 7666 kB
CRC 5c77cbfe
Kernel: arch/x86/boot/bzImage is ready (#1
出现这个就表示已经编译成功了。
因为是小白入坑教程,所以我想应该解释下什么是bzimage
vmlinux 编译出来的最原始的内核文件,未压缩。
zImage 是vmlinux经过gzip压缩后的文件。
bzImage bz表示“big zImage”
这样解释后应该清楚的多了。那么我们现在就已经有一个内核文件了,接下来创建文件系统。
编译busybox
(from sakura大佬 blog
wget https://busybox.net/downloads/busybox-1.27.2.tar.bz2
tar -jxvf busybox-1.27.2.tar.bz2
cd busybox-1.27.2
make menuconfig # Busybox Settings -> Build Options -> Build Busybox as a static binary
make install
在文件夹下会有_install文件
建立文件系统
cd _install
mkdir proc
mkdir sys
touch init
chmod +x init
写init文件
#!/bin/sh
mkdir /tmp
mount -t proc none /proc
mount -t sysfs none /sys
mount -t debugfs none /sys/kernel/debug
mount -t tmpfs none /tmp
mdev -s # We need this to find /dev/sda later
setsid /bin/cttyhack setuidgid 1000 /