Building a CentOS 6.4 module

  1. Install necessary tools.
    • yum groupinstall "Development Tools
    • yum install rpm-build redhat-rpm-config asciidoc hmaccalc perl-ExtUtils-Embed xmlto
    • yum install binutils-devel elfutils-libelf-devel newt-devel python-devel zlib-devel
  2. Get the kernel headers.
    • yum install kernel-devel
  3. Create a build tree and get the kernel source
  4. Unpack the source files
    • cd ~/rpmbuild/SPECS
    • rpmbuild -bp --target=$(uname -m) kernel.spec
  5. The source tree will be under ~/rpmbuild/BUILD/kernel*/linux*/
  6. Prepare the kernel
    • cd ~/rpmbuild/BUILD/kernel-2.6.32/linux-2.6.32.`uname -m`
    • cp /boot/config-`uname -r` .config
    • make oldconfig
    • make prepare
    • make modules_prepare
  7. Note: make modules_prepare will not build a Module.symvers file. If you need module versioning then the kernel needs to be built.  See http://wiki.centos.org/HowTos/Custom_Kernel
  8. Change directory to the module you want to build
  9. Build the module
    • make -C /lib/modules/`uname -r`/build M=`pwd` modules
  10. Copy the .ko to /lib/modules/`uname -r`/extra on the target system
  11. Update the dependencies
    • depmod -a
  12. Use modprobe to load the module. To display info about a loaded module use modinfo
Advertisements
%d bloggers like this: