wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.19.303.tar.xz
tar -xvf linux-4.19.303.tar.xz
```
2. 修改编译配置
执行 `make menuconfig` 进入 tui 配置界面,需要开启 `Compile the kernel with debug info` 和关闭 `Randomize the address of the kernel image`
```
Kernel hacking --->
[*] Kernel debugging
Compile-time checks and compiler options --->
[*] Compile the kernel with debug info
[*] Provide GDB scripts for kernel debuggin
Processor type and features ---->
[] Randomize the address of the kernel image (KASLR)
```
3. 安装编译时会用到的工具
```shell
sudo apt-get install libncurses5-dev openssl libssl- dev
sudo apt-get install build-essential openssl
sudo apt-get install pkg-config
sudo apt-get install libc6-dev
sudo apt-get install bison
sudo apt-get install flex
sudo apt-get install libelf-dev
sudo apt-get install zlibc minizip
sudo apt-get install libidn11-dev libidn11
```
4. 编译 `make -j<编译用到的cpu核心数>`
5. 编译完成后在 `arch` 目录下找到自己的 cpu 架构下对应的目录。里面的 `boot` 中包含 `bzImage` 和 `vmLinux`。其中 `bzImage` 是一个 `gzip` 自解压的 Linux 压缩镜像。`vmLinux` 是未压缩的镜像,它包含调试信息。
### 制作 rootfs
rootfs 提供了 Linux 运行所需要的文件,例如关键的目录结构、shell命令、系统配置、动态链接库等。Linux 初始化过程中需要这个文件系统作为 initramfs (内存之上的文件系统) 来引导系统启动。
busybox 将多个工具(如 ls、cp、mv、rm、cat、echo 等)集成到一个单一的可执行文件中,可以通过符号链接(symlink)或硬链接(hard link)来调用不同的工具。
所以我们可以利用 busybox 来作为 rootfs 的一部分。
1. 下载 busybox,并解压
```shell
wget https://busybox.net/downloads/busybox-1.36.1.tar.bz2
tar -xvf busybox-1.36.1.tar.bz2
```
2. 进入 busybox 目录,修改 busybox 编译配置
```shell
$ make menuconfig
-> Settings
--- Build Options
[*] Build static binary (no shared libs)
```
3. 编译 busybox
```shell
make && make install