udev 自動掛載U盤 轉發
一.前提系統已經裝載過udev應用
2.新增udev的支援
(1)首先建立這個目錄
/bin/udevd
/bin/udevstart
(2)修改etc/init.d/rcS指令碼,然後新增如下命令:
/bin/mount -t sysfs sysfs /sys
/bin/mount -t tmpfs tmpfs /dev
/bin/udevd --daemON
/bin/udevstart
重新啟動系統後,我們的檔案系統就有了自動建立節點的功能了。
二、自動掛載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=".
udev_log="err"
4.在rules.d下建立規則檔案
如實現U盤自動掛載
vi 11-add-usb.rules
新增如下內容
ACTION!="add",GOTO="farsight"
KERNEL=="sd[a-z][0-9]",RUN+="/sbin/mount-usb.sh %k"
LABEL="farsight"
這個檔案中ACTION後是說明是什麼事件,KERNEL後是說明是什麼裝置比如sda1,mmcblk0p1等,RUN這個裝置插進後往執行哪個程式%k是傳進這個程式的引數,這裡%k=KERNEL的值也就是sda1等。
在/sbin/下建立mount-usb.sh檔案新增如下內容
#!/bin/sh
/bin/mount -t vfat /dev/$1 /tmp
sync
修改檔案許可權為其新增可執行的許可權。
這樣就實現了U盤的自動掛載,下面附上U盤的解除安裝規則檔案和sd卡的檔案
Usb解除安裝
11-add-remove.rules
ACTION !="remove",GOTO="farsight"
SUBSYSTEM!="block",GOTO="farsight"
KERNEL=="sd[a-z][0-9]",RUN+="/sbin/umount-usb.sh"
LABEL="farsight"
umount-usb.sh
#!/bin/sh
sync
umount /tmp/
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 /tmp
Sync
SD卡解除安裝
ACTION !="remove",GOTO="farsight"
SUBSYSTEM!="block",GOTO="farsight"
KERNEL=="mmcblk[0-9]p[0-9]",RUN+="/sbin/umount-sd.sh"
LABEL="farsight"
umount-sd.sh
#!/bin/sh
sync
umount /tmp/