创建文件/etc/udev/rules.d/11-add-usb.rules
# SD卡自动挂载
ACTION=="add",GOTO="farsight", KERNEL=="mmcblk[0-9]p[0-9]", RUN+="/etc/mount-sd.sh %k", LABEL="farsight"
# U盘自动挂载
ACTION=="add",GOTO="farsight",KERNEL=="sd[a-z][0-9]",RUN+="/etc/mount-usb.sh %k",LABEL="farsight"
#U盘测试之后挂载方式
ACTION=="add",KERNEL=="sd[a-z][0-9]",RUN+="/etc/mount-usb.sh %k",LABEL="farsight"
/etc/udev/rules.d/11-add-remove.rules
# 卸载SD卡
ACTION=="remove",GOTO="farsight", SUBSYSTEM=="block",GOTO="farsight", KERNEL=="mmcblk[0-9]p[0-9]",RUN+="/etc/umount-sd.sh", LABEL="farsight"
# 卸载U盘
ACTION=="remove",GOTO="farsight",SUBSYSTEM=="block",GOTO="farsight",KERNEL=="sd[a-z][0-9]",RUN+="/etc/umount-usb.sh",LABEL="farsight"
#U盘测试之后卸载U盘方式
ACTION=="remove",SUBSYSTEM=="block",KERNEL=="sd[a-z][0-9]",RUN+="/etc/umount-usb.sh",LABEL="farsight"
mkdir /mnt/sd -p
mkdir /mnt/usb -p
创建脚本/etc/mount-sd.sh
#!/bin/sh
/bin/mount -t vfat /dev/$1 /mnt/sd
sync
添加可执行权限
chmod +x /etc/mount-sd.sh
创建/etc/umount-sd.sh
#!/bin/sh
sync
umount /mnt/sd
添加可执行权限
chmod +x /etc/umount-sd.sh
创建/etc/mount-usb.sh
#!/bin/sh
mkdir /mnt/usb
mount -t vfat /dev/$1 /mnt/usb
sync
chmod +x /etc/mount-usb.sh //执行权限
创建/etc/umount-usb.sh
#!/bin/sh
sync
umount /mnt/usb
rm -rf /mnt/usb
chmod +x /etc/umount-usb.sh //执行权限
1.原因:直接将sda进行格式化,正常情况是对sda1设备节点进行格式化
解决HISI单板U盘可以识别,但是/dev下只有sda,没有设备路由(sda1)
解决方案->(下列是Xshell中命令操作) (电脑端格式化一下可能也是可以的)
//查看U盘是否分区
#fdisk /dev/sda //进入fdisk命令操作空间
#Command(m for help): m
a toggle a bootable flag #设置引导扇区
b edit bsd disklabel #编辑卷标
c toggle the dos compatibility flag
d delete a partition #删除分区
l list known partition types #列出已知的分支类型
n add a new partition #添加一个新的分区
o create a new empty DOS partition table #生成一个新的空DOS分区列表
p print the partition table #打印分区信息
q quit without saving changes #不保存退出
s create a new empty Sun disklabel
t change a partition's system id #改变一个分区列表的ID
u change display/entry units
v verify the partition table
w write table to disk and exit #写入列表到磁盘并退出
x extra functionality (experts only)
#Command (m for help): p
Disk /dev/sda: 4090 MB, 4090494976 bytes
126 heads, 62 sectors/track, 1022 cylinders
Units = cylinders of 7812 * 512 = 3999744 bytes
Device Boot Start End Blocks Id System #可见U盘无分区
##--->(如果没有分区,创建分区sda1, 并格式化[也可以不进行格式化])
#Command (m for help): m
Command Action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
#Command (m for help): n #添加一个新的分区
Command action
e extended #创建扩展分区
p primary partition (1-4) #创建主分区
p
#Partition number (1-4): 1 #输入主分区号 这里设置为1
#Using default value 1 #起始,回车使用默认
Last cylinder or +size or +sizeM or +sizeK (1-1022, default 1022): Using default value 1022
#Command (m for help): p #打印分区列表
Disk /dev/sda: 4090 MB, 4090494976 bytes
126 heads, 62 sectors/track, 1022 cylinders
Units = cylinders of 7812 * 512 = 3999744 bytes
Device Boot Start End Blocks Id Syste #sda1分区创建
/dev/sda1 1 1022 3991901 83 Linux
#Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table
# mkfs.vfat /dev/sda1 #sda1进行格式化
####--->前面的全部执行完,在/dev目录下将会出现可用sda1;如果没有手动创建sda1
# mknod /dev/sda1 b 8 1 #手动创建设备节点sda1
mknod: /dev/sda1: File exists
# mount /dev/sda1 /root/usb/
# umount /root/usb/
//插拔U盘
PS: 解决/dev目录下只有sda
2.原因:通过mkfs.vfat /dev/sda1格式化U盘
问题:ls: ./System Volume Information: Input/output error
解决方案:–>
在电脑上重新进行格式化之后,再次插入HISI单板上会出现System Volume Information文件夹
System Volume Information文件夹最终发现是Windows文件夹,只要插入WIN10系统,就会出现此文件夹
系统命令处理
umount /root/usb #取消挂载
mkfs.vfat /dev/sda1 #sda1进行格式化(千万不能格式sda,会出现设备节点清除问题)
#->直接进行硬件重启即可 -->加入文件重新插拔也是可以的
测试1 : 取消挂载 - 进行格式化 - 插拔U盘 (盘中没有SVI文件夹) ->[重新插拔 放入UI文件还是没有]
发现 需要产生 SVI文件就必须在电脑上进行一次插拔
需要实测--------------------->** 实测失败
Nov 12 10:06:24 udevd[79]: GOTO 'farsight' has no matching label in: '/etc/udev/rules.d/11-add-remove.rules'
Nov 12 10:06:24 udevd[79]: unknown key 'CTION' in /etc/udev/rules.d/11-add-usb.rules:1
Nov 12 10:06:24 udevd[79]: GOTO 'farsight' has no matching label in: '/etc/udev/rules.d/11-add-usb.rules'
解答:除去所有的GOTO部分,在CTION 前面加入 “ACTION”;