Kernel

Build a Single in Tree Linux Kernel Module (Debian & Clones)

How misleading and complicated this task should be that I’m writing such an article in 2022?
Anyway, if you struggle compiling a simple, standalone Linux kernel module on Debian, Ubuntu, Mint and the like, here’s the recipe:

  • Fetch linux-source-<version> and linux-headers-<version>
$ sudo apt install linux-source-5.4.0 linux-headers-$(uname -r)

Do not use apt-get source linux-source-<version>, only pain will you find.

  • Untar the fetched archive where you’d like
$ tar jxvf /usr/src/linux-source-5.4.0.tar.bz2
  • Copy your current kernel configuration
$ cd linux-source-5.4.0
$ cp /boot/config-$(uname -r) .config
  • Prepare the build environment
$ make oldconfig scripts prepare modules_prepare
  • Copy current kernel exported symbols file
$ cp /usr/src/linux-headers-$(uname -r)/Module.symvers .
  • Build the module you need
$ make -C . M=arch/x86/kvm
  • Test it
$ sudo insmod arch/x86/kvm/kvm-intel.ko

Eventually backup the current loaded module (modinfo <module>), replace it with your freshly built one and don’t forget to depmod -a.

An Innocent Mount Issue

I work as a freelance contractor for about a year now, I quit a 10+ years regular CTO job to give into more technical subjects, troubleshoot, code, build infrastructures, A-Team style, I help companies with complex matters that might require experience and rigorousness.

One of my last missions was really, really fun to deal with. A rather big company handling scientific, secret-level data, had an issue with their storage system.
They use Infiniband as their communication layer on an HPC environment, it was not a problem while the underlying operating system was CentOS 7.1 with kernel 3.10.0-1160, but since new machines were installed with CentOS 7.7 and up, with kernels 3.10.0-1062 and up, whenever they wrote a file less than 701 bytes long, the file would be corrupted.
For the record and understanding of the following debugging session, the company uses NFS over RDMA, the latter being the technique used by Infiniband to achieve low latency and great throughput.