I have a simple linux module that I want to build and insert into the kernel, but having some trouble on the 'sudo insmod <module_name>' part.
Ubuntu is running on a Win10 host via VirtualBox.
Two other friends did the same steps and it worked for them.
One has the kernel version 5.11.0-40 while the other has the same as me, 5.11.0-41.
The module 'linux_module.c' looks like this:
#include <linux/kernel.h>
#include <linux/module.h>
MODULE_LICENSE("GPL");
__init int init_module(void)
{
printk (KERN_INFO "Hello world from linux_module\n");
return 0;
}
__exit void cleanup_module(void)
{
}
The Makefile:
obj-m =
obj-m += linux_module.o
KVERSION = $(shell uname -r)
modules all:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean
Using 'make all' returns me this:
make -C /lib/modules/5.11.0-41-generic/build M=/home/soberflow/Documents/BS/KernelModule/LinuxModule modules
make[1]: Entering directory '/usr/src/linux-headers-5.11.0-41-generic'
CC [M] /home/soberflow/Documents/BS/KernelModule/LinuxModule/linux_module.o
MODPOST /home/soberflow/Documents/BS/KernelModule/LinuxModule/Module.symvers
CC [M] /home/soberflow/Documents/BS/KernelModule/LinuxModule/linux_module.mod.o
LD [M] /home/soberflow/Documents/BS/KernelModule/LinuxModule/linux_module.ko
make[1]: Leaving directory '/usr/src/linux-headers-5.11.0-41-generic'
Im getting the following error:
insmod: ERROR: could not insert module linux_module.ko: Invalid module format
With 'modprobe <module_name>' it says the following:
modprobe: FATAL: Module linux_module.ko not found in directory /lib/modules/5.11.0-41-generic
Does anyone have an idea what the issue could be?