Compiling modules against OpenSUSE kernel

Hi All,
I am having some issues compiling kernel modules against the pre-built OpenSUSE kernel.

Whenever I compile a module and try to load it, I get something like:


insmod fs/smbfs/smbfs.ko
insmod: error inserting 'fs/smbfs/smbfs.ko': -1 Invalid module format

It doesn’t actually matter what the module is, they all do the same thing. I have tried the above mentioned smbfs, I’ve also tried:

  • vmware kernel module
  • nVidia
  • VirtualBox

However, if I compile the entire kernel (and boot from it), the individual module loads fine.

This behavior is consistent across a significant number of machines and installations (>6). As I recall, when I first started using SuSE at around version 9.2, I could successfully compile modules against the supplied kernel. Somewhere around version 10.x (possibly 10.1) it changed. Similarly, I’ve used RedHat / Fedora / CentOS extensively over the years, and compiling modules always worked on them.

For the past few years I’ve actually been compiling the entire kernel so that I can then compile the individual module. That’s starting to wear a little thin.

NB. When I do make my own kernel, even just doing a make all after a make cloneconfig, the resulting kernel and modules are significantly different in size to the supplied ones. eg:

-rw-r--r--  1 root root 3.3M Jan 29 01:26 vmlinuz-2.6.31.12-0.1-xen
-rw-r--r--  1 root root 3.2M Feb 21 12:48 vmlinuz-2.6.31.8-0.2-xen

To me, this seems to indicate that there is something different about how the supplied kernel was built compared to the ones I build locally. I have no idea what though.

I do recall some times when I was using RedHat that I couldn’t compile modules for a specific kernel release. In those cases, the supplied kernel had been compiled with a different version of gcc than was supplied with the distro, so the resulting modules weren’t right for the kernel. Does anyone know what compiler / version is used to build the standard OpenSUSE kernel?

I have following kernel related packages installed:

  • kernel-desktop-2.6.31.12-0.1.1.x86_64
  • kernel-desktop-devel-2.6.31.12-0.1.1.x86_64
  • kernel-default-2.6.31.12-0.1.1.x86_64
  • kernel-source-2.6.31.12-0.1.1.noarch
  • kernel-xen-devel-2.6.31.12-0.1.1.x86_64
  • kernel-xen-2.6.31.12-0.1.1.x86_64
  • kernel-default-devel-2.6.31.12-0.1.1.x86_64
  • linux-kernel-headers-2.6.31-3.4.noarch
  • kernel-debug-devel-2.6.31.12-0.1.1.x86_64
  • kernel-syms-2.6.31.12-0.1.1.x86_64

Before trying to compile a module I do:

  • make clean
  • make cloneconfig
  • make prepare
  • make modules_prepare

Does anyone have any thoughts on how to successfully compile individual modules without compiling the entire kernel as well?

Which kernel are you actually booting from

Post result of:

uname -a
Linux david 2.6.31.12-0.1-default #1 SMP 2010-01-27 08:20:11 +0100 x86_64 x86_64 x86_64 GNU/Linux

Although, as mentioned, this behavior is consistent across multiple machines / installations / versions / kernel types.

But only kernel-desktop in your list has anything like what you need.

Do you have a reason for installing all those different kernels?

The default and desktop kernels were installed by the installer (possibly in a previous version). I installed the xen kernel the other day when I wanted to try it.

As far as I’m aware, there isn’t any real downside to having multiple kernels installed. You only use one at a time. The others just sit there until they are used.

Let me show you mine, I have no problems

kernel-default-2.6.31.12-0.1.1.i586
kernel-default-base-2.6.31.12-0.1.1.i586
kernel-firmware-20090821-4.1.noarch
kernel-default-devel-2.6.31.12-0.1.1.i586
kernel-source-2.6.31.12-0.1.1.noarch

Haven’t had any problems myself, e.g. with compiling vboxdrv, through all the releases of openSUSE. Maybe you have a systemic error, e.g. an older and incompatible version of gcc or binutils that’s in /usr/local/bin or somewhere ahead in your PATH and getting invoked instead of the correct ones. Do this:

which gcc as ld nm strip

Anything location other than /usr/bin is not good.

Perhaps you should also post the log of a compile session. E.g. /var/log/vbox-install.log

Could you please run through the exact steps you use to compile an individual kernel module. for example the smbfs module I’ve been using as an example.

NB. To find it in the “make xconfig”, look under “File systems” -> “Network File systems” (select SMB file system at that level)

Thanks,
David

