1.多分区U盘和普通U盘区别
2.接下来重新修改/etc/mdev.conf文件
sd[a-z] 0:0 660 * if [ $ACTION = "add" ]; then /etc/hotplug/usb/udisk_insert.sh; else /etc/hotplug/usb/udisk_remove.sh; fi
sd[a-z][1-9]+ 0:0 660 * if [ $ACTION = "add" ]; then /etc/hotplug/usb/udisk_insert1.sh; else /etc/hotplug/usb/udisk_remove.sh; fi
上面表示:
3.添加/etc/hotplug/usb/udisk_insert.sh文件
#!/bin/sh
MOUNT_POINT=/mnt/usbdisk
if [ ! -f $MDEV ]; then
if [ ! -d $MOUNT_POINT ]; then #判断挂载目录是否存在
mkdir -p $MOUNT_POINT
fi
echo "${MDEV} usb insert"
sleep 0.5 #延时500ms,判断一下是否有sda1,如果没有,则表示没有分区
if [! -e "/dev/sda1"]; then #如果有/dev/sda1,则属于多分区U盘,所以不需要再挂载/dev/sda了
echo " ${MDEV} don't have to create " > /dev/console
exit
fi
echo "create usb disk mount point: $MOUNT_POINT." > /dev/console
mount -t vfat,exfat,ntfs /dev/$MDEV $MOUNT_POINT
if [ $? -ne 0 ]; then
echo "mount usb disk ${MDEV} falied!" > /dev/console
else
echo "mount usb disk successfully!" > /dev/console
fi
fi
注意: 由于/dev/sda文件最先创建,所以上面需要延时500ms后,判断是否有/dev/sda1,来区别是否是多分区
4.添加/etc/hotplug/usb/udisk_insert1.sh文件
#!/bin/sh
POINT_SOURCE=/mnt/usbdisk
num=${MDEV#*sda} #获取sda后缀数字
MOUNT_POINT=${POINT_SOURCE}${num}
if [ ! -f $MDEV ]; then
if [ ! -d $MOUNT_POINT ]; then
mkdir -p $MOUNT_POINT
fi
echo "${MDEV} usb insert1"
echo "create usb disk mount point: $MOUNT_POINT." > /dev/console
mount -t vfat,exfat,ntfs /dev/$MDEV $MOUNT_POINT
if [ $? -ne 0 ]; then
echo "mount usb disk ${MDEV} falied!" > /dev/console
else
echo "mount usb disk successfully!" > /dev/console
fi
fi
5.添加/etc/hotplug/usb/udisk_remove.sh文件
#!/bin/sh
POINT_SOURCE=/mnt/usbdisk
num=${MDEV#*sda}
MOUNT_POINT=${POINT_SOURCE}${num}
umount $MOUNT_POINT
if [ $? -ne 0 ]; then
echo "umount usb disk falied! ${MDEV} " > /dev/console
else
echo "umount usb disk successfully!" > /dev/console
fi
rm -rf $MOUNT_POINT
echo "remove usb disk mount point: $MOUNT_POINT." > /dev/console