Getting a Debian kernel source tree for driver compilation

I have stumbled into this a few times, so I’d better write it down. Here is how you get a kernel source tree setup for compilation of drivers under Debian, assuming you’re using a Debian provided kernel package.
The information is shamelessly stolen from Martin List-Petersen:
Lets assume you’ve installed kernel-image-2.x.y-z-arch. It could be kernel-image-2.4.25-1-386 in which case x=4, y=25, z=1, arch=386. These numbers are need in the following.
The procedure is this:
Download the kernel source package:

apt-get install kernel-source-2.x.y

Unpack it:

cd /usr/src
tar -xjvf kernel-source-2.x.y.tar.bz2

Install the correct config-file:

cd kernel-source-2.x.y
cp /boot/config-2.x.y-z-arch .config

Generate dependencies and Makefiles:

make-kpkg --append-to-version "-z-arch" --revision 2.x.y-z --config old configure

Check build link:

rm -f /lib/modules/2.x.y-z-arch/build
ln -s /usr/src/kernel-source-2.x.y /lib/modules/2.x.y-z-arch/build

Most drivers will use the build link to find the correct kernel source tree for include files and Makefiles.
With this in place many drivers can be installed with a simple “make install”.


Comments

13 responses to “Getting a Debian kernel source tree for driver compilation”

  1. Thorbjørn avatar
    Thorbjørn

    I had some problems, when I followed your short description… it does not tell you what other packages you need to do the trick…

    According to http://newbiedoc.sourceforg… you also need:
    1. gcc
    2. kernel-package
    3. kernel-source-2.4.18 (or whatever kernel sources you will be using)
    4. libc6-dev
    5. tk8.0 or tk8.1 or tk8.3
    6. libncurses5-dev
    7. fakeroot
    8. bin86 (for building 2.2.x kernels on PCs)

    Without these packages, make-dpkp stops during execution… it took me some time to figure out what was wrong 🙁

  2. marcel avatar

    Maybe it was not complete but that was the most useful advice I have found after hours of search!

    Marcel

  3. puchatek avatar
    puchatek

    I have this:
    make-kpkg –revision 2.6.11 –config old configure
    /usr/bin/make
    ARCH=i386 oldconfig
    make[1]: Entering directory `/usr/src/kernel-source-2.6.11′
    HOSTCC scripts/basic/fixdep
    In file included from /usr/include/sys/socket.h:35,
    from /usr/include/netinet/in.h:24,
    from /usr/include/arpa/inet.h:23,
    from scripts/basic/fixdep.c:115:
    /usr/include/bits/socket.h:305:24: asm/socket.h: Nie ma takiego pliku ani katalogu
    make[2]: *** [scripts/basic/fixdep] Błąd 1
    make[1]: *** [scripts_basic] Błąd 2
    make[1]: Leaving directory `/usr/src/kernel-source-2.6.11′
    make: *** [stamp-kernel-configure] Błąd 2

    Why?? I have installed
    1. gcc
    2. kernel-package
    3. kernel-source-2.4.18 (or whatever kernel sources you will be using)
    4. libc6-dev
    5. tk8.0 or tk8.1 or tk8.3
    6. libncurses5-dev
    7. fakeroot
    8. bin86 (for building 2.2.x kernels on PCs)

  4. puchatek avatar
    puchatek

    *** 3. kernel-source-2.6.11-7
    # uname -a
    Linux boomcak 2.6.11 #2 SMP Thu May 26 20:53:11 CEST 2005 i686 GNU/Linux

  5. Worked for me, thanks to both of you!

  6. Thanks a million! To get make-kpkg, you need to install kernel-package and ncurses-dev. If you’re as clueless how to do this as I was (Linux is surprisingly different from FreeBSD!), type “apt-get install kernel-package ncurses-dev” as root. Obviously, don’t type the quotes (“).

  7. SNOWman avatar

    Txt Akshay, I had the same problem and you helped me. Great!

  8. Calamitynouch avatar
    Calamitynouch

    Hi, I have a pb : I need to link from /lib/modules/ the “includes” directory from kernel and the “.config” file in order to install ndiswrapper (for SMC wifi card driver). Don’t know how to do without crashing everything ;-). Thanx for your help

  9. Calamitynouch avatar
    Calamitynouch

    Hi, I have a pb : I need to link from /lib/modules/ the “includes” directory from kernel and the “.config” file in order to install ndiswrapper (for SMC wifi card driver). Don’t know how to do without crashing everything ;-). Thanx for your help

  10. Phoenix avatar
    Phoenix

    Thank you so much. Following your instructions I finaly got both the kernel source and the driver I was trying to compile to install without error messages or configuration edits.

  11. hi everyone

    Many thanks to René and Ashkay, both of you posted vital info, and I have now successfully compiled my very first kernel module 🙂

    My suggestion for other newbies is to use aptitude rather than apt-get for installing packages – it will look for the dependent packages for you.

    The detailed steps of how to do this are as follows:

    At the main screen, type

    /kernel.source.2.6.

    (or whatever kernel you are on). It puts you at the top of the list of kernels. NB you do *not* want the item kernel.source.2.6, you need to find something like kernel.source.2.6.8.

    Hit return to go to the list it is showing you, use the arrow keys to go to the exact one that you want, and hit + to add it to your system.

    Then

    /kernel.headers.2.6.

    and find the right headers, followed by

    /kernel.package

    Note that ‘.’ is a wild card here, so if you are as lazy as me you can use dot to match any punctuation. (You can also use ‘.*’ as a multi character wild card, and other perl-like regexps)

    Then hit g to get the packages, and aptitude shows you a screen with two main headings, what it thinks you need as well, and what you asked for. Put the cursor on either of these and hit enter to expand the list, if you want to check. For me it had correctly spotted that I needed make and gcc. It did not get the ncurses stuff, but it seemed to work anyway (aptitude lists that as ‘recommnded’ not as essential).

    Then if you need to change anything, use q to quit the get and go back to selecting packages. Use + to add them, – to remove them, then g to look at the list again.

    When the list looks right, press g a second time, and aptitude automatically downloads and installs everything.

    When it comes back, q y will exit. Often (especially on a ssh session) aptitude leaves the screen a mess, so type clear<return> to get bask to clear it for you.

    Now resume René’s instructions from

    cd /usr/src
    tar -xjvf kernel-source-2.6.8.tar.bz2

    Hope this helps someone as much as R & A have helped me here 🙂
    River~~

  12. ps

    In my above posting, please note the trailing dot on lines like

    /kernel.source.2.6.

    which is needed to move aptitude on from the virtual package /kernel.source.2.6 (without the dot).

    R~~

  13. I had additionally to execute “make scripts” in the kernel source tree, to get the above recipe working.
    Otherwise I got the following errors:

    Building modules, stage 2.
    MODPOST
    /bin/sh: scripts/mod/modpost: No such file or directory

Leave a Reply

Your email address will not be published. Required fields are marked *