I’ve only ever compiled the vboxdrv module and the command is simply

/etc/init.d/vboxdrv setup

But the commands for compiling other kernel modules are simply those given in heaps of tutes on the net, no black magic involved, generally just running make.

which gcc as ld nm strip
/usr/bin/gcc
/usr/bin/as
/usr/bin/ld
/usr/bin/nm
/usr/bin/strip

Everything is where I would expect it.

As mentioned, I’ve had this issue across many systems etc. It may well be systematic in the way I set my OpenSUSE boxes up.

I install the “Linux Kernel Development” pattern. I assume that it installs everything I need.

gcc --version
gcc (SUSE Linux) 4.4.1 [gcc-4_4-branch revision t
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE

.

Just to reitterate, if I compile the entire kernel myself first, I can then compile any additional modules I like. But if I use exactly the same method with the pre-compiled kernel it fails.

Below is an example of the commands I use. NB. when I do the “make xconfig” step I set the SMB file system module as mentioned above.

Could someone else try these steps and let me know what they get.

Alternatively, could someone describe their exact steps to compile a module.

NB. When I do things like build the nVidia or VMware modules, it compiles fine, there are no issues shown in the logs, but just fails to insert into the running kernel, exactly the same as this example.

The commands I use are:


cd /usr/src/linux
make mrproper
make cloneconfig
make prepare
make modules_prepare
make xconfig
make fs/smbfs/smbfs.ko
insmod fs/smbfs/smbfs.ko

The output from the above is:


david:/usr/src/linux # make mrproper
  CLEAN   /usr/src/linux-2.6.31.12-0.1
  CLEAN   .tmp_versions               
  CLEAN   scripts/basic               
  CLEAN   scripts/genksyms            
  CLEAN   scripts/kconfig             
  CLEAN   scripts/mod                 
  CLEAN   scripts/selinux/mdp         
  CLEAN   scripts                     
  CLEAN   include/config              
  CLEAN   .config .config.old include/asm include/linux/autoconf.h include/linux/version.h include/linux/utsrelease.h include/linux/bounds.h include/asm/asm-offsets.h Module.symvers Module.markers                                                                                                                                          
david:/usr/src/linux # make cloneconfig                                                                                                                                
  HOSTCC  scripts/basic/fixdep                                                                                                                                         
  HOSTCC  scripts/basic/docproc                                                                                                                                        
  HOSTCC  scripts/basic/hash                                                                                                                                           
  HOSTCC  scripts/kconfig/conf.o                                                                                                                                       
  HOSTCC  scripts/kconfig/kxgettext.o                                                                                                                                  
  SHIPPED scripts/kconfig/zconf.tab.c                                                                                                                                  
  SHIPPED scripts/kconfig/lex.zconf.c                                                                                                                                  
  SHIPPED scripts/kconfig/zconf.hash.c                                                                                                                                 
  HOSTCC  scripts/kconfig/zconf.tab.o                                                                                                                                  
  HOSTLD  scripts/kconfig/conf                                                                                                                                         
Cloning configuration file /proc/config.gz                                                                                                                             

#
# configuration written to .config
#                                 
david:/usr/src/linux # make prepare
scripts/kconfig/conf -s arch/x86/Kconfig
  CHK     include/linux/version.h       
  UPD     include/linux/version.h       
  CHK     include/linux/utsrelease.h    
  UPD     include/linux/utsrelease.h    
  SYMLINK include/asm -> arch/x86/include/asm
  CC      kernel/bounds.s                    
  GEN     include/linux/bounds.h             
  CC      arch/x86/kernel/asm-offsets.s      
  GEN     include/asm/asm-offsets.h          
  CALL    scripts/checksyscalls.sh           
david:/usr/src/linux # make modules_prepare
  CHK     include/linux/version.h          
  CHK     include/linux/utsrelease.h       
  SYMLINK include/asm -> arch/x86/include/asm
  CALL    scripts/checksyscalls.sh           
  HOSTCC  scripts/genksyms/genksyms.o        
  SHIPPED scripts/genksyms/lex.c             
  SHIPPED scripts/genksyms/parse.h           
  SHIPPED scripts/genksyms/keywords.c        
  HOSTCC  scripts/genksyms/lex.o             
  SHIPPED scripts/genksyms/parse.c           
  HOSTCC  scripts/genksyms/parse.o           
  HOSTLD  scripts/genksyms/genksyms          
  CC      scripts/mod/empty.o                
  HOSTCC  scripts/mod/mk_elfconfig           
  MKELF   scripts/mod/elfconfig.h            
  HOSTCC  scripts/mod/file2alias.o           
  HOSTCC  scripts/mod/modpost.o              
  HOSTCC  scripts/mod/sumversion.o           
  HOSTLD  scripts/mod/modpost                
  HOSTCC  scripts/selinux/mdp/mdp            
  HOSTCC  scripts/kallsyms
  HOSTCC  scripts/conmakehash
  HOSTCC  scripts/bin2c
david:/usr/src/linux # make xconfig
  CHECK   qt
sed < scripts/kconfig/lkc_proto.h > scripts/kconfig/lkc_defs.h 's/P(\([^,]*\),.*/#define \1 (\*\1_p)/'
  HOSTCC  scripts/kconfig/kconfig_load.o
/usr/lib/qt3//bin/moc -i scripts/kconfig/qconf.h -o scripts/kconfig/qconf.moc
  HOSTCXX scripts/kconfig/qconf.o
  HOSTLD  scripts/kconfig/qconf
scripts/kconfig/qconf arch/x86/Kconfig
#
# configuration written to .config
#
david:/usr/src/linux # make fs/smbfs/smbfs.ko
scripts/kconfig/conf -s arch/x86/Kconfig
  CHK     include/linux/version.h
  CHK     include/linux/utsrelease.h
  SYMLINK include/asm -> arch/x86/include/asm
  CALL    scripts/checksyscalls.sh
  CC [M]  fs/smbfs/proc.o
  CC [M]  fs/smbfs/dir.o
  CC [M]  fs/smbfs/cache.o
  CC [M]  fs/smbfs/sock.o
  CC [M]  fs/smbfs/inode.o
  CC [M]  fs/smbfs/file.o
  CC [M]  fs/smbfs/ioctl.o
  CC [M]  fs/smbfs/getopt.o
  CC [M]  fs/smbfs/symlink.o
  CC [M]  fs/smbfs/smbiod.o
  CC [M]  fs/smbfs/request.o
  LD [M]  fs/smbfs/smbfs.o
  MODPOST 1 modules
  CC      fs/smbfs/smbfs.mod.o
  LD [M]  fs/smbfs/smbfs.ko
david:/usr/src/linux # insmod fs/smbfs/smbfs.ko
insmod: error inserting 'fs/smbfs/smbfs.ko': -1 Invalid module format


A search on that insmod message returns lots of possible reasons. Here’s one that you should investigate:

insmod: error inserting ‘x.ko’: -1 Invalid module format | KernelTrap

Thank you for that.

I’ve done quite a bit of Googling similar to this, but I haven’t found anything that really helps.

Most of the results I’ve found relate to some specific issue. In my case it is a systematic issue.

I think that the problem is that there is something different about my build system than that used to build the supplied kernel. I just can’t figure out what it is.

What happens if you try to build vboxdrv.ko without messing with the kernel sources directory at all? AFAIK, people may have trouble compiling vboxdrv.ko for various reasons like gcc or make missing, but nobody has hit a wrong module format error when they have all the prerequisites.

/etc/init.d/vboxdrv setup

OK, now this is weird. I can now successfully run:

/etc/init.d/vboxdrv setup

and the “xboxdrv” module loads fine. I’m now running the Sun version of VirtualBox.

Whereas before it compiled successfully, but wouldn’t load.

That’s actually what started me trying to fix this today.

However, this hasn’t fixed my more general problem.

Another example, if I try to compile the nfs module:

david:/usr/src/linux # rmmod nfs
david:/usr/src/linux # make fs/nfs/nfs.ko
  CHK     include/linux/version.h        
  CHK     include/linux/utsrelease.h     
  SYMLINK include/asm -> arch/x86/include/asm
  CALL    scripts/checksyscalls.sh           
  CC [M]  fs/nfs/client.o                    
  CC [M]  fs/nfs/dir.o
  CC [M]  fs/nfs/file.o
  CC [M]  fs/nfs/getroot.o
  CC [M]  fs/nfs/inode.o
  CC [M]  fs/nfs/super.o
  CC [M]  fs/nfs/nfs2xdr.o
  CC [M]  fs/nfs/direct.o
  CC [M]  fs/nfs/pagelist.o
  CC [M]  fs/nfs/proc.o
  CC [M]  fs/nfs/read.o
  CC [M]  fs/nfs/symlink.o
  CC [M]  fs/nfs/unlink.o
  CC [M]  fs/nfs/write.o
  CC [M]  fs/nfs/namespace.o
  CC [M]  fs/nfs/mount_clnt.o
  CC [M]  fs/nfs/nfs3proc.o
  CC [M]  fs/nfs/nfs3xdr.o
  CC [M]  fs/nfs/nfs3acl.o
  CC [M]  fs/nfs/nfs4proc.o
  CC [M]  fs/nfs/nfs4xdr.o
  CC [M]  fs/nfs/nfs4state.o
  CC [M]  fs/nfs/nfs4renewd.o
  CC [M]  fs/nfs/delegation.o
  CC [M]  fs/nfs/idmap.o
  CC [M]  fs/nfs/callback.o
  CC [M]  fs/nfs/callback_xdr.o
  CC [M]  fs/nfs/callback_proc.o
  CC [M]  fs/nfs/nfs4namespace.o
  CC [M]  fs/nfs/sysctl.o
  CC [M]  fs/nfs/fscache.o
  CC [M]  fs/nfs/fscache-index.o
  LD [M]  fs/nfs/nfs.o
  MODPOST 2 modules
  CC      fs/nfs/nfs.mod.o
  LD [M]  fs/nfs/nfs.ko
david:/usr/src/linux # insmod fs/nfs/nfs.ko
insmod: error inserting 'fs/nfs/nfs.ko': -1 Invalid module format
david:/usr/src/linux # ls -lah fs/nfs/nfs.ko /lib/modules/`uname -r`/kernel/fs/nfs/nfs.ko
-rw-r--r-- 1 root root 645K Jan 29 01:47 /lib/modules/2.6.31.12-0.1-default/kernel/fs/nfs/nfs.ko
-rw-r--r-- 1 root root 7.3M Feb 27 20:07 fs/nfs/nfs.ko

Note the massive difference in size of the resulting modules.

Could someone else see if they can duplicate this, or if it actually works for them.

I think what you are doing wrong is putting the foreign module source into the kernel source tree. Usually the foreign module is designed so that you unpack it elsewhere, adjust the Makefile to point to the untouched kernel source from the openSUSE package, and compile it. That’s how vboxdrv is compiled. if you look at the log it leaves behind.

Now what you do for native modules is I think make a copy of a sufficiently independent part of the tree elsewhere, modify it and proceed as above. So you don’t really need that make config stuff in the kernel source directory. I think that’s what causing your resulting module to be incompatible with the installed kernel.

But I’m not actually making a foreign module. The smbfs and nfs modules are standard kernel modules. It’s just that when I compile them, they won’t work with the supplied kernel.

I do get the same effect when I compile third party modules, but when I make them I use whatever instructions came with them.

Could someone see if they can compile say the nfs module and load it. You don’t have to install it permanently or anything. Just use insmod on the resulting .ko (after rmmodding the supplied nfs module)

Thanks,
David

The point is you should not be compiling them inside the kernel source tree if you want to them work with the existing kernel. If you are going to build the whole kernel, then sure. If you look at instructions for compiling say one NIC driver updated by the vendor, e.g. e1000, these are compiled outside of the kernel source using a reference to the kernel sources.

Though I don’t know how easy it is to build a subsystem like NFS outside of the kernel source tree. I don’t know if you could make a copy of the NFS sources and compile them outside of the main kernel using a reference.

Or you could just accept it and build your own private version of the kernel and modules and install them.

Hi
I always use the rpm method to build/patch kernel modules, using a
standard spec file, the modules source zipped up and a preamble (txt)
file.

Search on the OBS for a kmp src rpm… here is on I did to flip a
webcam video;
http://software.opensuse.org/search?baseproject=openSUSE%3A11.2&p=1&q=uvcvideo


Cheers Malcolm °¿° (Linux Counter #276890)
SUSE Linux Enterprise Desktop 11 (x86_64) Kernel 2.6.27.42-0.1-default
up 19 days 18:57, 4 users, load average: 0.41, 0.30, 0.18
GPU GeForce 8600 GTS Silent - CUDA Driver Version: 190.53

OK, I’ve solved the problem (well at least I think I have).

The problem was that “make mrproper” removed the
/usr/src/linux/Module.symvers file. Therefore the kernel modules that I was making didn’t match the running kernel.

When I compiled the entire kernel myself the Module.symvers file was recreated so I could then create more modules fine.

There is a copy of the Module.symvers file in the
/lib/modules/uname -r/build/
directory.

I copied that file back to /usr/src/linux and I can now compile modules fine, well my test on the nfs module worked anyway.

The resulting modules are still massively different in size, but it loaded fine.

I hope this helps someone else in the future.