How do I compile DKMS module for multiple kernel image versions in Debian?

8,780

You can use DKMS install command (Ref: man dkms) to rebuild and install the module for specific kernel. Below an example created by removing virtualbox modules for one kernel version.

sudo dkms install <module-name>/<module-version> -k <kernel-version>

$ dkms status
vboxhost, 5.0.10, 4.2.0-21-generic, x86_64: installed
vboxhost, 5.0.10, 4.2.0-22-generic, x86_64: installed
vboxhost, 5.0.10, 4.2.0-23-generic, x86_64: installed
vboxhost, 5.0.10, 4.2.0-25-generic, x86_64: installed

$ sudo dkms remove vboxhost/5.0.10 -k 4.2.0-22-generic
...

$ dkms status
vboxhost, 5.0.10, 4.2.0-21-generic, x86_64: installed
vboxhost, 5.0.10, 4.2.0-23-generic, x86_64: installed
vboxhost, 5.0.10, 4.2.0-25-generic, x86_64: installed


$ sudo dkms install vboxhost/5.0.10 -k 4.2.0-22-generic

Kernel preparation unnecessary for this kernel.  Skipping...

Building module:
cleaning build area....
make KERNELRELEASE=4.2.0-22-generic -C /lib/modules/4.2.0-22-generic/build M=/var/lib/dkms/vboxhost/5.0.10/build...............
cleaning build area....

DKMS: build completed.

vboxdrv.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/4.2.0-22-generic/updates/dkms/

vboxnetflt.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/4.2.0-22-generic/updates/dkms/

vboxnetadp.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/4.2.0-22-generic/updates/dkms/

vboxpci.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/4.2.0-22-generic/updates/dkms/

depmod....

DKMS: install completed.

$ dkms status
vboxhost, 5.0.10, 4.2.0-21-generic, x86_64: installed
vboxhost, 5.0.10, 4.2.0-22-generic, x86_64: installed
vboxhost, 5.0.10, 4.2.0-23-generic, x86_64: installed
vboxhost, 5.0.10, 4.2.0-25-generic, x86_64: installed
Share:
8,780

Related videos on Youtube

Gilles 'SO- stop being evil'
Author by

Gilles 'SO- stop being evil'

Updated on September 18, 2022

Comments

  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 1 year

    I have versions 3.16 and 4.0 of linux-image package installed. During login I can select which kernel I want to boot in the "advanced options" menu item. However, when I install a DKMS module it is compiled only for the newer version:

    Setting up fglrx-modules-dkms (1:14.12-1) ...
    Loading new fglrx-14.12 DKMS files...
    Building only for 4.0.0-1-amd64
    

    Relevant packages (linux-headers, linux-kbuild, linux-compiler-gcc) are installed for 3.16 too.

    Why does the package not get compiled for the old kernel image? Can I configure something so it is compiled?

    • Admin
      Admin almost 9 years
      Does it already exist, perhaps?
    • Admin
      Admin almost 9 years
      I don't have access to that computer right now to check, but I got the same message trying to reinstall that DKMS package. So, probably no.
    • Admin
      Admin almost 9 years
      No, it was not installed. However, now a newer version of that package became available, and once I upgraded, it got automatically built for both kernels. So, it might have been some problem in the package too. On the other hand, I performed upgrade while booted in 3.16, so maybe it always builds for the current kernel and any installed newer ones?
  • Ruslan
    Ruslan almost 8 years
    Great, this works. And to learn which modules and versions are known to DKMS, use dkms status command.