编译hello驱动时,能够使用insmod加载进去,但rmmod时却无法卸载。
大家都知道的hello驱动:
1 #include <linux/module.h>
2 #include <linux/init.h>
3 MODULE_LICENSE("GPL");
4 static int __init hello_init (void)
5 {
6 printk("Hello module init\n");
7 return 0;
8 }
9
10 static void __exit hello_exit (void)
11 {
12 printk("Hello module exit\n");
13 }
14
15 module_init(hello_init);
16 module_exit(hello_exit);
在经过内核编译等步骤结束后,使用sudo insmod XXX/hello.ko 时可以正常加载,通过输入dmesg命令可以看到log信息(如红色字体所示):
[ 18.765265] init: plymouth-stop pre-start process (1277) terminated with status 1
[ 20.250274] EXT4-fs (sda10): re-mounted. Opts: errors=remount-ro,commit=0
[ 203.420799] Hello module init
然后使用:sudo rmmod hello时却遇到下面的错误:
ERROR: Removing 'hello': Device or resource busy
在网上搜索后,通过重启电脑后自动卸载这个hello驱动程序,这一点我们可以理解,因为insmod是临时加载的,不是永久加载。但是我们不能总是重启电脑去解决这个问题。
有网友说在make menuconfig时把Enable loadable module support选项选中,这个我也选中了,并且保存退出了,但是经过编译后使用rmmod命令还是出现这个错误。
也有网友说,使用这个命令:
rmmod -f hello
或者:
rmmod -- force hello
但是都没用。
也有网友说是设备号什么问题,但是也没有说清楚,所以也看不懂。
请高手指点。