Ubuntu自動掛載NAS smb 網(wǎng)絡位置
參考鏈接:
https://www.raobee.com/archives/308/? (基本 手動掛載方式)
https://blog.csdn.net/qq_42259469/article/details/107368930 (自動掛載方式)
前提
NAS已經(jīng)開啟smb服務,Ubuntu(linux)已經(jīng)在/mnt 下創(chuàng)建好映射的文件夾,如

安裝cifs工具
sudo apt install cifs-utils
編輯/etc/fstab文件
sudo vim /etc/fstab
加入內(nèi)容
//your_nas_ip/dir /mnt/NAS/dir cifs rw,dir_mode=0777,file_mode=0777,vers=2.0,username=yourusername,password=yourpassword 0 0
fstab語法詳情參考:https://blog.csdn.net/youmatterhsp/article/details/83933158
這里username當然是nas的登錄用戶名,對應的密碼也是nas 的
我的范例:
如果掛載n個文件夾,就需要執(zhí)行n條命令
如:
#NAS auto mount
//192.168.1.11/003 /mnt/NAS/003 cifs rw,dir_mode=0777,file_mode=0777,vers=2.0,username=admin,password=1234567 0 0
//192.168.1.11/001電影 /mnt/NAS/001電影 cifs rw,dir_mode=0777,file_mode=0777,vers=2.0,username=admin,password=1234567 0 0
//192.168.1.11/002電視劇 /mnt/NAS/002電視劇 cifs rw,dir_mode=0777,file_mode=0777,vers=2.0,username=admin,password=1234567 0 0
//192.168.1.11/004紀錄片 /mnt/NAS/004紀錄片 cifs rw,dir_mode=0777,file_mode=0777,vers=2.0,username=admin,password=1234567 0 0
//192.168.1.11/006Music /mnt/NAS/006Music cifs rw,dir_mode=0777,file_mode=0777,vers=2.0,username=admin,password=1234567 0 0
//192.168.1.11/007歸檔 /mnt/NAS/007歸檔 cifs rw,dir_mode=0777,file_mode=0777,vers=2.0,username=admin,password=1234567 0 0
//192.168.1.11/BT /mnt/NAS/BT cifs rw,dir_mode=0777,file_mode=0777,vers=2.0,username=admin,password=1234567 0 0
//192.168.1.11/test /mnt/NAS/test cifs rw,dir_mode=0777,file_mode=0777,vers=2.0,username=admin,password=1234567 0 0
最后一步:掛載命令
sudo mount -a
但是無法實現(xiàn)開機自動掛載
普通硬盤這樣可以直接掛載,但網(wǎng)絡硬盤不能,每次重啟都要打入??sudo mount -a??命令才可以
解決方案:開機后自動執(zhí)行 sudo mount -a
1、可能有人沒開啟這個服務,先開啟
systemctl start?remote-fs.target
systemctl enable?remote-fs.target
2、提升用戶權限為root和sudo
sudo vi?/etc/sudoers
兩個位置中加入內(nèi)容,用戶名不要用weig,而要用自己的

3、開機執(zhí)行命令
cd && vi .bashrc
然后在最后一行加入下面命令
sudo mount -a

保存退出
4、驗證
reboot 重啟后,可以看到,自動掛載成功!

總結
ubuntu還真是蛋疼,
其實NAS中不應該直接創(chuàng)建頂級共享目錄,應該先創(chuàng)建一個多媒體目錄,然后再在下面創(chuàng)建動漫、電影、紀錄片這些不同的文件夾,要不然真是費勁死,以后維護也不方便