My Linux kernel development setup
I started 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: how to run a kernel in QEMU, how to track linux-next, and the tools used to follow kernel development.
QEMU
I wanted to emulate the Linux kernel using QEMU.
I was inspired by this post (archived copy) even if it's outdated. This post is also a good reference.
Filesystem
I used this script from the syzkaller project to create the disk image, then booted the kernel with:
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.logKernel 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-20260209Following development
The current developer flow revolves around two tools:
- b4 which you can install with your distro package manager or from PyPi.
- lei also packaged by major distros
b4
B4 is a tool created to make it easier to work with kernel patches from mailing lists. You can also use it to download lore discussion threads but I think that lei is a better tool for this task.
To retrieve and apply a patch, the commands to use are b4 am or b4 shazam.
The difference between the two commands described in the docs can be summarized as:
b4 amprepares the patch series so you cangit amthe resulting mbox file, but it doesn't make any actual modifications to your current branchb4 shazamprepares the patch series and applies it to the current branch.
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.
Where I stopped
I moved on from kernel hacking before sending my first patch, so this is as far as the setup goes.
It still works as a starting point: the next steps would be configuring the kernel (make localmodconfig gives you a
bootable config based on the one you are running), building it, and booting the resulting bzImage with the QEMU command above.