|
现在有个sd卡需要自动挂载到系统的/media/usb-sd*下面,正常卸载的情况下可以通过脚本自动删除/media下的目录,但是直接拔掉sd卡的时候却没有调用脚本删除/media下的目录,而且用mount命令发现sd卡设备还是挂载的状态,没有调用相应的卸载脚本。
写了下面的udev规则,不知道怎么搞了,有明白的指点下:
udev规则 90-vfat.rules
- KERNEL!="sd[b-z]*", GOTO="media_by_label_auto_mount_end"
- # Import FS infos
- IMPORT{program}="/sbin/blkid -o udev -p %N"
- #IMPORT{program}="/user/bin/env"
- #
- # # Get a label if present, otherwise specify one
- #ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
- #ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"
- ENV{dir_name}="usb-%k"
- #ENV{dir_name}="ntfs"
- ENV{DISPLAY}=":0.0"
- #
- #
- # # Global mount options
- #ACTION=="add", ENV{mount_options}="relatime"
- # # Filesystem-specific mount options
- ACTION=="add", ENV{ID_FS_TYPE}=="vfat", RUN+="/bin/vfat-in.sh %k %E{dir_name}"
- #
- # # Mount the device
- #
- # # Clean up after removal
- ACTION=="remove", ENV{ID_FS_TYPE}=="vfat",RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rm -fr /media/%E{dir_name}", RUN+="/bin/vfat-out.sh %E{dir_name}"
- #
- # # Exit
- LABEL="media_by_label_auto_mount_end"
- #
复制代码
vfat-in.sh
- #!/bin/bash
- LOCKFILE=/tmp/$2.lock
- export LANG=zh_CN.UTF-8
- export LANGUAGE=zh_CN.UTF-8
- if [ -e $LOCKFILE ]; then
- exit 1;
- else
- /bin/touch $LOCKFILE
- /bin/mkdir -p /media/$2
- /bin/mount -o iocharset=utf8 /dev/$1 /media/$2
- if [ $? = 0 ]; then
- /usr/bin/nautilus --no-desktop /media/$2 &
- sleep 2
- /bin/dbus-send --system --type=signal /com/example/msg com.example.msg.msg_signal string:'in' string:'usb'
- else
- rm -fr /media/$2
- rm -fr $LOCKFILE
- exit 1;
- fi
- fi
复制代码
vfat-out.sh
- #!/bin/bash
- LOCKFILE=/tmp/$1.lock
- if [ -e $LOCKFILE ]; then
- rm -fr $LOCKFILE
- /bin/dbus-send --system --type=signal /com/example/msg com.example.msg.msg_signal string:'out' string:'usb'
- fi
复制代码 |
|