菜鸟求助,如何设置openwrt的优盘热插拔自动挂载
如题,现在优盘插入有信息提示,也可以手动挂载成功,现在想让它插入后自动挂载,求大神提点!直接贴代码吧
编辑/etc/hotplug.d/block/10-mount(用winscp工具连接路由,编辑文件)
___________________________以下是文件内容_________________________________
#!/bin/sh
# Copyright (C) 2009 OpenWrt.org(C) 2010 OpenWrt.org.cn
blkdev=`dirname $DEVPATH`
if [ `basename $blkdev` != "block" ]; then
device=`basename $DEVPATH`
case "$ACTION" in
add)
mkdir -p /mnt/$device
# vfat & ntfs-3g check
if[ `which fdisk` ]; then
isntfs=`fdisk -l | grep $device | grep NTFS`
isvfat=`fdisk -l | grep $device | grep FAT`
isfuse=`lsmod | grep fuse`
isntfs3g=`which ntfs-3g`
else
isntfs=""
isvfat=""
fi
# mount with ntfs-3g if possible, else with default mount
if [ "$isntfs" -a "$isfuse" -a "$isntfs3g" ]; then
ntfs-3g -o nls=utf8 /dev/$device /mnt/$device
elif [ "$isvfat" ]; then
mount -t vfat -o iocharset=utf8,rw,sync,umask=0000,dmask=0000,fmask=0000 /dev/$device /mnt/$device
else
mount /dev/$device /mnt/$device
fi
if [ -f /dev/${device}/swapfile ]; then
mkswap /dev/${device}/swapfile
swapon /dev/${device}/swapfile
fi
;;
remove)
if [ -f /dev/${device}/swapfile ]; then
swapoff /dev/${device}/swapfile
fi
umount /dev/$device
;;
esac
fi hongyancl 发表于 2017-11-5 21:40
直接贴代码吧
编辑/etc/hotplug.d/block/10-mount(用winscp工具连接路由,编辑文件)
我的系统原先没有block文件夹,我新建了这个文件夹,新建了10-mount文件,复制了你的,也chmod 777了,然而还是失败了
好像插入优盘的时候并没有运行这个脚本 再顶一下 hongyancl 发表于 2017-11-5 21:40
直接贴代码吧
编辑/etc/hotplug.d/block/10-mount(用winscp工具连接路由,编辑文件)
谢谢你的脚本,普通优盘,sd卡,读卡器可以自动挂载了
但是我自己拿nuc442做的一个优盘却不可以自动挂载(手动可以),是否跟我的名字有关,在/dev/文件夹下叫sda
另外增加了一个脚本,达到想要的目的了:
#!/bin/ash
case "$ACTION" in
add)
for i in $(ls /dev/ | grep 'sd')
do
mkdir -p /www/mnt/$i
mount /dev/$i /www/mnt/$i
done
;;
remove)
for i in $(mount | grep -o '/www/mnt/sd')
do
umount $i
if [ $? -eq 0 ]
then
rm -r $i
fi
done
;;
esac
页:
[1]