login
Header Space

 
 

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

May 22, 2008 - 10:07am
Submitted by Eus on May 22, 2008 - 10:07am.
Linux

That error message is issued because a version mismatch occurs when the Linux kernel module to be inserted into the working kernel was not compiled with the source code that was used to compile the working Linux kernel.

Even when it can be ensured that the module was compiled with the source code that was used to compile the working Linux kernel, a version mismatch can still occur. For example, the source code of Linux kernel 2.6.21.5 in Machine A was used to compile the working Linux kernel for Machine B, but with the following important configuration items:

CONFIG_LOCALVERSION=""
# CONFIG_LOCALVERSION_AUTO is not set
# CONFIG_SMP is not set

Unfortunately, the Linux kernel 2.6.21.5 source code stored in /usr/src/ in Machine B still has the following default values for the configuration items mentioned above:

CONFIG_LOCALVERSION="-smp"
# CONFIG_LOCALVERSION_AUTO is not set
CONFIG_SMP=y

This way, the module compiled with the kernel source code in Machine B cannot be loaded into the working kernel of Machine B because the module has version 2.6.21.5-smp SMP instead of 2.6.21.5.

The remedy will be to set the default values of the configuration items mentioned above of the kernel source code in Machine B to match those that were used to compile the working kernel. Then, run make and hit Ctrl+C after the following lines has appeared on the screen (HOSTLD line does not always appear):

  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf -s arch/i386/Kconfig
  CHK     include/linux/version.h
  CHK     include/linux/utsrelease.h
  UPD     include/linux/utsrelease.h

Archive: Linux Kernel's Module

This way, the module

May 22, 2008 - 10:32am

This way, the module compiled with the kernel source code in Machine B cannot be loaded into the working kernel of Machine B because the module has version 2.6.21.5-smp SMP instead of 2.6.21.5.

typo: 's/Machine B/Machine A/2'?

There's a lot more going on: linux-2.6/scripts/Makefile.modpost

HOSTCC/HOSTLD -- stages, when config/build tools are made using host toolchain, not a cross one (e.g. x86 build host with source, AVR32 or ARM target kernel).

Don't mess with smp/preemt modules and kernels, even of you can make it load and look as if they are working. Just don't.

It's Not a Mistake

May 27, 2008 - 3:03pm

> typo: 's/Machine B/Machine A/2'?

No, I didn't make a mistake.

The state in Machine B is:
1. Working kernel compiled in Machine A (2.6.21.5)
2. Kernel source code (2.6.21.5-smp SMP)

Therefore, when you compile a module in Machine B, the module will always have version string 2.6.21.5-smp SMP because the kernel source code in Machine B has that configuration already. This way the module will not be able to be inserted to the running kernel because of version string mismatch (the running kernel's version string is 2.6.21.5).

> Don't mess with smp/preemt modules and kernels, even of you can make it load and look as if they are working. Just don't.

Yes.

But, I forgot to say that in this case Machine A == Machine B (those are the lab's PCs) and both of them are running the same working Linux kernel compiled in the central computer. Unfortunately, the distro that was installed in both of them has Linux kernel source code whose configuration is different from the working kernel. So, it should be okay to do that in this case.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
speck-geostationary