Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1336800
  • 博文数量: 198
  • 博客积分: 1629
  • 博客等级: 上尉
  • 技术积分: 2743
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-01 15:41
文章分类
文章存档

2023年(6)

2022年(20)

2021年(8)

2020年(3)

2018年(17)

2017年(3)

2016年(3)

2015年(9)

2014年(13)

2013年(17)

2012年(77)

2011年(22)

分类: LINUX

2015-10-10 16:36:48

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


阅读(8861) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~