CentOS Icon CentOS Logo
CentOS Text
   
  
www.centos.org Forum Index
   CentOS 4 - General Support
  HOWTO: Build new modules for an existing kernel

 

 Bottom   Previous Topic   Next Topic
  •  Rate Thread
      Rate this Thread
      Excellent
      Good
      Average
      Bad
      Terrible
Poster Thread Rated:  3 Votes
  •  cybermac912
      cybermac912
HOWTO: Build new modules for an existing kernel
#1
Newbie
Joined: 2005/4/26
From Southern California
Posts: 7
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:

- The Linux Kernel Module Programming Guide, Chap. 2
- Building External Linux Kernel Modules Under Fedora Core 3

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.
[root@isis ~]# yum install kernel-sourcecode # for the latest

If you have a different kernel than the latest
[root@isis ~]# yum install kernel-sourcecode-`uname -r`

Note that the kernel-devel package is not sufficient, as it has only headers and makefiles, not source code.

2) Change to source directory.
[root@isis ~]# cd /usr/src/linux-`uname -r`

3) Copy appropriate kernel config from boot directory.
[root@isis linux-2.6.9-5.0.5.EL]# cp /boot/config-`uname -r` .config

4) Edit to enable the module.
[root@isis linux-2.6.9-5.0.5.EL]# make menuconfig

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.
[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


6) Build and install the module.
[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.
  MODPOST
  CC      relative/path/to/module/themod.mod.o
  LD [M]  relative/path/to/module/themod.ko
  INSTALL relative/path/to/module/themod.ko


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


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/<version>, but does not work. It must be added to the current System.map (mimic what kernel build does).
[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/System.map-`uname -r` `uname -r`

9) Now the module will load.
[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

Hope this helps somebody. Any suggestions/comments from the community?

Eric
Posted on: 2005/4/27 23:35
Create PDF from Post Print
Top
  •  gavin
      gavin
Re: HOWTO: Build new modules for an existing kernel
#2
Newbie
Joined: 2005/3/10
From
Posts: 10
When I followed these instructions, everything worked great but the NTFS kernel module was installed into /lib/modules/2.6.9-5.0.5.ELcustom and not directly into the modules directory of my running kernel.

I had to move the fs/ntfs folder and contents into the normal /lib/modules/2.6.9-5.0.5.EL 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 :)
Posted on: 2005/5/19 10:11
Create PDF from Post Print
Top
  •  cybermac912
      cybermac912
Re: HOWTO: Build new modules for an existing kernel
#3
Newbie
Joined: 2005/4/26
From Southern California
Posts: 7
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.

Step 2.5) Edit Makefile. Change the line (near the top) that starts with "EXTRAVERSION". Remove the "custom" part. Save and quit.
[root@isis linux-2.6.9-5.0.5.EL]# vi Makefile
# Change this line to look like this...
EXTRAVERSION = -5.0.5.EL
Posted on: 2005/5/19 15:35
Create PDF from Post Print
Top
  •  hughesjr
      hughesjr
Re: HOWTO: Build new modules for an existing kernel
#4
WebMaster
Joined: 2004/12/5
From Corpus Christi, Texas, USA
Posts: 401
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:

http://mirror.centos.org/centos/4/centosplus/Readme.txt
Posted on: 2005/5/20 19:44
Create PDF from Post Print
Top
  •  herrold
      herrold
Re: HOWTO: Build new modules for an existing kernel
#5
WebMaster
Joined: 2005/3/19
From
Posts: 89
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: How to Build Kernel Modules
Posted on: 2008/3/5 14:22
Create PDF from Post Print
Top
 Top   Previous Topic   Next Topic

 


 You cannot start a new topic.
 You can view topic.
 You cannot reply to posts.
 You cannot edit your posts.
 You cannot delete your posts.
 You cannot add new polls.
 You cannot vote in polls.
 You cannot attach files to posts.
 You cannot post without approval.




"Linux" is a registered trademark of Linus Torvalds. | All other trademarks are property of their respective owners. | All other content is Copyright @ 2004-2009 by the CentOS Project or "each individual contributor (forums, comments, etc.) unless otherwise assigned".| Theme based on a theme by 7dana.com