|
本帖最后由 tomery 于 2017-8-8 18:59 编辑
这是Openwrt官网提供的自动挂载USB外设磁盘的脚本代码,已经是最新稳定的,保存代码命名为10-mount,需要安装blkid和hdparm,存放路径/etc/hotplug.d/block/10-mount
- #!/bin/sh
- # Copyright (C) 2015 OpenWrt.org
- # 0 yes blockdevice handles this - 1 no it is not there
- blkdev=`dirname $DEVPATH`
- basename=`basename $blkdev`
- device=`basename $DEVPATH`
- skip=`block info | sed 's/\(.*\): .*/\1/' | grep -q $device ; echo $?`
- path=$DEVPATH
- if [ $basename != "block" ] && [ -z "${device##sd*}" ] && [ $skip -eq 1 ]; then
- islabel=`blkid /dev/$device | grep -q LABEL ; echo $?`
- if [ $islabel -eq 0 ] ; then
- mntpnt=`blkid /dev/$device |sed 's/.*LABEL="\(.*\)" UUID.*/\1/'`
- else
- mntpnt=$device
- fi
- case "$ACTION" in
- add)
- mkdir -p /export/$mntpnt
- # Set APM value for automatic spin down
- /sbin/hdparm -B 127 /dev/$device
- # Try to be gentle on solid state devices
- mount -o rw,noatime,discard /dev/$device /export/$mntpnt
- ;;
- remove)
- # Once the device is removed, the /dev entry disappear. We need mountpoint
- mountpoint=`mount |grep /dev/$device | sed 's/.* on \(.*\) type.*/\1/'`
- umount -l $mountpoint
- ;;
- esac
- fi
复制代码
|
|