1

I am trying to recompile the sound/usb module on Ubuntu 18.10 against the running kernel. I get no compilation errors but when I try to load the module I get this error:

Invalid module format

I am running the 4.18.0-21-lowlatency kernel.

I obtain the kernel source this way

apt source linux

This downloads and extracts the source of the 4.18.0 kernel into the linux-4.18.0 folder.

I copy the .config and Module.symvers files from /lib/modules/4.18.0-21-lowlatency/build to the root of my kernel source directory.

I run make EXTRAVERSION=-21-lowlatency modules_prepare, and then make EXTRAVERSION=-21-lowlatency M=sound/usb

Running insmod results in the following error written into syslog

snd_usb_audio: version magic '4.18.20-21-lowlatency SMP preempt mod_unload ' should be '4.18.0-21-lowlatency SMP preempt mod_unload '

Running modinfo /lib/modules/uname -r/kernel/sound/usb/snd-usb-audio.ko | grep vermagic returns this

vermagic:       4.18.0-21-lowlatency SMP preempt mod_unload

Running modinfo on my newly compiled module returns this

vermagic:       4.18.20-21-lowlatency SMP preempt mod_unload

I traced back the issue to the first few lines of the Makefile

VERSION = 4
PATCHLEVEL = 18
SUBLEVEL = 20

If I change the SUBLEVEL to 0 and then compile, I can successfully load the module.

So even though I am running the 4.18.0 kernel, and the apt source linux seems to download the 4.18.0 kernel, the downloaded files are versioned 4.18.20.

Is this normal or I am missing something?

1 Answer 1

0

I had similar problem. The trouble lies with the method how you obtain the kernel source and how you "build" the kernel. There is a link to what the official way of doing it. I followed it from https://help.ubuntu.com/community/Kernel/Compile. By the look of it, it appears to be out of date and long reading.

Based on the situation I want to use the official released Ubuntu kernel (not from anywhere else) apt-get source xxxxx. It is a folder with Debian folder and a tar ball. Then I follow partial instructions from Trying to build kernel on 18.04. No editconfigs option

  1. Download kernel sources (deb-src should be uncommented in /etc/apt/sources.list)

    $ apt-get install linux-source kernel-package
    
  2. Go to folder with kernel sources and untar

    $ cd /usr/src/linux-source-x.x.x
    $ tar jxvf linux-source-x.x.x.tar.bz2
    
  3. Move content to current folder
    $ mv linux-source-x.x.x/* .
    $ rm -rf linux-source-x.x.x/
    
  4. Get necessary packages
    $ apt-get build-dep linux-source
    $ mkdir debian/stamps
    

Then I can run fakeroot debian/rules clean and fakeroot debian/rules binary-headers binary-generic binary-perarch. In the middle I have to manually copy one amd gpu header file to the missing location, otherwise the compilation failed. This way the fakeroot debian/rules is using your running kernel configuration (uname -r).

If I use the make menuconfigure and .config, I end up the same problem as you. So you can use my sample to use official released Ubuntu kernel and fakeroot debian/rules to compile. The version of the module could match.

My version is Ubuntu 18.04, and my uname -r is 5.3.0-51. I use apt-get to get source around 2020-4-15.

I believe there are other ways to use make instead of fakeroot debian/rules, and it could help to build in-tree modules.

2
  • I ended up missing a few more things but I figured it out. I wrote a blog post about it here: includeguitar.home.blog/2019/06/18/… May 11, 2020 at 9:16
  • @SzőkeSzabolcs, the method you mentioned involves a manual step to change the kernel version in the downloaded kernel, which might overlook the difference between the original downloaded kernel and the version being changed too. Should this "new" version to have a proper patch instead of a manual version update? Still your step might work to avoid the version check when the binary is deployed. but there will be a risk this binary uses different header or function since the manually changed kernel version is not a real kernel with proper patches. This is an acceptable hack if in emergency. Jun 12, 2020 at 0:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .