Creating Linux Kernel Module made easy

Can you believe that a two line C source code can become a Linux module?

$ cat simplest_module.c
#include <linux/module.h>

$ cat Makefile
obj-m := simplest_module.o
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

Just "make".
$ make

To install your brand new bogus module:
$ sudo insmod simplest_module.ko

The lsmod command show that your module has been loaded:
$ lsmod |grep simplest_module
simplest_module          689  0
To remove the module:
$ sudo rmmod simplest_module
It is very simple to create a Linux Kernel Module. If you want more than a do nothing module, follow the links:

Source: Writing device drivers in Linux: A brief tutorial
Recommended: Writing a Simple USB Driver

Popular posts from this blog

Buffalo WZR-1750DHP + OpenWRT

How to tell rpmbuild the number of simultaneous jobs? (make -j)

Adding a serial console to the Buffalo Air Station WZR-1750DHP