Linux: Scaffolding For Out-of-Tree Loadable Modules

Whenever it comes to quick-and-dirty testing of what can (or cannot) be done in the Linux kernel, I find myself searching for the boilerplate of a loadable kernel module and the list of Debian packages that must be installed for an out-of-tree compilation. Finally, I am tired of that: here is the script that does everything for me.

The script, checks for the presence of required Debian packages and initiates installation of the missing ones with apt-get install and then creates a directory with a Makefile and a C source file for the module, ready for compilation.

The invocation is as simple as

sh the-name-of-the-module

There are two things to note:

  1. The coding convention of the generated source is different from the enforced agreed upon in the Linux kernel; you must reformat the source if you are going to show it to anyone otherwise you will seriously irritate other people;
  2. The C source file declares the module license as "Dual BSD/GPL" to avoid tainting the kernel; you may want to change it.

Vadim Penzin, September 21st, 2015

I hereby place this article into the public domain.
I publish this information in the hope that it will be useful, but without ANY WARRANTY.
You are responsible for any and all consequences that may arise as the result of using this information.