Insmod Error: Inserting './Hello.Ko': -1 Invalid Module Format"

insmod error: inserting './hello.ko': -1 Invalid module format

Kernel from which you build your kernel module and to which you are inserting module should be of same version. If you do not want to take care of this thing you can use following Makefile.

obj−m += hello−world.o

all:
make −C /lib/modules/$(shell uname −r)/build M=$(PWD) modules
clean:
make −C /lib/modules/$(shell uname −r)/build M=$(PWD) clean

Now you can build and try to insert module.

I suggest you to become root if possible before this line

$sudo cp /boot/config-2.6.38-8-generic ./.config

$su
#cp /boot/config-2.6.38-8-generic ./.config
#insmod hello_world.ko

Alternatively you can also use following make file

TARGET  := hello-world
WARN := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
INCLUDE := -isystem /lib/modules/`uname -r`/build/include
CFLAGS := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
CC := gcc-3.0

${TARGET}.o: ${TARGET}.c

.PHONY: clean

clean:
rm -rf ${TARGET}.o

insmod error, invalid module format, fedora 35

This post set me on the right path and might help others not using fedora
Linux Kernel Module Development "module: x86/modules: Skipping invalid relocation target, existing value is nonzero for type 1"

The issue was with the kernel headers, as always the problem was solved with the reliable uninstall and reinstall:

sudo dnf remove kernel-devel
sudo dnf install kernel-devel

insmod: 'error ... invalid module format' - cross compilation usage

found the problem.
Thought I was using the correct Kernel compilation but - as implied @Tsyvarev, i took the other Kernel version all this time. :-)

insmod: ERROR: could not insert module HelloWorld.ko: Operation not permitted

So I had the same problem and this worked for me:

  1. You need to disable Secure Boot using mokutil use the first answer in this link

  2. Run the insmod command via sudo.

Good Luck.



Related Topics



Leave a reply



Submit