1.源文件 helloworld.c
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
static int hello_init(void)
{
printk("Hello! This is the helloworld module!\n");
return 0;
}
static void hello_exit(void)
{
printk("Module helloworld exit!\n");
return;
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
2.文件 Makefile
obj-m := helloworld.o
clean:
rm -rf *.o *.ko *.mod.c .tmp_versions modules* Module*
3、执行命令
make -C /lib/modules/`uname -r`/build M=$(pwd) modules
生成helloworld.ko文件
4、内核插入模块
insmod helloworld.ko
dmesg | tail
6、查看当前内核加载模块
lsmod | grep hello
7、移除模块
rmmod helloworld
查看 dmesg | tail