Fedora: Compile a single module directory for current running Kernel

Sometimes one may want to just compile a single module and use it without rebooting the machine. In my case I wanted to play with 8139cp/8139too modules inside a KVM virtual machine running Fedora.

There are two requirements:
1 - Kernel source code
2 - Kernel development package

The source code is where to do the changes, while the development package contains the headers that allow to compile Kernel modules with the right version magic.

There are some options for obtaining the Kernel source code, but here the Fedora way is listed. You could probably download the Kernel from http://kernel.org.

Install packages, prepare RPM buil tree, and "install" the source code(Fedora way):
[fedora] $ sudo yum install @"Development Tools" rpmdevtools yum-utils ncurses-devel
[fedora] $ rpmdev-setuptree
[fedora] $ yumdownloader --source kernel
[fedora] $ sudo yum-builddep kernel-<version>.src.rpm
[fedora] $ rpm -Uvh kernel-<version>.src.rpm
Prepare the source code for building:
[fedora] $ cd ~/rpmbuild/SPECS
[fedora] $ rpmbuild -bp --target=$(uname -m) kernel.spec

Install kernel-devel:
[fedora] $ sudo yum install kernel-devel

Build Realtek Ethernet modules:
[fedora] $ cd ~/rpmbuild/BUILD/kernel-<version>/linux-<version>
[fedora] $ make -C /lib/modules/`uname -r`/build M=`pwd`/drivers/net/ethernet/realtek modules

Remove original mudules, load new ones:
[fedora] $ sudo rmmod 8139cp
[fedora] $ sudo rmmod 8139too
[fedora] $ sudo insmod ~/rpmbuild/BUILD/kernel-<version>/linux-<version>/drivers/net/ethernet/realtek/8139cp.ko
[fedora] $ sudo insmod ~/rpmbuild/BUILD/kernel-<version>/linux-<version>/drivers/net/ethernet/realtek/8139too.ko

Nice resources:
 - Building a custom kernel

Popular posts from this blog

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

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

Buffalo WZR-1750DHP + OpenWRT