Saturday, January 30, 2010

Building Kernel Modules With Module-Assistant On Debian Lenny

module-assistant is a tool for building Debian kernel modules from source, without having to rebuild the whole kernel.

It fetches module-source packages that have been prepared for the Debian distribution via apt and produces .deb packages.

This tutorial shows how to use module-assistant in command-line mode and in interactive mode.

I do not issue any guarantee that this will work for you!


1 Preliminary Note
In this tutorial I will demonstrate how to build the ndiswrapper kernel module for Debian Lenny. The procedure is the same for any other kernel module that module-assistant knows.


2 Using Module-Assistant In Command-Line Mode
Install module-assistant as follows:

# aptitude install module-assistant

Next we must make module-assistant download the headers of the current kernel, and some tools that are needed to build packages from source (such as build-essential, etc.). This can be achieved with the following command:

# m-a prepare

Now we update the list of available kernel modules by running:

# m-a update

server1:~# m-a update

Updated infos about 85 packages

server1:~#

The command

# m-a list

shows a list of available kernel modules in detailed form, and

# m-a -t list | grep -E '^[^ ].*\(' | cut -d " " -f 1 | sort

shows the same list in short form, e.g. as follows:

server1:~# m-a -t list | grep -E '^[^ ].*\(' | cut -d " " -f 1 | sort
acx100-source
affix-source
alsa-source
arla-modules-source
at76c503a-source
bcm4400-source
bcm5700-source
cdfs-src
cipe-source
cloop-src
comedi-source
cpad-kernel-source
cryptoapi-core-source
cryptoloop-source
dazuko-source
ddrmat-source
device3dfx-source
drbd0.7-module-source
drbd8-module-source
dvb-driver-source
e100-source
eagle-usb-modules-source
em8300-source
exmap-modules-source
fglrx-kernel-src
freeswan-modules-source
ftape-source
ftpfs-src
fuse-source
fwatch-modules-src
gpib-modules-source
hostap-source
hubcot-source
i2c-source
ieee80211-source
ipw2100-source
ipw2200-source
ivtv-source
kqemu-source
linux-uvc-source
linux-wlan-ng-source
lirc-modules-source
lm-sensors-source
loop-aes-ciphers-source
loop-aes-source
lufs-source
madwifi-source
mga-vid-source
misdn-kernel-source
ndiswrapper-source
nozomi-source
nvidia-kernel-legacy-source
nvidia-kernel-source
openafs-modules-source
openswan-modules-source
ov511-source
pcmcia-source
plex86-kernel-src
ppscsi-source
qc-usb-source
qla2x00-source
realtime-lsm-source
rt2400-source
rt2500-source
rt2570-source
rtai-source
shfs-source
sl-modem-source
spca5xx-source
squashfs-source
sysprof-module-source
thinkpad-source
tidev-modules-source
translucency-source
tun-source
unicorn-source
unionfs-source
userlink-source
vaiostat-source
video4linux-nw802-source
wacom-kernel-source
xdslusb-source
xlibmesa-drm-src
zaptel-source
zd1211-source
server1:~#

Before we pick a module to build, we should make sure that our /etc/apt/sources.list includes the contrib and non-free repositories because otherwise module-assistant might not be able to install required dependencies for the kernel module that we want to build:

# vi /etc/apt/sources.list

[...]
deb http://ftp2.de.debian.org/debian/ lenny main contrib non-free
deb-src http://ftp2.de.debian.org/debian/ lenny main contrib non-free

deb http://security.debian.org/ lenny/updates main contrib non-free
deb-src http://security.debian.org/ lenny/updates main contrib non-free
[...]

Run

# aptitude update

if you had to modify /etc/apt/sources.list.

Now we can build the kernel module. I want to build the ndiswrapper kernel module, so I run:

# m-a a-i ndiswrapper

(Please note that m-a list appends the string -source to all available modules, but we leave that string out when we build the module with m-a a-i!)

This will not only build the kernel module .deb package, but also automatically install it.
Now that the module is installed, we can load it into our kernel as follows:

# modprobe ndiswrapper

To check if it really got loaded, run:

# lsmod | grep ndiswrapper

The output should be similar to this one:

server1:~# lsmod | grep ndiswrapper
ndiswrapper           152348  0
usbcore               118160  1 ndiswrapper

server1:~#

To make sure that the module gets loaded automatically whenever you boot the system, you can add it to
 /etc/modules:

# vi /etc/modules

[...]
ndiswrapper

That's it!


3 Using Module-Assistant In Interactive Mode


Install module-assistant as follows:

# aptitude install module-assistant

Before we start module-assistant in interactive mode, we should make sure that our /etc/apt/sources.list includes the contrib and non-free repositories because otherwise module-assistant might not be able to install required dependencies for the kernel module that we want to build:

# vi /etc/apt/sources.list

[...]
deb http://ftp2.de.debian.org/debian/ lenny main contrib non-free
deb-src http://ftp2.de.debian.org/debian/ lenny main contrib non-free

deb http://security.debian.org/ lenny/updates main contrib non-free
deb-src http://security.debian.org/ lenny/updates main contrib non-free
[...]

Run

# aptitude update

if you had to modify /etc/apt/sources.list.

To start module-assistant in interactive mode, simply type:

# m-a

You will see the following dialogue. We must make module-assistant download the headers of the current kernel, and some tools that are needed to build packages from source (such as build-essential, etc.). To do this, select PREPARE:


Click to enlarge


Now we update the list of available kernel modules by selecting UPDATE:


Click to enlarge


Afterwards, go to SELECT:


Click to enlarge


You will see the list of available kernel modules. Pick the one you want to build by pressing the SPACE bar (I select ndiswrapper in this example), and hit Ok:


Click to enlarge



Click to enlarge


Select Yes to install/upgrade the selected source package:


Click to enlarge


Now the kernel module is being built:


Click to enlarge


After the build process is complete, select Yes if you want to install the module:


Click to enlarge


Alternatively, you can as well select INSTALL in this menu:


Click to enlarge


After you've installed the module, select BACK to go back to the list of available modules:


Click to enlarge


Select Cancel to leave the list and go back to the main menu:


Click to enlarge


In the main menu, choose EXIT to leave module-assistant:


Click to enlarge


Now that the module is installed, we can load it into our kernel as follows:

# modprobe ndiswrapper

To check if it really got loaded, run:

# lsmod | grep ndiswrapper

The output should be similar to this one:

server1:~# lsmod | grep ndiswrapper
ndiswrapper           152348  0
usbcore               118160  1 ndiswrapper

server1:~#

To make sure that the module gets loaded automatically whenever you boot the system, you can add it to /etc/modules:

# vi /etc/modules

[...]
ndiswrapper

That's it!


4 Links

No comments:

Post a Comment