HOWTO: Build new modules for an existing kernel

General support questions including new installations
Post Reply
Posts: 7
Joined: 2005/04/26 20:02:09
Location: Southern California

HOWTO: Build new modules for an existing kernel

Post by cybermac912 » 2005/04/27 23:35:13

Recently, I wanted to add NTFS support to my kernel as a module. Rather than recompile the whole kernel, or even all of the modules, I thought I should be able to build just the module I was interested in adding. It turns out this process isn't real straightforward, but it can be done pretty easily. I thought it might be good to pull together some information for other CentOS users. First, I found these two sources very helpful:

- [url=]The Linux Kernel Module Programming Guide, Chap. 2[/url]
- [url=]Building External Linux Kernel Modules Under Fedora Core 3[/url]

The following steps are a distillation of the above sources and are modified slightly for CentOS 4. They assume you are using a stock kernel from CentOS.
1) Install kernel sources.
[code][root@isis ~]# yum install kernel-sourcecode # for the latest[/code]
If you have a different kernel than the latest
[code][root@isis ~]# yum install kernel-sourcecode-`uname -r`[/code]
Note that the kernel-devel package is not sufficient, as it has only headers and makefiles, not source code.

2) Change to source directory.
[code][root@isis ~]# cd /usr/src/linux-`uname -r`[/code]
3) Copy appropriate kernel config from boot directory.
[code][root@isis linux-2.6.9-5.0.5.EL]# cp /boot/config-`uname -r` .config[/code]
4) Edit to enable the module.
[code][root@isis linux-2.6.9-5.0.5.EL]# make menuconfig[/code]
You can also just edit .config if you know the name of the parameter you are looking for. This step is very important, because the actual build step will do nothing if the module isn't enabled in the .config file.

5) Prepare the build environment.
[code][root@isis linux-2.6.9-5.0.5.EL]# make modules_prepare
CHK include/linux/version.h
UPD include/linux/version.h
SYMLINK include/asm -> include/asm-i386
CC arch/i386/kernel/asm-offsets.s
CHK include/asm-i386/asm_offsets.h
UPD include/asm-i386/asm_offsets.h[/code]

6) Build and install the module.
[code][root@isis linux-2.6.9-5.0.5.EL]# make M=relative/path/to/module/ modules modules_install
CC [M] relative/path/to/module/theobj.o
LD [M] relative/path/to/module/themod.o
Building modules, stage 2.
CC relative/path/to/module/themod.mod.o
LD [M] relative/path/to/module/themod.ko
INSTALL relative/path/to/module/themod.ko[/code]

For instance, if you want to add NTFS support:
[code]make M=fs/ntfs/ modules modules_install[/code]

Notice that we are using the external module build mechanism, but because we're building a module inside the kernel source tree, we don't need the -C argument to make.

7) At this point, the module shows up under /lib/modules/, but does not work. It must be added to the current (mimic what kernel build does).
[code][root@isis linux-2.6.9-5.0.5.EL]# modprobe ntfs
FATAL: Module ntfs not found.
[root@isis linux-2.6.9-5.0.5.EL]# depmod -ae -F /boot/`uname -r` `uname -r`[/code]
9) Now the module will load.
[code][root@isis linux-2.6.9-5.0.5.EL]# modprobe themod
[root@isis linux-2.6.9-5.0.5.EL]# grep "themod" /proc/modules
themod 84336 0 - Live 0xf02d4000[/code]
Hope this helps somebody. Any suggestions/comments from the community?


Posts: 10
Joined: 2005/03/10 18:34:29

Re: HOWTO: Build new modules for an existing kernel

Post by gavin » 2005/05/19 10:11:01

When I followed these instructions, everything worked great but the NTFS kernel module was installed into [b]/lib/modules/2.6.9-5.0.5.ELcustom[/b] and not directly into the modules directory of my running kernel.

I had to move the fs/ntfs folder and contents into the normal [b]/lib/modules/2.6.9-5.0.5.EL[/b] directory before depmod'ing and modprobe'ing. Otherwise it doesn't get picked up by depmod and I still get the "not found" message.

Hope this helps :)

Posts: 7
Joined: 2005/04/26 20:02:09
Location: Southern California

Re: HOWTO: Build new modules for an existing kernel

Post by cybermac912 » 2005/05/19 15:35:14

Dang, left a step out! I thought I triple-checked that I put this in there. What a goof! Here's the missing step. I was going to edit the original post, but it looks like it's locked for some reason. Thanks for finding this.

[b]Step 2.5)[/b] Edit Makefile. Change the line (near the top) that starts with "EXTRAVERSION". Remove the "custom" part. Save and quit.
[code][root@isis linux-2.6.9-5.0.5.EL]# vi Makefile
# Change this line to look like this...
EXTRAVERSION = -5.0.5.EL[/code]

Site Admin
Posts: 251
Joined: 2004/12/05 01:51:26
Location: Corpus Christi, Texas, USA

Re: HOWTO: Build new modules for an existing kernel

Post by hughesjr » 2005/05/20 19:44:51

That works well, thanks for the information.

For some things (like NTFS, ReiserFS, XFS, JFS support and some others), they are now built into a kernel that we have released in CentOS plus. It is called kernel-xxxxx-unsupported. It replaces the main kernel and provides items not in the standard boot Kernel.

Read more about it here:

Posts: 100
Joined: 2005/03/19 22:14:28

Re: HOWTO: Build new modules for an existing kernel

Post by herrold » 2008/03/05 14:22:56

With the passage of time, and the sequential and static nature of a Forum, this article has gone stale.

Please refer to the Wiki article maintained by the CentOS documentation team, at: [url=]How to Build Kernel Modules[/url]

Post Reply

Return to “CentOS 4 - General Support”