Try   HackMD

Linux 開機自動掛載NAS的SMB資料夾

本教學以debian系統為主
NAS使用OpenMediaVault
English Version

NAS設置

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

共有三個smb資料夾,︁分別是

  • sdb
  • sdc
  • sdd

設定NAS SMB資料夾

git clone https://github.com/frakw/nas_smb_mounter.git

修改nas.conf,︁存放NAS的基本資訊

NAS_IP=NAS的IP
MOUNT_POINT=/mnt
NAS_NAME=NAS的名字
NAS_SMB_1=NAS的第1個SMB資料夾名稱
NAS_SMB_2=NAS的第2個SMB資料夾名稱
NAS_SMB_3=NAS的第3個SMB資料夾名稱

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

修改.smbcredentials,︁存放NAS的帳號密碼

username=NAS的使用者名稱
password=NAS的使用者密碼

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

測試掛載

cd nas_smb_mounter

設定.smbcredentials的權限

sudo chmod 600 .smbcredentials

安裝必要套件

sudo apt install cifs-utils 

設定腳本為可執行文件

sudo chmod +x mount.sh
sudo chmod +x unmount.sh

執行掛載

./mount.sh

成功看到資料夾內容

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

解除掛載

./unmount.sh

開機自動進行掛載

sudo crontab -e

在最底下加入

@reboot sleep 30 && <mount.sh的位置>

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

會加入sleep 30是因為我透過Tailscale來與NAS連線,︁所以等待Tailscale啟動後再執行