Install Correct Kernel Header for insmod

Max is learning kernal module programming. And he found a nice online tutorial for beginer
http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html#AEN128. However, the HelloWorld module is successfully built, but insmod failed.

> insmod hello-1.ko
insmod: error inserting 'hello-1.ko: -1 Invalid module format

After googling some time, Max figured out his Debian may have installed incorrect kernel header.
Check the running kernel by
>uname -r

First remove incorrect kernel header package by 'apt-get remove'
Install the following three packages:

  • linux-headers-2.6.26-2-common
  • linux-kbuild-2.6.26
  • linux-headers-2.6.26-2-686
They can be found at http://ftp.us.debian.org/debian/pool/main/l/linux-2.6/. Max download these three deb manually, and installed them. Finally, check whether they are installed by

>dpkg-query --show | grep -i linux-
linux-headers-2.6.26-2-686 2.6.26-21
linux-headers-2.6.26-2-common 2.6.26-21
linux-kbuild-2.6.26 2.6.26-3

Now the hello-1.c can be build and loaded.


No comments:

Post a Comment