0

I am developing a kernel module and need to compile it for an older version of Gentoo that I don't have the headers for. The Linux kernel version is 4.14.34 and I have the source for that, with the output from uname -r being 4.14.34-gentoo-x64. However, when I compiled the module using that source and tried to insmod the module it create it output insmod: ERROR: could not insert module module.ko: Invalid module format.

I have access to the system and could potentially pull some headers from that but I'm not entirely sure where to get them from since the normal directories that I would pull the headers from (/usr/src/linux-x64 or /lib/modules/4.14.34-gentoo-x64/build) don't exist. I've looked around and haven't been able to find the Gentoo 4.14.34 source anywhere.

I'm fairly new to kernel module development, so I may be missing something obvious, but what are the minimum required files to compile for a specific kernel version? Alternatively, is the source for Gentoo 4.14.34 available?

RPiAwesomeness
  • 5,009
  • 10
  • 34
  • 52

1 Answers1

0

Linux 4.14 is still in the portage tree. The headers from a more recent patch should do just fine - you (probably) don't need the older patch version.

$ export FMT='<category>/<name>-<version>\n'; \
    eix sys-kernel/gentoo-sources \
      --format '<availableversions:FMT>' | grep -e -4.14
sys-kernel/gentoo-sources-4.14.245
sys-kernel/gentoo-sources-4.14.246
sys-kernel/gentoo-sources-4.14.247
sys-kernel/gentoo-sources-4.14.248
sys-kernel/gentoo-sources-4.14.249
sys-kernel/gentoo-sources-4.14.250
sys-kernel/gentoo-sources-4.14.251
sys-kernel/gentoo-sources-4.14.252
sys-kernel/gentoo-sources-4.14.253

With the 4.14.251 being 'stable' aka well tested.

stable 4.14


The corresponding 4.14 headers package is also still available.

$ eix linux-headers
[I] sys-kernel/linux-headers
     Available versions:  3.18^bs 4.4^bs ~4.9^bs 4.14-r1^bs 4.19^bs{tbz2} 5.4-r1^bs{tbz2} ~5.9^bs 5.10^bs{tbz2} ~5.11^bs ~5.12^bs ~5.13^bs (~)5.14^bs{tbz2} {headers-only}
     Installed versions:  5.14^bs{tbz2}(04:48:19 PM 11/01/2021)(-headers-only)
     Homepage:            https://www.kernel.org/ https://wiki.gentoo.org/wiki/Kernel
     Description:         Linux system headers

YOu can find the download location for the headers by looking at the ebuild (package definition):

/var/db/repos/gentoo/sys-kernel/linux-headers/linux-headers-4.14-r1.ebuild

You can download the package like this:

$ emerge =linux-headers-4.14-r1 --fetchonly

The output should tell you where it lands. If in doubt, use $ emerge --info | grep DIST, which produces the output:

DISTDIR="/G/distfiles" 

on my system (I don't remember where the default download location is). So the headers are available in:

$ ls $DISTDIR/gentoo-headers-* -1
/G/distfiles/gentoo-headers-4.14-1.tar.xz
/G/distfiles/gentoo-headers-4.19-1.tar.xz
/G/distfiles/gentoo-headers-4.4-1.tar.xz
/G/distfiles/gentoo-headers-5.10-1.tar.xz
/G/distfiles/gentoo-headers-5.14-1.tar.xz
/G/distfiles/gentoo-headers-5.4-2.tar.xz
/G/distfiles/gentoo-headers-base-4.14.tar.xz
/G/distfiles/gentoo-headers-base-4.19.tar.xz
/G/distfiles/gentoo-headers-base-4.4.tar.xz

You want the "base" archve.

$ tar tf /G/distfiles/gentoo-headers-base-4.14.tar.xz   | shuf | head -n 7 
gentoo-headers-base-4.14/include/media/v4l2-mediabus.h
gentoo-headers-base-4.14/arch/blackfin/include/asm/tlb.h
gentoo-headers-base-4.14/include/linux/mtd/super.h
gentoo-headers-base-4.14/include/linux/timb_gpio.h
gentoo-headers-base-4.14/arch/frv/include/asm/string.h
gentoo-headers-base-4.14/arch/c6x/include/asm/checksum.h
gentoo-headers-base-4.14/arch/um/include/asm/uaccess.h

Hopefully that answers your question.


Pro tip:

join #gentoo on libera irc network and ask your questions there.