LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Rebuilding a single kernel module (https://www.linuxquestions.org/questions/linux-kernel-70/rebuilding-a-single-kernel-module-595116/)

kmand 10-27-2007 06:31 PM

Rebuilding a single kernel module
 
I need to make a small change and rebuild just one module in the Gutsy distribution.

How do I do this without building the kernel or the other modules?

I want to just manually replace the module in my /lib/module tree. How can I be sure it will be versioned consistantly so that the kernel won't complain at load time?

Ubuntu uses a Debian style make-kpkg for its builds.

MS3FGX 10-28-2007 11:32 AM

Do you want to create an installable package from this module, or just replace the existing one? Rebuilding the modules separate from the kernel is as easy as "make modules" in the kernel build directory. From there you could either install them all, or just manually replace the one you rebuilt (though there is really no reason not to replace them all).

As long as the modules are built against the same source tree as the running kernel, they will install fine on the official Ubuntu binary kernel (I.E. make sure you get the kernel source package from the Ubuntu repositories, and not just try and download the vanilla kernel).

But, again, if you want to make an installable package out of these (create a new kernel module package to replace the current one, for example) then there will be more steps involved. Depending on what your needs are, you might not need to actually go that far.

kmand 10-28-2007 11:59 AM

I just want to build the single "ko" file, not the package. However, I would like not to build all the kernel modules, just the one I want.

osor 10-28-2007 01:17 PM

Quote:

Originally Posted by kmand (Post 2939872)
However, I would like not to build all the kernel modules, just the one I want.

If the only changes are for the files in question that is what “make modules” is supposed to do (it compares the timestamps of the sources to the timestamps of the objects and rebuilds only if the sources are newer than the objects—in your case, you edit the sources for a specific module so it will be the only one rebuilt).

kmand 10-28-2007 01:25 PM

Quote:

Originally Posted by osor (Post 2939972)
If the only changes are for the files in question that is what “make modules” is supposed to do (it compares the timestamps of the sources to the timestamps of the objects and rebuilds only if the sources are newer than the objects—in your case, you edit the sources for a specific module so it will be the only one rebuilt).

That assumes that I have already built the modules once. What I'm asking is can I build just one module without building all of them?

If I need to make the change each time there is a kernel update, I would prefer to just build the one module I need to change.

osor 10-28-2007 01:34 PM

Quote:

Originally Posted by kmand (Post 2939983)
That assumes that I have already built the modules once. What I'm asking is can I build just one module without building all of them?

Ah… quite true. Another possibility is to obtain from your distribution the sourcetree and buildtree for your current kernel (if that’s possible).

In any case, you can always force the rebuild of a particular module with make as well (by passing the pathname to make). E.g., if I want to rebuild the rtc.ko module, I would type the following:
Code:

$ make drivers/char/rtc.ko
Note that this should be done in a preconfigured kernel source tree (and all dependencies of rtc.ko might also be built).

If you ever need quick help with the kernel make system, “make help” will explain most of the targets.

pixelbeat 08-18-2009 06:06 PM

I've detailed this here: http://www.pixelbeat.org/docs/rebuil...el_module.html

Quakeboy02 08-18-2009 06:33 PM

I am assuming Ubuntu is the same as Debian in the following:

If you look in the file "Makefile" you will find this:
Quote:

# Use make M=dir to specify directory of external module to build
# Old syntax make ... SUBDIRS=$PWD is still supported
# Setting the environment variable KBUILD_EXTMOD take precedence
A little further on, you find:
Quote:

# The following are the only valid targets when building external
# modules.
# make M=dir clean Delete all automatically generated files
# make M=dir modules Make all modules in specified dir
# make M=dir Same as 'make M=dir modules'
# make M=dir modules_install
# Install the modules built in the module directory
# Assumes install directory is already created
So, you can type "make M=dir" where dir is the subdirectory containing the module, such as:
Code:

make M=drivers/ata
This would make any changed (or not previously made) .ko files in drivers/ata.

You might want to consider adding your distro to your LQ options.


All times are GMT -5. The time now is 06:01 AM.