树莓派 挂载U盘


sudo vi /etc/udev/rules.d/10-usbstorage.rules
保存以下代码, pi可以自动挂在U盘到 /media 目录下
--------------------------------------------------------------------------------

KERNEL!="sd*", GOTO="media_by_label_auto_mount_end"
SUBSYSTEM!="block",GOTO="media_by_label_auto_mount_end"
IMPORT{program}="/sbin/blkid -o udev -p %N"
ENV{ID_FS_TYPE}=="", GOTO="media_by_label_auto_mount_end"
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="Untitled-%k"
ACTION=="add", ENV{mount_options}="relatime,sync"
ACTION=="add", ENV{ID_FS_TYPE}=="vfat", ENV{mount_options}="iocharset=utf8,umask=000"
ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", ENV{mount_options}="iocharset=utf8,umask=000"
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"

ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"
LABEL="media_by_label_auto_mount_end"  

 


-------------------------------------------------------------------------------------

手动挂载/卸载 U盘
==========================================
1, cat /proc/partitions
查看U盘插入前后, 多出的 sd* 分区, 既是插入的U盘

2,  sudo fdisk -l /dev/sdb

输出类似

Disk /dev/sdb: 15.2 GiB, 16357785600 bytes, 31948800 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x9bbd9bbd

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sdb1  *    1142528 31948799 30806272 14.7G  7 HPFS/NTFS/exFAT


第一行,表示一块硬盘/U盘设备
最后一行, 表示这个设备有一个分区 /dev/sdb1,  即我们的U盘可用的分区内容了

3, 建立要挂载到的目录, 如:  /mnt/usb  如果没有需建立

4, 挂载U盘
sudo mount -t vfat /dev/sdb1 /mnt/usb

5, 卸载U盘
sudo umount /mnt/usb

posted @ 2016-12-05 10:42  青松梧桐  阅读(3336)  评论(0编辑  收藏  举报