Make kernel modules available that have been deactivated on Fedora

7,479

I think I got it, although it's probably far from perfect.

  1. Prepare the source code by running

    rpmbuild -bp --target=$(uname -m) kernel.spec
    
  2. Go to the build directory, for example by:

    cd ~/rpmbuild/BUILD/kernel-3.14.fc20/linux-3.14.8-200.fc20.x86_64
    
  3. Edit Makefile and set EXTRAVERSION to something like:

    EXTRAVERSION = -200.fc20.x86_64
    
  4. Enable the modules. I suggest starting with the corresponding file underneath the configs directory (I used kernel-3.14.8-x86_64.config).

  5. Prepare the kernel for modules:

    make modules_prepare
    
  6. Build the module:

    make M=drivers/net/can
    
  7. Profit! Insert the module:

    insmod can-dev.ko
    
Share:
7,479

Related videos on Youtube

frans
Author by

frans

Updated on September 18, 2022

Comments

  • frans
    frans over 1 year

    Edit: I turned Cristians answer into a script which does everything automatically: https://github.com/frans-fuerst/magic/blob/master/fedora-activate-can.sh

    I need some kernel modules which are available in the Linux source but deactivated on Fedora 20 and I wonder what's the easiest and most forward way to do make them available. (namely then net/CAN suport resulting in some can_* modules)

    • are there fedora-repos/rpms which make deactivated modules available?
    • or do I have to compile these modules manually?
    • in this case - is there some mechanism to automate this in case of a kernel update or do i have to compile them over and over again?

    I've already followed this HowTo (and there are many more very similar out there) but the "build a module only" section seems to work only for modules which haven't been disabled because in that case even the module sources are missing.

    Here is what I tried following the mentioned HowTo:

    First I tried to follow the Out Of Tree Modules section but in that damn source tree shipped with kernel-devel even the sources for CAN support are missing. So I try to build the modules from the src.rpm:

    $ yumdownloader --source kernel
    $ sudo yum-builddep kernel-3.14.8-200.fc20.src.rpm
    $ rpm -Uvh kernel-3.14.8-200.fc20.src.rpm
    $ cd ~/rpmbuild/SPECS
    $ rpmbuild -bp --target=$(uname -m) kernel.special
    $ cd ~/rpmbuild/BUILD/<kerneldir>/<linuxdir>
    $ <configure the kernel using menuconfig>
    $ make prepare
    

    Then I build and get some warnings:

    $ make -C /lib/modules/`uname -r`/build M=`pwd`/net/can modules
    make: Entering directory `<rpmbuild-BUILD-kernel-linux-dir>'
    
      WARNING: Symbol version dump <rpmbuild-BUILD-kernel-linux-dir>/Module.symvers
               is missing; modules will have no dependencies and modversions.
    
      CC [M]  <rpmbuild-BUILD-kernel-linux-dir>/net/can/bcm.o
      CC [M]  <rpmbuild-BUILD-kernel-linux-dir>/net/can/gw.o
      CC [M]  <rpmbuild-BUILD-kernel-linux-dir>/net/can/raw.o
      CC [M]  <rpmbuild-BUILD-kernel-linux-dir>/net/can/af_can.o
      CC [M]  <rpmbuild-BUILD-kernel-linux-dir>/net/can/proc.o
      LD [M]  <rpmbuild-BUILD-kernel-linux-dir>/net/can/can.o
      LD [M]  <rpmbuild-BUILD-kernel-linux-dir>/net/can/can-raw.o
      LD [M]  <rpmbuild-BUILD-kernel-linux-dir>/net/can/can-bcm.o
      LD [M]  <rpmbuild-BUILD-kernel-linux-dir>/net/can/can-gw.o
      Building modules, stage 2.
      MODPOST 4 modules
      CC      <rpmbuild-BUILD-kernel-linux-dir>/net/can/can-bcm.mod.o
      LD [M]  <rpmbuild-BUILD-kernel-linux-dir>/net/can/can-bcm.ko
      CC      <rpmbuild-BUILD-kernel-linux-dir>/net/can/can-gw.mod.o
      LD [M]  <rpmbuild-BUILD-kernel-linux-dir>/net/can/can-gw.ko
      CC      <rpmbuild-BUILD-kernel-linux-dir>/net/can/can-raw.mod.o
      LD [M]  <rpmbuild-BUILD-kernel-linux-dir>/net/can/can-raw.ko
      CC      <rpmbuild-BUILD-kernel-linux-dir>/net/can/can.mod.o
      LD [M]  <rpmbuild-BUILD-kernel-linux-dir>/net/can/can.ko
    make: Leaving directory `<rpmbuild-BUILD-kernel-linux-dir>'
    
    $ sudo make -C /lib/modules/`uname -r`/build M=`pwd`/net/can modules_install
    make: Entering directory `<rpmbuild-BUILD-kernel-linux-dir>'
      INSTALL <rpmbuild-BUILD-kernel-linux-dir>/net/can/can-bcm.ko
    Can't read private key
      INSTALL <rpmbuild-BUILD-kernel-linux-dir>/net/can/can-gw.ko
    Can't read private key
      INSTALL <rpmbuild-BUILD-kernel-linux-dir>/net/can/can-raw.ko
    Can't read private key
      INSTALL <rpmbuild-BUILD-kernel-linux-dir>/net/can/can.ko
    Can't read private key
      DEPMOD  3.14.8
    make: Leaving directory `<rpmbuild-BUILD-kernel-linux-dir>'
    

    I don't get the first warning when I just run make modules but this costs me about an hour.

    However after installing, the .ko files are located in the wrong directory (/usr/lib/modules/3.14.8 rather than /usr/lib/modules/3.14.8-200.fc20.x86_64) and after depmod -a and modprobe can I get

    modprobe: ERROR: could not insert 'can': Exec format error
    

    What am I doing wrong?

    • iSee
      iSee almost 10 years
      Are the modules that you want included in the src.rpm? If so, why not install the src.rpm, patch the .config to enable them and then build the RPM? You could also probably build just those modules by following the "Building Only Kernel Modules (Out Of Tree Modules)" section of that howto.
    • frans
      frans almost 10 years
      I did so. But maybe I need some detailed instructions for that. I'm unable to just build the required modules running make M='pwd'/net/can modules. I get WARNING: Symbol version dump <DIR>/Module.symvers is missing; modules will have no dependencies and modversions. When I just run make modules the modules are built but I can't install them to the correct location. When I copy them manually and try to load them I get modprobe: ERROR: could not insert 'can': Exec format error
    • iSee
      iSee almost 10 years
      There's a similar question on Ask Ubuntu: "How do I build a single in-tree kernel module?" (and it also happens to be about CONFIG_CAN_PEAK_USB).
    • frans
      frans almost 10 years
      Unfortunately this is a different situation - On Ubuntu everything is fine because the source for the CAN modules exists. The .symvers file shipped with Fedora does not contain information about the CAN modules. Looks like I have to migrate to Ubuntu if I don't want to compile very single kernel which is being released..
  • frans
    frans almost 10 years
    I'll check this tomorrow and in case that works you really deserve this bounty :) But at the same time I'm really gutted about how Fedora treats people who want to modify their system.. bugzilla.redhat.com/show_bug.cgi?id=871655 also demonstrates this attitude.
  • iSee
    iSee almost 10 years
    Markdown links are vice-versa [...](...). You could request to include the modules in the kernel-modules-extra package (although they're probably gonna refuse on the same grounds) or perhaps ask the guys from RPM Fusion.