The mothod to solve this issue is we shoud go to root dir of current used kernal source code and execute:
$ make modules_prepare
At first, you should have one linux kernal source code, and have opened "Enable Loadable module support" in Linux Kernal Configuration GUI by "$ sudo make menuconfig".
1. The source code of the module:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
MODULE_LICENSE ("GPL");
static int __init hello_2_init (void)
{
printk (KERN_INFO "Hello world\n");
return 0;
}
static void __exit hello_2_exit (void)
{
printk (KERN_INFO "Goodbye world\n");
}
module_init (hello_2_init);
module_exit (hello_2_exit);
ifeq ($(KERNELRELEASE),)
#KERNELDIR ?= /home/lht/kernel2.6/linux-2.6.14
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
.PHONY:
modules modules_install clean
else
obj-m := hello.o
endi
5. Print module output message that was saved in the kernal message stack
$ sudo dmesg -c
[12104.762170] Hello world
6. Remove the "Hello" module
$ sudo rmmod hello
$ sudo dmesg -c
[12143.629505] Goodbye world
Notes:
The mothod to solve this issue is we shoud go to root dir of current used kernal source code and execute:
$ make modules_prepare