树莓派移动硬盘自动挂载工具+samba搭建局域网NAS

1,安装samba

[root@raspberrypi ~]$ apt-get install samba

[root@raspberrypi ~]$ samba --version
Version 4.9.5-Debian

samba设置root用户密码:

[root@raspberrypi ~]$ smbpasswd -a root
New SMB password:
Retype new SMB password:
[root@raspberrypi ~]$

2,下载auto-mount工具

下载地址:https://download.csdn.net/download/u010177891/12332420

3,安装工具

解压:

[root@raspberrypi /home/sunkai]$ unzip auto-mount.zip 
Archive:  auto-mount.zip
  inflating: auto-mount/auto-mount   
  inflating: auto-mount/auto-mount.sh  
  inflating: auto-mount/config       
  inflating: auto-mount/readme.txt

 给config添加执行权限:

[root@raspberrypi /home/sunkai]$ cd auto-mount/
[root@raspberrypi /home/sunkai/auto-mount]$ ls
auto-mount  auto-mount.sh  config  readme.txt
[root@raspberrypi /home/sunkai/auto-mount]$ chmod +x config 
[root@raspberrypi /home/sunkai/auto-mount]$ ls
auto-mount  auto-mount.sh  config  readme.txt

安装auto-mount:

[root@raspberrypi /home/sunkai/auto-mount]$ ./config install
✔ install success
[root@raspberrypi /home/sunkai/auto-mount]$ 

查看auto-mount的运行状态:

[root@raspberrypi /home/sunkai/auto-mount]$ /etc/init.d/auto-mount status
service auto-mount is running

4,插入U盘或者移动硬盘

随便在树莓派的USB口插入U盘或者移动硬盘等待30s检测工具自动检测出来并完成挂载

5,验证是否可以在局域网访问:

在同一局域网内打开“文件资源管理器”输入“\\192.168.1.107”树莓派的ip,按提示输入root用户和密码即可访问。

6,卸载

[root@raspberrypi /home/sunkai/auto-mount]$ ./config uninstall
✔ uninstall success

7,功能

1,auto-mount运行起来是会定期(30s)扫描是否有USB存储设备插入。

2,当有USB存储设备插入树莓派时auto-mount可以检测出来并识别该设备的名称也就是lable,然后会创建/home/mnt/{设备lable}目录并将该设备挂载到该目录下。

3,在挂载的同时会修改samba的配置文件(/etc/samba/smb.conf)自动添加共享配置参数并重启samba服务,将/home/mnt/{设备lable}通过samba共享出去。

4,默认的共享配置如下,可以修改auto-mount.sh文件定制自己的配置

[${lable}]
    browseable = yes
    path = /home/mnt/${lable}
    create mask = 0755
    directory mask = 0755
    valid users = root
    write list = root, @root
    writable = yes
    available = yes

5,auto-mount停止。/etc/init.d/auto-mount stop可以卸载USB存储设备,删除添加的配置,取消samba共享。如果正在占用已挂载的USB存储设备可能会出现stop失败,需要检查哪些程序在使用并停止占用才能stop成功

注意:

1,U盘或者移动硬盘的名字不要设置为中文,因为blkid命令不能别中文,所以可能出现共享的目录是乱码。

2,如果有U盘或者移动硬盘的名字是空的也就是label是空的会跳过挂载无法实现共享。

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章