Linux Kernel Module Cheat

Run one command, get into QEMU Buildroot BusyBox with several minimal Linux kernel module example tutorials. Tested in Ubuntu 14.04.

Usage:

./run

First build will take a while (GCC, Linux kernel).

QEMU opens up, and you can run:

insmod /hello.ko
insmod /hello2.ko
rmmod hello
rmmod hello2

Each module comes from a C file under kernel_module/. head *.c for module usage.

The Linux kernel version can be found with:

grep BR2_LINUX_KERNEL_VERSION buildroot/.config

We use printk a lot, and it shows on the QEMU terminal by default. If that annoys you (e.g. you want to see stdout separately), do:

dmesg -n 1

See also: https://superuser.com/questions/351387/how-to-stop-kernel-messages-from-flooding-my-console

  1. Introduction
  2. Build
  3. kmod
  4. Bibliography
  5. Examples
    1. Host
    2. Buildroot
      1. hello
      2. hello2
      3. debugfs
      4. fops
      5. workqueue
Description
The perfect emulation setup to study and develop the Linux kernel v5.4.3, kernel modules, QEMU, gem5 and x86_64, ARMv7 and ARMv8 userland and baremetal assembly, ANSI C, C++ and POSIX. GDB step debug and KGDB just work. Powered by Buildroot and crosstool-NG. Highly automated. Thoroughly documented. Automated tests. "Tested" in an Ubuntu 24.04 host.
Readme 25 MiB
Languages
Python 37.3%
C 33.8%
Assembly 13.6%
C++ 8.6%
Shell 3.7%
Other 2.8%