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

1.硬盘挂载

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

pi@raspbian:~$ 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 挂载到指定位置

pi@raspbian:~$ mkdir share
pi@raspbian:~$ ls
share
pi@raspbian:~$ sudo mount /dev/sda1 share

1.3 查看挂载情况

df -h
pi@raspbian:~$ 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查看盘符挂载情况

pi@raspbian:~$ 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文件

sudo vim /etc/samba/smb.conf

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

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

6.保存后,重启samba服务

sudo /usr/sbin/samba restart

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

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

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

pi@raspbian:~$ sudo su
root@raspbian:/home/pi# smbpasswd -a pi
New SMB password:
Retype new SMB password:
Added user pi

8.ok 完成

参考

posted @ 2022-10-10 21:48  baixf白小飞  阅读(173)  评论(0编辑  收藏  举报