Build a Custom Kernel Driver

In this lab you’ll build a custom device driver from source.


Git is a source control management (SCM) tool that is popular with open source projects. Git gives you a way to download source code for a program, keep up with updates and contribute your own features and fixes to the authors. Once you have a driver’s source code you must compile it to yield a loadable kernel module.Using Git to get the Source CodeIn this lab you’ll use a kernel driver that is an example in the excellent book Linux Device Drivers. The book was published in 2005 so some of the example code needs a bit of fixups. I maintain a Git repository that fixes some compilation problems. You can checkout the code with the following command:

$ git clone

That will create an “ldd3” directory in the current directory. There are several drivers in that directory, the “simple” driver compiles and can be inserted into your kernel.

$ cd ldd3/simple

Once you’re in the directory you invoke the “make” command to build the source:

$ make

This creates simple.ko. The *.ko extension is used for kernel modules. You can insert the kernel module with the insmod command:

$ sudo insmod simple.ko

Check to verify that your module is inserted:

$ lsmod
$ lsmod | grep simple

Most drivers print a banner to the kernel log when they are inserted. Look at the kernel message buffer to see what the simple driver reported:

$ dmesg | tail
$ tail /var/log/kern.log

Verify that you see the banner from the simple driver. Now remove the module from the kernel and verify that it’s gone:

$ sudo rmmod simple
$ lsmod | grep simple

Turn In

When you’re done save the bottom lines of your kernel log to a file called custom_driver.txt like this:

$ sudo tail /var/log/kern.log > /vagrant/custom_driver.txt