开发者

How to build a kernel module

I am trying to compile a hello world module given over here

I have followed the following step.

  1. Downloaded Linux kernel 2.6.35-rc5
  2. extracted to directory /general/source/linux
  3. Complied the entire kernel.
  4. created a dir test in the linux folder.
  5. Created and complied a hello world module as mentioned there.

when I run the insmod command, I get开发者_如何学Python this error

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

How do I sort out this error?

Regards,


Ok the mistake that you are making is the kernel version.

First try

uname -r 

You would get the kernel version. The downloaded version mostly likely won't be the kernel version of your system. So change the make file to

ifeq ($(KERNELRELEASE),)

KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

.PHONY: build clean

build:
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

clean:
        rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c
else

$(info Building with KERNELRELEASE = ${KERNELRELEASE})
obj-m :=    hello.o

endif

Make sure the tabs are in the order as mentioned in the above script.


Your kernel module must match the running kernel. If you want to install this specific module, for example, you'd need to also install the kernel that you've built.

Normally, you'd not build the kernel on your own and use a pre-built version that matches your distribution's kernel. Look for a kernel-headers package in your distribution's repository.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