2016-11-18 69 views
0

试图找出当我插入一个特定的内核模块,可以自动创建设备节点和删除该设备节点的udev规则当内核模块被删除。使用udev规则创建并在内核模块负载删除设备节点和卸载

+0

Stack Overflow是用于编程和发展问题的站点。这个问题似乎与题目无关,因为它不涉及编程或开发。请参阅帮助中心的[我可以询问哪些主题](http://stackoverflow.com/help/on-topic)。也许[超级用户](http://superuser.com/)或[Unix&Linux堆栈交换](http://unix.stackexchange.com/)会是一个更好的地方。另请参阅[我在哪里发布关于Dev Ops的问题?](http://meta.stackexchange.com/q/134306) – jww

+0

@jww,感谢您的反馈。其实我的问题并不直接涉及编程/脚本,但答案的确如此。将来,我会牢记这一点,并以形式表达它的问题,看起来不像是开发者的问题。 – aarshad

回答

0

探索udev规则详细且udevadm工具的帮助下,我能得到下面的udev规则,我的内核模块的名称是“amdtPwrProf”。

行动==“添加”创建设备节点和ACTION ==“除去”该设备节点被去除。

# Create the device file when the module is inserted. 

SUBSYSTEM=="module", ACTION=="add", KERNEL=="amdtPwrProf", RUN+="/opt/codexl/amdtPwrProf_mknod.sh" 


# Remove the device file when the module is removed. 

SUBSYSTEM=="module", ACTION=="remove", KERNEL=="amdtPwrProf", RUN+="/bin/rm /dev/amdtPwrProf" 

脚本 “amdtPwrProf_mknod.sh” 的内容,

mknod /dev/amdtPwrProf -m 666 c `cat /proc/amdtPwrProf/device` 0 
0

你必须学会​​如何工作的udev

尝试添加脚本:

cat >/path/to/myscript <<"eof" 
#!/bin/sh 

newfile=`mktemp /tmp/udev-test-XXXXXXXXXX` 
echo "$0 -- [email protected]" >$newfile 
set >>$newfile 
eof 
chmod +x /path/to/myscript 

然后(根)

echo >/etc/udev/rules.d/99-myscript.rules 'RUN+="/path/to/myscript"' 

service udev restart 

然后尝试添加/删除设备,并期待在/tmp/udev-test-*

...读man udev,看在其他文件并通过细化您的个人规则来创建您自己的脚本。

+0

感谢您的评论,是的,我已经了解了udev和udev规则的基本知识,但主要是想解决特定的场景。在深入挖掘后能够找到解决方案。 – aarshad