Sefu
Sefu

Reputation: 2494

How to compile a module from downloaded Linux source?

I would ultimately like to modify and compile the existing Linux USB storage driver and test it. For the first step, I wanted to compile the module as is.

I downloaded the latest Linux kernel (version 3.12) and extracted it to ~/linux-3.12.

I found the driver I wanted to compile: drivers/usb/storage, but when I ran make, I got the following error:

make: *** No targets.  Stop.

I found many guides online, but none of them worked for the USB storage driver. All I want is to compile this one module and get the .ko so I can test it out.

NOTE: I'm running Ubuntu 13.04 64-bit, and uname -r outputs 3.8.0-30-generic - I'm not sure if that's the problem, but I managed to compile the whole Kernel before. I don't want to do that now because it takes an eon.

Upvotes: 1

Views: 1072

Answers (2)

Levente Kurusa
Levente Kurusa

Reputation: 1866

If you wanted to build the drivers/usb/storage module you would do this:

make M=drivers/usb/storage

from the root directory of the kernel tree. Before doing so, you will need to make sure that your configuration is the same as the config of the running kernel.

Upvotes: 3

Kristof Provost
Kristof Provost

Reputation: 26332

You can't simply take the source code for one kernel and use it to build modules for another one. The module needs to be built from the same source and with the same configuration as the kernel itself.

Basically, you need to find the source code for the Ubuntu kernel you're running. In Ubuntu, as in Debian, that can be done with 'apt-get source '. The package name is probably something like 'linux-image-3.8-2-amd64'.

Once you have the source code you need to find the configuration of your running kernel. Fortunately Ubuntu keeps that in /boot/config-3.8-....

Copy that config to your kernel source tree as .config and run 'make oldconfig'. Now you should be able to build the module (assuming it's not already built into your kernel!).

Upvotes: 2

Related Questions