Linux – Update single kernel module / driver

driverskernellinuxUbuntu

I needed a newer version of a Kernel module in an quite old kernel.

How can I replace a single kernel module of the mainstream linux kernel and compile only this module?

Best Answer

One warning: There is no gurantee, that the new driver version is compatible with the old kernel. But it is worth a try.

  1. Find the newer driver in the kernel. There are two options: You can use the original kernel driver from the kernel git, for example in https://github.com/torvalds/linux/tree/master/drivers. It is handy to select a tag to find the specific kernel version you need. Download the specific thedriver.h and thedriver.c files and put them into a new directory.

    The second option is to fetch Ubuntu's new kernel from http://packages.ubuntu.com or via apt-get source ...

  2. Install the packages build-essentials and the linux-kernel-headers

  3. Now we create a makefile for this single module as shown on cyberciti.biz, thedriver.o has to be replaced by the driver name. In the folder which contains the driver code, create a file Makefile with the following content:

    obj-m += thedriver.o
    
    all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    
    clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
    
  4. Now, in this directory, type make to compile the driver.

  5. If everything works well, a thedriver.ko file should have been created that can be placed into the folder /lib/modules/$kernelversion/kernel/drivers (do not forget to create a backup)

Related Question