2.6的LKM加载机制和2.4有些区别。下面是我的第一个LKM
/*hello.c*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
static int hello_init(void) {
printk(KERN_ALERT"Hello, world!/n");
return 1;
}
static void hello_exit(void) {
printk(KERN_ALERT"Goodbye!/n");
}
module_init(hello_init);
module_exit(hello_exit);
/*makefile*/
obj-m = hello.o
all:
make -C /lib/modules/'uname -r'/build M=$(PWD) modules
clean:
rm *.o *.ko
注意makefile中的两个tab键
编译成功后,加载模块
insmod hello.ko
卸载
rmmod hello.ko
# tail /var/log/messages
"Hello world"
"Goodbye"