This repository contains a set of scripts that are useful for analyzing the Linux kernel. For example, the following versions of the kernel can be built and debugged very concisely on docker without having to worry about dependent packages.
- upstream (kernel v2.6.39)
- centos6 (kernel v2.6.32-754.35.1.el6)
- centos7 (kernel v3.10.0-1160.13.1.el7)
- centos8 (kernel v4.18.0-348.7.1.el8_5)
- rocky9 (kernel v5.14.0-162.6.1.el9_1)
- ubuntu20.04 (kernel v5.4.0-65.73)
- ubuntu22.04 (kernel v5.15.0-43.46)
These are the distributions that I am familiar with, so they are supported by default, but other versions can be applied as well. While using this tool, I am reading the book "Understanding the Linux Kernel, 3rd Edition".
- linux on x86/64
- docker
# Prepare the .config file and build the docker image as the kernel build environment.
# Also, the kernel code is downloaded here.
make prepare
# Generate a userland based on busybox. A simple shell environment and SSH server are included.
make busybox/initrd
# Change the build settings of the kernel. If you don't need it, you can skip this step.
make menuconfig
# Build the kernel in docker container
make bzImage
# Boot the kernel on a qemu virtual machine.
make qemu
# Connect to the virtual machine via SSH.
make ssh
If you want to use gdb
to debug the kernel, replace make qemu
with the following:
# Boot the kernel and wait for the debugger to connect
make qemu_freeze
# Connect the debugger to the virtual machine
make gdb
The kernel version can be specified as follows:
# centos6 (kernel v2.6.32-754.35.1.el6)
make LINUX_VERSION=2_6_32_754_35_1_el6 ...
# centos7 (kernel v3.10.0-1160.13.1.el7)
make LINUX_VERSION=3_10_0_1160_31_1_el7 ...
# centos8 (kernel v4.18.0-348.7.1.el8_5)
make LINUX_VERSION=4_18_0_348_7_1_el8_5 ...
# rocky9 (kernel v5.14.0-162.6.1.el9_1)
make LINUX_VERSION=5_14_0_162_6_1_el9_1 ...
# ubuntu20.04 (kernel v5.4.0-65.73)
make LINUX_VERSION=5_4_0_65_73 ...
# ubuntu22.04 (kernel v5.15.0-43.46)
make LINUX_VERSION=5_15_0_43_46 ...