Kernel exploration and experimentation
I am starting to dig again into some linux kernel internals, so I decided to write down (mostly for myself) all the results and documents I found to be useful.
QEmu
I wanted to emulate the linux kernel using QEMU.
I was inspired by this post even if it's outdated. This post is also a good reference.
Filesystem
I used this script from the syzkaller project.
qemu-system-x86_64 \
-kernel $KERNEL_PATH/arch/x86/boot/bzImage \
-append "console=ttyS0 root=/dev/sda debug earlyprintk=serial slub_debug=QUZ"\
-hda $IMAGE_PATH/trixie.img \
-net user,hostfwd=tcp::10021-:22 -net nic \
-enable-kvm \
-nographic \
-m 2G \
-smp 2 \
-pidfile vm.pid \
2>&1 | tee vm.log
Kernel build
I want to keep an eye on staging drivers to find some easy code style fix to have the chance to send a first patch. Here are the steps I am following
Download linux-next
Following the documentation you can find here you can start tracking the linux-next development branch.
We start cloning the mainline kernel
$ git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Then we add a remote tracking branch for linux-next
$ cd linux
$ git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
Every day you want to sync with the latest developments:
$ git remote update
Then delete local branches tracking daily tags
$ git branch -D my_local
List daily tags to find the latest one:
$ git tag -l "next-*" | tail
Now choose the latest one and track it using a local branch
$ git checkout -b my_local next-20260209
Config
I started by using the make localmodconfig to have a booting build of the kernel based on my running config.
Follow kernel developments
The current developer flow rotates around two tools:
- b4 which you can install with your distro package manager or from PyPi.
- lei also packaged by major distros
b4
lei
This tool is very useful to get a local copy of the kernel mailing lists you are interested in without subscribing and, most importantly, to get a local copy of the conversations in a given time interval (e.g. the last month) to browse them with mutt or another mail client while offline and/or without using the archives web interface.