5

I'm trying to compile and insert a module into my kernel, but I keep getting this error:

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

I followed the steps described in this tutorial over here:http://www.cyberciti.biz/tips/compiling-linux-kernel-module.html. And everything seemed to make sense and worked. I got my sample module compiled BUT there was a warning that might be an important lead to why this thing is failing. The warning was this one:

WARNING: Symbol version dump /usr/src/linux-3.0.0/Module.symvers is missing; modules will have no dependencies and modversions.

I frankly don't know why the Module.symvers file is not there. The /usr/src/linux-3.0.0 directory and all its contents were created by me after I dowloaded the sources using this command:

apt-get source linux-image-$(uname -r)

That was in fact the only step of that tutorial that I didn't follow, because I could not find the exact sources for my kernel (3.0.0-32-generic) and thought the aptitude tool would sort that out to me.

And I'm running Ubuntu on a 64 bits machine by the way, here's the uname -a output:

Linux vega 3.0.0-32-generic #51-Ubuntu SMP Thu Mar 21 15:50:59 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

Any suggestions as to what to try next? any recommended reading?

PS1. After some more research I confirmed I'm running the 3.0.0-32-generic. update-grub returned:

Found linux image: /boot/vmlinuz-3.0.0-32-generic

But after issuing a sudo make oldconfig and checking the resulting .config file I get this interesting line:

CONFIG_VERSION_SIGNATURE="Ubuntu 3.0.0-32.51-generic 3.0.69"

Does that qualify as a missmatch?

PS2. dmesg outputs this:

[    5.869900] ADDRCONF(NETDEV_UP): eth1: link is not ready
[    6.144304] EXT4-fs (dm-1): re-mounted. Opts: errors=remount-ro
[    6.368936] EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: (null)
[    6.433919] vesafb: mode is 640x480x32, linelength=2560, pages=0
[    6.433921] vesafb: scrolling: redraw
[    6.433923] vesafb: Truecolor: size=8:8:8:8, shift=24:16:8:0
[    6.435424] vesafb: framebuffer at 0xb0000000, mapped to 0xffffc90012800000, using 1216k, total 1216k
[    6.435516] Console: switching to colour frame buffer device 80x30
[    6.443104] EXT4-fs (dm-2): mounted filesystem with ordered data mode. Opts: (null)
[    6.450198] fb0: VESA VGA frame buffer device
[    8.884523] e1000e: eth1 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: Rx/Tx
[    8.885845] ADDRCONF(NETDEV_CHANGE): eth1: link becomes ready
[   12.611236] init: ssh main process (762) terminated with status 255
[   12.624381] init: failsafe main process (752) killed by TERM signal
[   12.634739] type=1400 audit(1373412287.107:8): apparmor="STATUS" operation="profile_load" name="/usr/sbin/tcpdump" pid=852 comm="apparmor_parser"
[   12.634873] type=1400 audit(1373412287.107:9): apparmor="STATUS" operation="profile_replace" name="/sbin/dhclient" pid=851 comm="apparmor_parser"
[   12.635180] type=1400 audit(1373412287.107:10): apparmor="STATUS" operation="profile_replace" name="/usr/lib/NetworkManager/nm-dhcp-client.action" pid=851 comm="apparmor_parser"
[   12.635403] type=1400 audit(1373412287.107:11): apparmor="STATUS" operation="profile_replace" name="/usr/lib/connman/scripts/dhclient-script" pid=851 comm="apparmor_parser"
[   19.390991] eth1: no IPv6 routers present
[  576.758697] hello: no symbol version for module_layout
Bilthon
  • 2,461
  • 8
  • 36
  • 44
  • exactly after you run insmod what dmesg says, for example last 10 lines? – fghj Jul 10 '13 at 01:24
  • I just updated the question to paste some more lines of what dmesg outputs, but I believe only the last one to be relevant. – Bilthon Jul 10 '13 at 01:34
  • here http://stackoverflow.com/questions/1738539/how-do-i-fix-no-symbol-version-for-module-layout? – fghj Jul 10 '13 at 01:36
  • The problem in that link apparently was that he had a missmatch between the kernel's headers and source files. In my case the problem seems to be that I have the wrong sources. But I don't know how to get the right ones and don't really want to recompile the kernel. – Bilthon Jul 10 '13 at 01:50
  • In my opinion, all that you need is kernel headers. To get it on Ubuntu run following `apt-get install linux-headers-$(uname -r)` – Alexey Shmalko Jul 10 '13 at 07:53
  • The correct way is to obtain the right headers and build the kernel and modules. If you can **NOT** then, take a look at my answer for a similar question **[here](http://stackoverflow.com/questions/17369905/how-to-do-make-drivers-usb-storage-usb-storage-ko/17422682#17422682)**. – TheCodeArtist Jul 10 '13 at 11:25

1 Answers1

7

your current kernel version is 3.0.0-32-generic go to cd /lib/modules/3.0.0-32-gereric/ directory and check whether build directory is present or not. If present then you can directly compile your module using below command

make -C /lib/modules/3.0.0-32-generic/build M=$(PWD) modules

if you want to compile your module with kernel downloaded by you then follow the procedure below:

cd /usr/src/linux-3.0.0/

make menuconfig

make -j5

make modules

sudo make modules_install

sudo make install

sudo reboot 

then boot your system with linux-3.0.0 kernel, and compile your module using below command:

make -C /lib/modules/3.0.0/build M=$(PWD) modules
hft
  • 1,245
  • 10
  • 29
vishnumotghare
  • 591
  • 1
  • 5
  • 23
  • Thanks, I'll accept your answer as it's the only one provided as such! I didn't go through your steps though. Instead I just compiled a new kernel and ran insmod on the new one. It worked, but I also noticed that even though I did have the sources, they were not compiled so that might have been my problem. – Bilthon Jul 22 '13 at 04:24
  • Very helpful! I rebooted and insmod gave me this error on code that was working 5 minutes before. I checked in /lib/modules and sure enough there was a second dir with a later version number. I switched my make file to use the version and everything started working again. – Ethan Heilman Feb 19 '15 at 19:58