Skip to content

Instantly share code, notes, and snippets.

@willwhui
Created December 27, 2017 13:37
Show Gist options
  • Save willwhui/001e266c35ddaae5c1924aaf4ebf6b5d to your computer and use it in GitHub Desktop.
Save willwhui/001e266c35ddaae5c1924aaf4ebf6b5d to your computer and use it in GitHub Desktop.
在树莓派3B挂接u盘(移动硬盘)
@willwhui
Copy link
Author

willwhui commented Dec 27, 2017

参见:
https://elinux.org/RPi_Adding_USB_Drives

其中需要了解当前u盘的格式,运行命令:

sudo parted -l

得到如下输出:

Model: ST310005 28AS (scsi)
Disk /dev/sda: 1000GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      32.3kB  1000GB  1000GB  primary  ntfs


Model: SD SL16G (sd/mmc)
Disk /dev/mmcblk0: 15.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      4194kB  48.0MB  43.8MB  primary  fat32        lba
 2      48.2MB  15.9GB  15.9GB  primary  ext4

插入的U盘在“Disk /dev/sda”,可见是ntfs格式的。

在开机启动时要mount,如果想要稳妥点的话,需要获取PARTUUID
运行

ls -laF /dev/disk/by-uuid/

可得如下信息:

total 0
drwxr-xr-x 2 root root 100 Dec 27 21:44 ./
drwxr-xr-x 7 root root 140 Dec 27 21:43 ../
lrwxrwxrwx 1 root root  10 Dec 27 21:44 6E2833D828339E51 -> ../../sda1
lrwxrwxrwx 1 root root  15 Dec 27 21:43 9a7608bd-5bff-4dfc-ac1d-63a956744162 -> ../../mmcblk0p2
lrwxrwxrwx 1 root root  15 Dec 27 21:43 B60A-B262 -> ../../mmcblk0p1

可知sda1的UUID是6E2833D828339E51

通过编辑fstab来增加配置

sudo vi /etc/fstab

使用这个id的时候如果增加的配置写成这样:

PARTUUID=6E2833D828339E51  /media/pi/disk1t ntfs   rw,defaults  0       0

出现了启动失败的情况,不能肯定是不是一个意外(以后再试)。
反正,把sd卡拔出后,在电脑上修改成如下,再重新启动树莓派,成功了:

proc            /proc           proc    defaults          0       0
PARTUUID=f053dca1-01  /boot           vfat    defaults          0       2
PARTUUID=f053dca1-02  /               ext4    defaults,noatime  0       1
UUID=6E2833D828339E51  /media/pi/disk1t ntfs   rw,defaults  0       0                                                           

@willwhui
Copy link
Author

willwhui commented Dec 27, 2017

然而这样配置好之后有3个问题:

  1. pi用户不能直接访问disk1t
  2. samba共享后不能从远程访问其中的共享目录
  3. 中文文件名显示为问号(放了一晚上之后可以了,估计是移动硬盘休眠之后再加载,更新了目录缓存信息的缘故)

其原因应该是:磁盘格式是SFS

SFS (Secure FileSystem) is a set of programs which create and manage a number of encrypted disk volumes, and runs under both DOS and Windows. Each volume appears as a normal DOS drive, but all data stored on it is encryped at the individual-sector level.

查看这里的资料:
https://help.ubuntu.com/community/Fstab
https://guides.github.com/features/mastering-markdown/
提到:

# NTFS ~ Use ntfs-3g for write access (rw) 
# /dev/hda1
UUID=12102C02102CEB83  /media/windows  ntfs-3g  auto,users,uid=1000,gid=100,dmask=027,fmask=137,utf8  0  0

并且这里https://www.raspberrypi.org/forums/viewtopic.php?t=16803#p170646
提到需要安装ntfs-3g

我们先试一下手工mount:

sudo apt-get update
sudo apt-get install ntfs-3g
sudo mount -t ntfs-3g -o uid=pi,gid=pi /dev/sda1 /media/pi/disk1t

进入到disk1t目录下进行读写目录的操作,可知成功。
好了,现在继续编辑fstab:

sudo vi /etc/fstab

修改配置为:

UUID=6E2833D828339E51 /media/pi/disk1t ntfs-3g uid=pi,gid=pi    0       0

重启,成功了。

注:
尝试过程中,根据http://www.simonthepiman.com/how_to_setup_windows_file_server.php
运行了一下
sudo fdisk -l
发现磁盘格式是SFS的

SFS (Secure FileSystem) is a set of programs which create and manage a number of encrypted disk volumes, and runs under both DOS and Windows. Each volume appears as a normal DOS drive, but all data stored on it is encryped at the individual-sector level.

google "mount sfs",找到https://askubuntu.com/questions/231639/cant-mount-2nd-hd-sfs/412254#412254
试了试其中提到的工具ldmtool,也许它配置成功之后会把正确的参数写入到fstab里面
但是不行:

pi@raspberrypi:~ $ sudo ldmtool scan
[
]

没有扫出任何东西来。
不知道成功mount是否和ldmtool有关系,以后再试。

@willwhui
Copy link
Author

willwhui commented Jul 2, 2018

树莓派启动失败

断电,重新启动时,如果usb硬盘盒没有通电,那么启动树莓派的时候就不会成功。
失败的原因是:没有找到挂接的硬盘。
解决的办法:启动时保证外挂的硬盘盒通电,处于非休眠状态。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment