Score:0

Cannot insert module via 'sudo insmod ' on Ubuntu 20.04.3 LTS

cn flag

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?

Bodo avatar
pt flag
Where is the file `linux_module.ko`? Did you install the kernel module file to `/lib/modules/5.11.0-41-generic`? See https://www.kernel.org/doc/html/latest/kbuild/modules.html
cn flag
The `linux_module.ko` is in the same directory as the `linux_module.c` and `Makefile` under `/home/soberflow/Documents/BS/KernelModule/LinuxModule/` I havent installed the kernel module file at all, but I could try that, I guess. The only weird thing is the other two friends didnt need to do that step, if that is my problem. But I will try it regardless, thank you.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.