[HowTo] Manually build a Manjaro kernel module

Recently I’ve discovered some topics about building modules for Manjaro (like How to build a kernel module?) but nobody succeeded to build. Hence, I’m providing my solution to the problem.

I’ve got problematic, not supported USB MIDI device. No vendor/device id in quirks table (sound/usb). So I’ve managed compile standalone module (I’ll try to explain for beginners also):

  1. Download sources from kernel.org (the same version, including minor - check with uname - r). For me it was linux-5.15.85.tar.gz
  2. Unpack sources with tar xfv linux-5.xx.xx.tar.gz
  3. Change dir to sources
  4. Copy your current config : zcat /proc/config.gz > .config
  5. Ensure, in .config file your config set as module, not =y (for me : CONFIG_SND_USB_AUDIO=m)
  6. Perform changes in source code as you wish (this is up to your imagination and responsibility also)
  7. make EXTRAVERSION=-1 modules_prepare - EXTRAVERSION should be the same as for your kernel. Check with uname -r
  8. make M=path_to_module_dir (in my case make M=sound/usb)
  9. Compilation should take few seconds (depending on your machine)
  10. You can find freshly compiled kernel object(s) (*.ko) in the appropriate directory
  11. Replace existing modules or copy to /usr/lib/modules/<your_kernel>/extra (depending whether you would like replace existing modules or compiled new one)
  12. You can strip modules with running strip --strip-debug <ko file> to remove debugging info and symbols (this is to reduce size of the modules we’ve compiled)
  13. Run sudo depmod to rescan module dependencies
  14. Your module should work after running modprobe <module>. You can play also with modprobe and rmmod (to add and remove modules). Get module info/path with modinfo <modname> . Monitor real time situation with dmesg -kW (in separate terminal window)

If any questions, I will try to help

2 Likes

Isn’t dkms meant for exactly this purpose :thinking:
Maybe see: