樹莓派移動硬盤自動掛載工具+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是空的會跳過掛載無法實現共享。

 

 

 

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