玩转树莓派[02:树莓派+u盘搭建家庭共享]

1.硬盘挂载

1.1 使用fdisk -l 查看硬盘的详细信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
[email protected]:~$ sudo fdisk -l
Disk /dev/ram0: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram1: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram2: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram3: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram4: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram5: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram6: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram7: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram8: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram9: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram10: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram11: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram12: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram13: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram14: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram15: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mmcblk0: 29.9 GiB, 32105299968 bytes, 62705664 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: 0x68339dda
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 * 8192 524287 516096 252M c W95 FAT32 (LBA)
/dev/mmcblk0p2 524288 62705663 62181376 29.7G 83 Linux
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors
Disk model: U310
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: 0xb64d29a8
Device Boot Start End Sectors Size Id Type
/dev/sda1 8192 62914559 62906368 30G 7 HPFS/NTFS/exFAT

1.2 挂载到指定位置

1
2
3
4
[email protected]:~$ mkdir share
[email protected]:~$ ls
share
[email protected]:~$ sudo mount /dev/sda1 share

1.3 查看挂载情况

1
df -h
1
2
3
4
5
6
7
8
9
10
11
[email protected]:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 4.2G 24G 15% /
devtmpfs 918M 0 918M 0% /dev
tmpfs 950M 0 950M 0% /dev/shm
tmpfs 950M 8.9M 941M 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 950M 0 950M 0% /sys/fs/cgroup
/dev/mmcblk0p1 252M 71M 181M 29% /boot
tmpfs 190M 0 190M 0% /run/user/1000
/dev/sda1 30G 19G 9.9G 65% /home/pi/share

取消挂载 : sudo umount /dev/sda1

1.4 解决硬盘的自动挂载

每次树莓派重启或者硬盘插拔都需要对硬盘进行重新挂载,比较麻烦,因此需要自动挂载。这里要修改/etc/fstab文件。

可以看到,fstab文件其实就是一个表格,表格各列的含意如下:
第一列:磁盘分区名/卷标,一般是/dev/sdaN(N表示正整数)
第二列:挂载点,我们在这里把/dev/sda1挂到/samba上。
第三列:缺省设置,一般用defautls。
第四列:是否备份:0——表示不做 dump 备份;1——表示要将整个 fie sysytem 里的内容备份;2 也表示要做 dump 备份,但该分区的重要性比 1 小。
第五列:检测顺序:0——不进行检测;根分区(/),必须填写 1,其它的都不能填写 1。如果有分区填写大于 1 的话,则在检查完根分区后,从小到大依次检查下去。
具体填写方法在图中已注明。

2.df -h查看盘符挂载情况

1
2
3
4
5
6
7
8
9
10
11
[email protected]:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 788M 0 788M 0% /dev
tmpfs 185M 12M 173M 7% /run
/dev/mmcblk0p2 30G 8.8G 20G 32% /
tmpfs 925M 0 925M 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 925M 0 925M 0% /sys/fs/cgroup
/dev/mmcblk0p1 252M 89M 163M 36% /boot
tmpfs 185M 16K 185M 1% /run/user/1000
/dev/sda 500G 28G 473G 6% /media/pi/AE57-581F

3.已知盘符已自动挂载在/home/pi/share文件夹下

4.安装samba

更新一下源 :sudo apt-get update

安装samba : sudo apt-get install samba samba-common-bin

5.安装完成后,配置/etc/samba/smb.conf文件

1
sudo vim /etc/samba/smb.conf

<span class=label label-primary”>在其最后添加以下命令:

1
2
3
4
5
6
#共享文件的名称,将在网络上以此名称显示
path = /home/pi/share #共享文件的路径
valid users = root pi #允许访问的用户,这里我用的是root 和 pi 两个用户
browseable = yes  #允许浏览
public = yes  #共享开放
writable = yes  #可写

6.保存后,重启samba服务

1
sudo /usr/sbin/samba restart

(可通过 whereis samba 寻找 samba 所在位置)

7.最后使用root用户添加共享用户:

smbpasswd –a pi #这里我用的pi。

1
2
3
4
5
[email protected]:~$ sudo su
[email protected]:/home/pi# smbpasswd -a pi
New SMB password:
Retype new SMB password:
Added user pi

8.ok 完成

参考


玩转树莓派[02:树莓派+u盘搭建家庭共享]
https://blog.baixf.tk/2020/07/09/raspberry/玩转树莓派[02树莓派+u盘搭建家庭共享]/
作者
白小飞
发布于
2020年7月9日
许可协议