User Tools

Site Tools


notes:rebuilding_kernel_modules

Rebuilding Linux Kernel Modules

This page specifically concerns building kernel modules to work with an existing running kernel without having to rebuild the entire kernel or reboot the system. More detailed information on this topic can be found in the Documentation/kbuild/modules.txt file within the kernel source package.

There are two prerequisites for building modules to work with an existing kernel:

  • The current kernel's configuration file.
  • The current kernel's exported symbol list (the Modules.symvers file).

Under Ubuntu the files can be found in the following locations:

  • /boot/config-$(uname -r)
  • /usr/src/linux-headers-$(uname -r)/Module.symvers

On Ubuntu, the latter file is located within the linux-headers-$(uname -r) package.

Unzip a copy of the Linux kernel sources and change into the root directory of it. Then execute the following commands:

make clean
cp /boot/config-$(uname -r) .config
cp /usr/src/linux-headers-$(uname -r)/Module.symvers .
make oldconfig
make modules_prepare

At this point the kernel is ready to build modules:

make modules

To only build a subset of modules set the M variable to a subdirectory — for example, to rebuild only USB audio drivers:

make M=sound/usb

Once the build is complete you should find the .ko files in their respective subdirectories.

If there are no .ko files or there are other inexplicable build failures, double check that your GREP_OPTIONS environment variable isn't set, and unset it if it is. After unsetting you may need to repeat everything from make clean onwards.

notes/rebuilding_kernel_modules.txt · Last modified: 2012/10/17 10:32 by andy