打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
UDEV实现自动挂载

  1、开启/etc/rc.d/init.d/udev 服务
/etc/rc.d/rc.conf 文件cfg_services 中增加udev。
2、自动挂载U盘或SD卡

1)在/etc下创建udev目录
2)在/etc/udev下穿件目录rules.d和文件udev.conf
3)在udev.conf中添加如下内容
# udev.conf

# The initial syslog(3) priority: "err", "info", "debug" or its
# numerical equivalent. For runtime debugging, the daemons internal
# state can be changed with: "udevcontrol log_priority=<value>".
udev_log="err"

4)在rules.d下创建规则文件
如实现U盘自动挂载
vim /etc/udev/rules.d/11-add-usb.rules
添加如下内容:
ACTION!="add",GOTO="farsight"
KERNEL=="sd[a-z][0-9]",RUN+="/home/mountusb.sh %k"
KERNEL=="sd[a-z]",RUN+="/home/mountusb.sh %k"
LABEL="farsight"

这个文件中ACTION后是说明是什么事件,KERNEL后是说明是什么设备比如sda1,mmcblk0p1等,RUN这个设备插入后去执行哪个程序%k是传入这个程序的参数,这里%k=KERNEL的值也就是sda1等

在/home/下创建mountusb.sh文件添加如下内容:
#!/bin/sh
mount  -t vfat /dev/$1 /mnt/usb
sync

修改文件权限为其添加可执行的权限。
这样就实现了U盘的自动挂载,下面附上U盘的卸载规则文件和sd卡的文件

Usb卸载
vim etc/udev/rules.d/11-add-remove.rules

ACTION !="remove",GOTO="farsight"
SUBSYSTEM!="block",GOTO="farsight"
KERNEL=="sd[a-z][0-9]",RUN+="/home/umount-usb.sh"
LABEL="farsight"

umount-usb.sh
#!/bin/sh
sync
umount /mnt/usb

SD卡挂载
ACTION!='add',GOTO='farsight'
KERNEL=='mmcblk[0-9]p[0-9]',RUN+='/sbin/mount-sd.sh %k'
LABEL='farsight'

mount-sd.sh
#!/bin/sh
/bin/mount -t vfat /dev/$1 /mnt/sd
sync

SD卡卸载
ACTION !='remove',GOTO='farsight'
SUBSYSTEM!='block',GOTO='farsight'
KERNEL=='mmcblk[0-9]p[0-9]',RUN+='/home/umount-sd.sh'
LABEL='farsight'

umount-sd.sh
#!/bin/sh
sync
umount /mnt/sd


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
linux udev 自动挂载 SD卡/U盘
嵌入式Linux系列第16篇:使用SD卡
嵌入式LINUX-2.6内核技术 - udev轻松上路
Linux里udev的工作原理
Linux内核Ramdisk(initrd)机制
树莓派开发系列教程5
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服