加载驱动模块时Device or resource busy的解决方法

加载驱动模块时Device or resource busy的解决方法

加载驱动模块时Device or resource busy的解决方法
insmod或modprobe驱动模块时Device or resource busy的解决方法

在编译好memdev驱动模块后,通过insmod加载模块时发现以下错误提示:
#insmod memdev.ko
insmod: error inserting 'memdev.ko': -1 Device or resource busy


这种情况一般都是驱动的设备号已经被系统使用了。
我回头查看memdev模块的主设备号,我定义的是254,然后查看系统设备列表。
#cat /proc/devices
Character devices:
1 mem
2 pty
3 ttyp
4 /dev/vc/0
4 tty
4 ttyS
5 /dev/tty
5 /dev/console
5 /dev/ptmx
6 lp
7 vcs
10 misc
13 input
21 sg
29 fb
128 ptm
136 pts
180 usb
189 usb_device
254 vmci

Block devices:
1 ramdisk
2 fd
7 loop
8 sd
9 md
22 ide1
65 sd
66 sd
67 sd
68 sd
69 sd
70 sd
71 sd
128 sd
129 sd
130 sd
131 sd
132 sd
133 sd
134 sd
135 sd
253 device-mapper
254 mdp

此时发现字符设别驱动的254已经被使用了。

解决方法:更换一个上表未使用的的主设备号,或者直接让系统自动分配。
-----------------------------------------------------------------------------------------

另外值得注意的是,编译内核模块的时候,必须有一个已经配置好并编译过的内核源代码树。否则会出现以下错误:
  Building modules, stage 2.
/xxx/linux-2.6.29/scripts/Makefile.modpost:43: include/config/auto.conf: No such file or directory
make[2]: *** No rule to make target 'include/config/auto.conf'.
make[1]: *** [modules] Error 2
make[1]: Leaving directory '/xxx/linux-2.6.29'
make: *** [all] Error 2

解决方法:先配置编译内核源代码树,然后再编译内核模块或者驱动模块。

 

 

 

 

 

 

 

 

 

 

一:insmod时候错误:

1:错误信息insmod: error inserting 'hello.ko': -1 Device or resource busy

2:原因:你的代码里面的设备号和系统已经存在的相冲突

3:查看系统的设备号:

cat /proc/devices 

 查看和你的设备号有冲突的吗,注意要分开字符设备和块设备

4:解决,当然是你再换个设备号了。

二:rmmod

0:用rmmod -f也删除不掉的

1:查看当前gcc版本,命令:gcc  -v

2:ubuntu默认版本是4.6

3:如果你的不是4.6版本,修改成4.6,在目录/usr/bin下,建立软链接,

  我之前的gcc是软链接到gcc-4.4版本了,修改成gcc-4.6版本,如果之前存在gcc的软链接,删除他

sudo ln -s /usr/bin/gcc-4.6  /usr/bin/gcc

4:重新insmod模块,如果提示你模块已经存在,就是说你没修改之前安装的模块,你需要重启电脑,然后再insmod就可以了。

posted @ 2016-04-08 15:27  OracleLoyal  阅读(8226)  评论(0编辑  收藏  举报