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"