How to build a kernel module?

I have spent several days bouncing around on search engines to find how Manjaro builds kernel modules, I found lots of information but largely referencing the outdated ABS build system (Archlinux).
I did find an article on this forum and followed it.
I make the module and when trying to install the module I get this error : [modprobe: ERROR: could not insert ‘vhci_hcd’: Exec format error].
I know I must be missing something. I would appreciate any help. Thanks!

We are missing crucial information - and context.
… what are you trying to do? - and why?
… how did you go about it?

… I probably could deduce some of it from

[modprobe: ERROR: could not insert ‘vhci_hcd’: Exec format error]

but I’d rather have you give the story :wink:

ps:
your link isn’t working
to me it looks like a link (it’s red in color)
but it really isn’t a link - it does not refer to anywhere (for me)
clicking on it does nothing for me

1 Like

You’re kidding us, right? :rofl:

I know what I’m missing. What kernel module are you trying to build and why?

Classic XY Problem.

I thank you for your response. I hope I can replicate the process without term outputs as I am away from the VM. I am using code tags sorry if that is inappropriate.
The what:
I need to recompile a kernel module, usbip to be specific, to up the port counts and virtual hubs.
The why:
I have a need to connect more than 8 USB drives over the network.
The how:
I identified my current kernel

 uname-r 

I installed the needed dev tools

 sudo pacman -S base-devel git 

I installed the linux510-headers (I run 5.10.49-1)

 pacman -S linux510-headers 

I downloaded the kernel source from Manjaro

mkdir ~/Mine cd ~/Mine git clone https://gitlab.manjaro.org/packages/core/linux510.git cd linux510/

I made the src

 makepkg --nobuild 

I prepared the source directory

srcDir=src/linux-5.10 ln -s /usr/lib/modules/5.10.49-1-MANJARO/build/Module.symvers "$srcDir/" zcat /proc/config.gz > "$srcDir/.config" make -C "$srcDir" modules_prepare

I adjusted the .config to contain the new values

nano .config changed line CONFIG_USBIP_VHCI_HC_PORTS=15(8 default I did not leave these comment in the file) changed line CONFIG_USBIP_VHCI_NR_HCS=10 (1=default) saved

I made the modules

  make --directory="$srcDir" M=drivers/usb/usbip/ 

I packaged it for the system

 xz "the long path down"/usb/usbip/ *.ko 

I moved the files to the current kernel location

 sudo cp -r "the long path down"/usb/usbip/*xz /"path to current running kernel"/usb/usbip/ 

unloaded the current module and attempted to install the new

sudo modprobe -r vhci_hcd sudo modprobe vhci_hcd modprobe: ERROR: could not insert ‘vhci_hcd’: Exec format error

The last error is the only error I had during the whole process
Thanks once again

I thank you for your response.
I am an Archlinux and Manjaro fan.
The outdated comment comes from you can not install the abs package any more …
no disrespect meant to the distros.
:slight_smile:

Manjaro is not Arch. :wink:

I think you need to build the whole kernel instead of just the module.
That’s what I’d do.
And then use that kernel with that module instead of a standard kernel with your own adapted module.

I never edited the config directly - I always used make menuconfig or make nconfig or make xconfig - sometimes one change in one place will effect or necessitate changes in other places and these tools take care of that. Or so I thought …