当前位置: 技术问答>linux和unix
嵌入式下USB或移动硬盘的自动挂载???
来源: 互联网 发布时间:2016-09-30
本文导语: USB插到板子上用mount命令可以挂载。 但是通过UDEV的规则文件和脚本挂载却找不到U盘,各位大侠有碰到类似的问题的支下招,提个思路也可以。 以下是规则文件: KERNEL=="sda1", SUBSYSTEM=="block", GROUP="users",RUN+="...
USB插到板子上用mount命令可以挂载。
但是通过UDEV的规则文件和脚本挂载却找不到U盘,各位大侠有碰到类似的问题的支下招,提个思路也可以。
以下是规则文件:
KERNEL=="sda1", SUBSYSTEM=="block", GROUP="users",RUN+="/sbin/mount.sh"
#KERNEL=="sd[a-z]", NAME="%k", SYMLINK+="usbhd-%k", GROUP="users", OPTIONS="last_rule"
#ACTION=="add", KERNEL=="sd[a-z][0-9]", SYMLINK+="usbhd-%k", GROUP="users", NAME="%k"
#ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/mkdir -p /media/usbhd-%k"
#ACTION=="add", KERNEL=="sd[b-z][0-9]", PROGRAM=="/lib/udev/vol_id -t %N", RESULT=="vfat", RUN+="/bin/mount -t vfat -o #rw,utf8=true,codepage=936,noauto,flush,quiet,nodev,nosuid,noexec,noatime,dmask=000,fmask=111 /dev/%k /media/usbhd-%k", OPTIONS="last_rule"
#ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mount -t auto -o rw /dev/sda1 /mnt/usba1", OPTIONS="last_rule"
#ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/umount -l /media/usbhd-%k"
#ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/rm -rf /media/usbhd-%k", OPTIONS="last_rule"
下面是脚本:
#!/bin/sh
TOP_DIR=/mnt
SUB_NAME=usb$(echo $1 | cut -b 3,4)
DIR_NAME=${TOP_DIR}/${SUB_NAME}
DEV_TYPE=$(fdisk -l|grep $1|grep NTFS)
EXIST_FLAG=$(df | grep $DIR_NAME)
echo $SUB_NAME >> /home/usb-hotplug.log
mkdir -p $DIR_NAME
if [ "$EXIST_FLAG" = "" ]; then
if [ "${DEV_TYPE}" = "" ]; then
echo "mount -t vfat /dev/$1 ${DIR_NAME}" >> /home/usb-hotplug.log
mount -t vfat /dev/$1 ${DIR_NAME}
else
ntfs-3g /dev/$1 ${DIR_NAME}
fi
if [ $? = 0 ]; then
echo "new disk $1 mount to ${DIR_NAME} ... ok" >> /home/usb-hotplug.log
else
# rm -rf $DIR_NAME
echo "new disk $1 mount to ${DIR_NAME} ... err (info:${DEV_TYPE}) " >> /home/usb-hotplug.log
fi
else
echo "disk $1 already mount, ignore" >> /home/usb-hotplug.log
fi
哪里有问题吗?
但是通过UDEV的规则文件和脚本挂载却找不到U盘,各位大侠有碰到类似的问题的支下招,提个思路也可以。
以下是规则文件:
KERNEL=="sda1", SUBSYSTEM=="block", GROUP="users",RUN+="/sbin/mount.sh"
#KERNEL=="sd[a-z]", NAME="%k", SYMLINK+="usbhd-%k", GROUP="users", OPTIONS="last_rule"
#ACTION=="add", KERNEL=="sd[a-z][0-9]", SYMLINK+="usbhd-%k", GROUP="users", NAME="%k"
#ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/mkdir -p /media/usbhd-%k"
#ACTION=="add", KERNEL=="sd[b-z][0-9]", PROGRAM=="/lib/udev/vol_id -t %N", RESULT=="vfat", RUN+="/bin/mount -t vfat -o #rw,utf8=true,codepage=936,noauto,flush,quiet,nodev,nosuid,noexec,noatime,dmask=000,fmask=111 /dev/%k /media/usbhd-%k", OPTIONS="last_rule"
#ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mount -t auto -o rw /dev/sda1 /mnt/usba1", OPTIONS="last_rule"
#ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/umount -l /media/usbhd-%k"
#ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/rm -rf /media/usbhd-%k", OPTIONS="last_rule"
下面是脚本:
#!/bin/sh
TOP_DIR=/mnt
SUB_NAME=usb$(echo $1 | cut -b 3,4)
DIR_NAME=${TOP_DIR}/${SUB_NAME}
DEV_TYPE=$(fdisk -l|grep $1|grep NTFS)
EXIST_FLAG=$(df | grep $DIR_NAME)
echo $SUB_NAME >> /home/usb-hotplug.log
mkdir -p $DIR_NAME
if [ "$EXIST_FLAG" = "" ]; then
if [ "${DEV_TYPE}" = "" ]; then
echo "mount -t vfat /dev/$1 ${DIR_NAME}" >> /home/usb-hotplug.log
mount -t vfat /dev/$1 ${DIR_NAME}
else
ntfs-3g /dev/$1 ${DIR_NAME}
fi
if [ $? = 0 ]; then
echo "new disk $1 mount to ${DIR_NAME} ... ok" >> /home/usb-hotplug.log
else
# rm -rf $DIR_NAME
echo "new disk $1 mount to ${DIR_NAME} ... err (info:${DEV_TYPE}) " >> /home/usb-hotplug.log
fi
else
echo "disk $1 already mount, ignore" >> /home/usb-hotplug.log
fi
哪里有问题吗?
|
insmod [drivername]
|
学 习