OS: Windows 11, WSL2(Ubuntu 22.04)
inside WSL2, command uname -r
returns: 5.15.90.1-microsoft-standard-WSL2
Firstly, I dowloaded the correct version of Linux kernel from Github: WSL2-Linux-Kernel. Then I compiled and installed it, and created a soft link from /lib/modules to /usr/src with this command:
sudo ln -s /lib/modules/5.15.90.1-microsoft-standard-WSL2 /usr/src/5.15.90.1-microsoft-standard-WSL2
I wrote a custom kernel module with C: hello.c
, with a Makefile like below:
obj-m := hello.oall:make -C /usr/src/`uname -r` M=$PWD modulesclean:make -C /usr/src/`uname -r` M=$PWD clean
inside the same path of hello.c
, I use this command to build the hello.ko
file:
make -C /usr/src/`uname -r`/build M=$PWD
And then the hello.ko
file was successfully generated. But when I ran the command insmod hello.ko
it threw an error like this:
insmod: ERROR: could not insert module hello.ko: Invalid module format
How to fix it?