1. 背景
在 Ubuntu Server 中,经常需要通过 SMB/CIFS 挂载 NAS 或 Windows 文件共享。
传统的 /etc/fstab CIFS 挂载方式存在一个问题:
- 系统启动时 NAS 可能还没有就绪;
- 网络异常可能导致 CIFS 挂载失败;
- NAS 临时关机不应该影响服务器正常启动;
- 希望真正访问目录时才连接 NAS;
- NAS 使用的可能不是默认 SMB 445 端口。
这种场景可以使用:
/etc/fstab
+
x-systemd.automount
+
CIFS
实现按需自动挂载。
本文使用以下环境:
Ubuntu Server
NAS IP: 10.2.2.184
SMB Share: vlcshare
SMB Port: 1445
SMB Version: 3.0
本地挂载目录:
/data/share
凭据文件:
/etc/samba/nas-project.cred
最终实现:
系统启动
│
↓
systemd 读取 /etc/fstab
│
↓
创建 data-share.automount
│
↓
等待访问 /data/share
│
↓
业务访问 /data/share
│
↓
触发 data-share.mount
│
↓
mount.cifs
│
↓
10.2.2.184:1445
│
↓
//10.2.2.184/vlcshare
2. 安装 CIFS 客户端
Ubuntu 通过 cifs-utils 提供 CIFS 挂载工具。
安装:
sudo apt update
sudo apt install -y cifs-utils
检查:
mount.cifs -V
3. 创建本地挂载目录
创建:
sudo mkdir -p /data/share
检查:
ls -ld /data/share
注意:
/data/share
本质上首先是一个普通 Linux 目录。
NAS 挂载成功以后,远程文件系统会覆盖显示在这个目录上。
4. 创建 SMB 凭据文件
不建议直接把 SMB 用户名和密码写进 /etc/fstab。
创建:
sudo mkdir -p /etc/samba
sudo vim /etc/samba/nas-project.cred
内容:
username=smbuser
password=smbuser@2026
注意凭据文件里面不要写:
credentials=/etc/samba/nas-project.cred
credentials= 是 mount 参数,而不是凭据文件内容。
设置权限:
sudo chown root:root /etc/samba/nas-project.cred
sudo chmod 600 /etc/samba/nas-project.cred
检查:
ls -l /etc/samba/nas-project.cred
正常类似:
-rw------- 1 root root ... /etc/samba/nas-project.cred
这样普通用户无法直接读取 SMB 密码。
5. 检查 NAS 网络
首先测试 NAS 是否可达:
ping -c 3 10.2.2.184
但需要注意:
ping 成功
只能说明 ICMP 网络基本可达,并不能证明 SMB 服务正常。
本文 NAS 的 SMB 使用:
1445
而不是默认:
445
所以应该测试实际 SMB TCP 端口:
nc -zv -w 3 10.2.2.184 1445
如果没有 nc:
sudo apt install -y netcat-openbsd
也可以同时测试默认端口进行对比:
nc -zv -w 3 10.2.2.184 445
6. 手工测试 CIFS 挂载
第一次部署时,不建议直接修改 /etc/fstab。
应该先手工确认:
网络
SMB端口
账号密码
共享目录
SMB版本
全部正常。
执行:
sudo mount -t cifs \
"//10.2.2.184/vlcshare" \
/data/share \
-o credentials=/etc/samba/nas-project.cred,vers=3.0,iocharset=utf8,file_mode=0777,dir_mode=0777,port=1445
这里非常重要的是:
port=1445
因为 SMB 默认使用 TCP 445。
如果 NAS 使用自定义端口,而忘记配置 port=1445,就可能出现:
mount error(115): could not connect to 10.2.2.184
Unable to find suitable address.
7. 检查手工挂载
执行:
findmnt /data/share
正常应该能看到类似:
TARGET SOURCE
/data/share //10.2.2.184/vlcshare
查看文件:
ls -lah /data/share
如果需要验证写权限:
touch /data/share/cifs_test.txt
ls -l /data/share/cifs_test.txt
rm -f /data/share/cifs_test.txt
确认没有问题以后:
sudo umount /data/share
检查:
findmnt /data/share
此时没有输出,说明手工挂载已经卸载。
注意:
这里可以直接使用 umount,因为此时还没有正式启用 systemd automount。
8. 配置 /etc/fstab
先备份:
sudo cp -a /etc/fstab /etc/fstab.bak.$(date +%Y%m%d-%H%M%S)
编辑:
sudo vim /etc/fstab
增加:
//10.2.2.184/vlcshare /data/share cifs credentials=/etc/samba/nas-project.cred,vers=3.0,port=1445,_netdev,nofail,x-systemd.automount,x-systemd.idle-timeout=0,x-systemd.mount-timeout=10s 0 0
如果业务明确需要比较宽松的客户端权限表现,也可以:
//10.2.2.184/vlcshare /data/share cifs credentials=/etc/samba/nas-project.cred,vers=3.0,port=1445,iocharset=utf8,file_mode=0777,dir_mode=0777,_netdev,nofail,x-systemd.automount,x-systemd.idle-timeout=0,x-systemd.mount-timeout=10s 0 0
生产环境不建议无必要地使用 0777,实际权限还需要结合 NAS 端共享权限和 SMB 用户权限设计。
9. fstab 参数说明
credentials
credentials=/etc/samba/nas-project.cred
指定 SMB 用户名密码文件。
vers
vers=3.0
指定 SMB 3.0。
port
port=1445
指定 SMB 服务端口。
本案例 NAS 不使用默认 445,因此这个参数不能遗漏。
_netdev
_netdev
告诉 systemd:
这是网络文件系统。
systemd 会按照远程文件系统处理相关依赖。
nofail
nofail
NAS 挂载失败时,不因为这个远程文件系统而使系统启动失败。
对于 NAS、SMB、NFS 等外部存储非常实用。
x-systemd.automount
x-systemd.automount
这是整个方案最重要的参数之一。
它不是 CIFS 自身的参数,而是 systemd 对 /etc/fstab 提供的扩展。
作用是:
不立即真正挂载 NAS,而是在有人访问挂载目录时触发真正的 mount。
例如:
ls /data/share
才触发 CIFS 挂载。
x-systemd.idle-timeout
x-systemd.idle-timeout=0
表示挂载成功后,不因为长时间空闲而自动卸载。
x-systemd.mount-timeout
x-systemd.mount-timeout=10s
限制 systemd 执行 mount job 时等待的时间。
例如 NAS 无法连接时,不希望一次初始挂载任务长时间等待。
需要注意:
这个参数主要限制挂载过程,并不能解决 CIFS 已经挂载以后 NAS 突然断网所产生的 I/O 等待问题。
10. 检查 /etc/fstab
配置完成后:
sudo findmnt --verify --verbose
确认没有明显错误。
然后:
sudo systemctl daemon-reload
daemon-reload 的作用可以简单理解为:
我修改了 systemd 相关配置
↓
请 systemd 重新读取
对于当前场景:
/etc/fstab
↓
systemd-fstab-generator
↓
data-share.automount
data-share.mount
11. 为什么会出现 data-share.automount
我们并没有手工创建:
data-share.automount
这是 systemd 根据:
/data/share
自动生成的。
路径:
/data/share
转换成:
data-share
然后生成:
data-share.automount
data-share.mount
可以通过:
systemd-escape --path /data/share
查看:
data-share
例如如果目录改成:
/data/auto/share
执行:
systemd-escape --path /data/auto/share
得到:
data-auto-share
那么对应就是:
data-auto-share.automount
data-auto-share.mount
对于包含特殊字符的路径,不建议自己猜 Unit 名称,直接使用 systemd-escape --path 最可靠。
12. .automount 和 .mount 有什么区别
这两个 Unit 的作用完全不同。
data-share.automount
负责:
监控 /data/share 是否被访问
例如:
systemctl status data-share.automount
可能看到:
Active: active (waiting)
表示:
automount 已经准备好,正在等待有人访问
/data/share。
data-share.mount
负责:
真正执行 CIFS 挂载
也就是:
//10.2.2.184/vlcshare
↓
/data/share
可以:
systemctl status data-share.mount
真正挂载成功后应该看到:
Active: active (mounted)
13. 启动 automount
如果之前测试失败过,可以先:
sudo systemctl reset-failed data-share.mount
sudo systemctl reset-failed data-share.automount
这里:
reset-failed
只是:
清除 systemd 记录的 failed 状态。
它不会执行 CIFS 挂载。
然后:
sudo systemctl start data-share.automount
检查:
systemctl status data-share.automount --no-pager
正常可能看到:
Loaded: loaded (/etc/fstab; generated)
Active: active (waiting)
Where: /data/share
其中:
/etc/fstab; generated
非常重要。
说明:
配置来自 /etc/fstab
+
Unit 是 systemd 自动生成的
14. 触发 CIFS 自动挂载
执行:
ls /data/share
automount 会检测到目录访问:
访问 /data/share
↓
data-share.automount
↓
data-share.mount
↓
mount.cifs
↓
10.2.2.184:1445
检查:
systemctl status data-share.mount --no-pager
正常:
Active: active (mounted)
再检查:
findmnt /data/share
15. 为什么 ll 看不出来这是 NAS
例如:
cd /data
ll
可能只看到:
drwxr-xr-x 2 root root 0 Sep 7 13:38 share/
从 ls -l 的结果看:
share/
和普通目录没有特别明显的区别。
这是正常现象。
Linux 文件系统挂载的目的,就是把另一个文件系统挂到普通目录树中。
不要通过:
owner
目录大小
时间
判断是不是 NAS。
16. 正确判断是不是 NAS
最推荐:
findmnt -T /data/share
正常应该看到:
TARGET SOURCE FSTYPE
/data/share //10.2.2.184/vlcshare cifs
重点:
SOURCE = //10.2.2.184/vlcshare
FSTYPE = cifs
也可以:
df -hT /data/share
或者:
findmnt -T /data/share -o TARGET,SOURCE,FSTYPE,OPTIONS
如果只检查是不是 mountpoint:
mountpoint /data/share
但是使用 x-systemd.automount 时需要注意:
automount 本身也会创建 autofs 挂载点。
因此:
mountpoint /data/share
只能说明它是挂载点。
如果要确认真正的 CIFS 是否已经挂载,更推荐:
findmnt -T /data/share -t cifs
17. 一个容易忽略的问题:ll /data 可能触发 automount
实际测试中发现:
cd /data
ll
即使没有主动:
ls /data/share
也可能触发:
data-share.automount
systemd 日志中可以看到:
Got automount request for /data/share, triggered by ... (ls)
原因是:
ll
通常相当于:
ls -alF
ls -l 会获取目录项的属性信息。
当获取:
/data/share
的相关属性时,就可能触发 autofs。
过程:
ll /data
↓
ls 获取 share 属性
↓
触发 automount
↓
data-share.mount
↓
mount.cifs
↓
连接 NAS
如果 NAS 不可达:
ll /data
↓
触发 NAS 挂载
↓
等待 CIFS 连接
↓
直到成功或者超时
所以可能出现:
只是执行
ll /data,命令却卡了几秒。
18. 对目录结构的建议
如果 /data 是服务器的重要业务目录,例如:
/data/docker
/data/mysql
/data/redis
/data/images
/data/share
而:
/data/share
又是 NAS automount,那么 NAS 异常有可能影响对 /data 的某些目录遍历操作。
如果有非常严格的要求:
NAS 故障绝对不能影响
/data日常运维。
可以考虑将网络存储独立,例如:
/nas/vlcshare
或者:
/mnt/nas/vlcshare
形成:
/data
├── docker
├── mysql
├── redis
└── images
/nas
└── vlcshare
这样本地业务数据和网络存储的边界更加清晰。
19. 手动卸载 CIFS
使用 x-systemd.automount 后,不建议直接把:
umount /data/share
作为日常管理方式。
因为 /data/share 同时涉及 systemd 建立的 autofs 触发点。
直接操作可能导致:
data-share.automount:
Got hangup/error on autofs pipe from kernel
Result: unmounted
20. 只卸载 CIFS,但保留自动挂载
执行:
sudo systemctl stop data-share.mount
检查:
findmnt -t cifs /data/share
此时真正的 CIFS 可以被卸载,但是:
systemctl status data-share.automount
automount 仍然存在。
因此再次:
ls /data/share
就可能重新触发 CIFS 挂载。
这相当于:
停止 data-share.mount
↓
NAS 当前卸载
↓
automount 仍然工作
↓
再次访问
↓
重新挂载 NAS
21. 完全停止自动挂载
如果进行 NAS 维护,希望访问目录也不要重新挂载:
sudo systemctl stop data-share.automount
必要时再确认真正的 mount:
sudo systemctl stop data-share.mount
检查:
findmnt /data/share
恢复:
sudo systemctl start data-share.automount
以后访问:
ls /data/share
即可再次触发挂载。
22. NAS 维护前建议检查占用
不要在业务正在读写 NAS 时直接强制卸载。
先检查:
fuser -vm /data/share
如果存在业务进程,应先处理业务。
维护时可以:
sudo systemctl stop data-share.automount
sudo systemctl stop data-share.mount
不建议在不清楚影响的情况下直接:
umount -f /data/share
或者:
umount -l /data/share
尤其是正在写文件时。
23. 修改 /etc/fstab 后怎么重新加载
修改:
vim /etc/fstab
以后执行:
sudo findmnt --verify
sudo systemctl daemon-reload
sudo systemctl restart data-share.automount
如果之前 .mount 已经失败:
sudo systemctl reset-failed data-share.mount
如果 automount 自身也处于 failed:
sudo systemctl reset-failed data-share.automount
24. reset-failed、daemon-reload、restart 的区别
可以简单记忆:
systemctl daemon-reload
等于:
我修改配置了,请 systemd 重新读取。
systemctl reset-failed data-share.mount
等于:
清除这个 Unit 之前的 failed 状态。
systemctl restart data-share.automount
等于:
停止并重新启动 automount。
ls /data/share
等于:
真正触发 CIFS 挂载。
完整过程:
修改 /etc/fstab
↓
findmnt --verify
↓
systemctl daemon-reload
↓
reset-failed(之前失败过时)
↓
restart data-share.automount
↓
active (waiting)
↓
ls /data/share
↓
data-share.mount
↓
active (mounted)
25. 是否需要 systemctl enable
通常不需要手工:
systemctl enable data-share.automount
因为:
data-share.automount
不是我们手工创建的持久化 Unit。
配置来源是:
/etc/fstab
系统启动时:
开机
↓
systemd
↓
读取 /etc/fstab
↓
systemd-fstab-generator
↓
生成 data-share.automount
↓
建立 /data/share automount
因此真正需要长期保存的是:
/etc/fstab
26. 验证开机自动建立 automount
如果环境允许,可以重启:
sudo reboot
系统启动以后,先不要访问 /data/share。
检查:
systemctl status data-share.automount --no-pager
正常应该类似:
Loaded: loaded (/etc/fstab; generated)
Active: active (waiting)
Where: /data/share
此时真正的 CIFS 不一定已经挂载。
检查:
systemctl status data-share.mount --no-pager
然后:
ls /data/share
再次:
systemctl status data-share.mount --no-pager
findmnt -T /data/share
应该可以看到:
SOURCE FSTYPE
//10.2.2.184/vlcshare cifs
27. CIFS 故障排查命令
查看 automount:
systemctl status data-share.automount --no-pager
查看真正的 mount:
systemctl status data-share.mount --no-pager
查看挂载关系:
findmnt -T /data/share
查看 CIFS:
findmnt -t cifs
查看 systemd mount 日志:
journalctl -u data-share.mount -n 100 --no-pager
查看 automount 日志:
journalctl -u data-share.automount -n 100 --no-pager
查看 CIFS 内核日志:
dmesg -T | grep -i cifs
或者:
journalctl -k | grep -i cifs
查看 CIFS 内核状态:
cat /proc/fs/cifs/DebugData
统计:
cat /proc/fs/cifs/Stats
检查相关进程:
ps -ef | grep '[m]ount.cifs'
检查目录占用:
fuser -vm /data/share
检查 SMB 端口:
nc -zv -w 3 10.2.2.184 1445
28. mount error(115) 排查案例
实际配置过程中遇到:
mount error(115): could not connect to 10.2.2.184
Unable to find suitable address.
同时:
systemctl status data-share.mount
显示:
Active: failed (Result: exit-code)
最终发现 /etc/fstab 配置为:
//10.2.2.184/vlcshare /data/share cifs credentials=/etc/samba/nas-project.cred,vers=3.0,_netdev,nofail,x-systemd.automount,x-systemd.idle-timeout=0 0 0
这里遗漏了:
port=1445
而 NAS 实际 SMB 服务端口为:
1445
修正:
//10.2.2.184/vlcshare /data/share cifs credentials=/etc/samba/nas-project.cred,vers=3.0,port=1445,_netdev,nofail,x-systemd.automount,x-systemd.idle-timeout=0,x-systemd.mount-timeout=10s 0 0
重新:
systemctl daemon-reload
systemctl reset-failed data-share.mount
systemctl reset-failed data-share.automount
systemctl restart data-share.automount
访问:
ls /data/share
即可重新触发。
这个案例说明:
使用非标准 SMB 端口时,手工 mount 和
/etc/fstab必须同时配置port=,否则非常容易出现“手工挂载正常、systemd 自动挂载失败”的情况。
29. systemd 状态怎么看
automount 正常等待
data-share.automount
Active: active (waiting)
表示:
automount 正常
+
等待目录访问
automount 已经收到访问
日志:
Got automount request for /data/share, triggered by ... (ls)
说明:
ls
↓
访问 /data/share
↓
automount 已触发
CIFS 挂载成功
data-share.mount
Active: active (mounted)
这是判断真正 CIFS mount 成功的重要状态。
CIFS 挂载失败
data-share.mount
Active: failed (Result: exit-code)
此时应该重点检查:
NAS IP
SMB端口
网络
credentials
共享名称
vers
CIFS内核日志
30. CIFS 断网以后会不会自动恢复
这里需要区分两个阶段。
尚未挂载
如果:
data-share.automount
正在等待,而 NAS 当前不可用:
访问 /data/share
↓
尝试 data-share.mount
↓
失败
NAS 恢复以后,再次访问可以重新尝试挂载。
CIFS 已经挂载
如果:
data-share.mount = active
然后 NAS 突然断网,则主要进入 CIFS 客户端自身的连接恢复逻辑。
短暂网络故障可能恢复。
但应用程序执行:
read()
write()
stat()
fsync()
期间可能出现等待或者错误。
因此:
x-systemd.automount不是 NAS 健康检查器,也不是持续监控并自动重建所有异常 CIFS 会话的守护进程。
对于重要文件写入,业务程序仍然应该正确处理 I/O 错误、返回码,并根据数据重要程度进行完整性校验。
31. ping、nc、findmnt 分别能证明什么
这几个命令不要混淆。
ping 10.2.2.184
只能证明:
ICMP 网络基本可达
nc -zv -w 3 10.2.2.184 1445
可以证明:
TCP 1445 可以建立连接
但不能证明 SMB 用户名密码正确。
findmnt -T /data/share
可以判断:
当前目录属于哪个文件系统
真正验证 NAS 文件 I/O,还应该:
ls /data/share
以及根据业务需求进行实际读写测试。
32. 最终推荐配置
本文环境最终推荐:
//10.2.2.184/vlcshare /data/share cifs credentials=/etc/samba/nas-project.cred,vers=3.0,port=1445,_netdev,nofail,x-systemd.automount,x-systemd.idle-timeout=0,x-systemd.mount-timeout=10s 0 0
凭据:
username=smbuser
password=smbuser@2026
权限:
chown root:root /etc/samba/nas-project.cred
chmod 600 /etc/samba/nas-project.cred
33. 标准部署 SOP
最终可以把整个部署过程简化成:
安装 cifs-utils
↓
创建 /data/share
↓
创建 credentials
↓
chmod 600
↓
检查 10.2.2.184:1445
↓
手工 mount
↓
测试读写
↓
手工 umount
↓
备份 /etc/fstab
↓
增加 CIFS + x-systemd.automount
↓
findmnt --verify
↓
systemctl daemon-reload
↓
启动 data-share.automount
↓
确认 active (waiting)
↓
访问 /data/share
↓
触发 data-share.mount
↓
findmnt 确认 FSTYPE=cifs
↓
重启服务器
↓
验证开机自动建立 automount
34. 常用命令速查
检查自动挂载:
systemctl status data-share.automount
检查真正 CIFS:
systemctl status data-share.mount
检查 NAS 挂载:
findmnt -T /data/share
触发挂载:
ls /data/share
只停止真正的 CIFS:
systemctl stop data-share.mount
完全停止 automount:
systemctl stop data-share.automount
恢复:
systemctl start data-share.automount
修改 /etc/fstab 后:
findmnt --verify
systemctl daemon-reload
systemctl restart data-share.automount
失败后清状态:
systemctl reset-failed data-share.mount
systemctl reset-failed data-share.automount
检查 CIFS 日志:
journalctl -u data-share.mount -n 100 --no-pager
dmesg -T | grep -i cifs
检查端口:
nc -zv -w 3 10.2.2.184 1445
检查占用:
fuser -vm /data/share
35.查看这次启动以来的挂载日志
# CIFS mount
root@gtdq:/data# journalctl -u data-share.mount -b --no-pager
9月 22 13:48:56 gtdq systemd[1]: data-share.mount: Deactivated successfully.
9月 22 13:49:03 gtdq systemd[1]: Mounting data-share.mount - /data/share...
9月 22 13:49:03 gtdq systemd[1]: Mounted data-share.mount - /data/share.
# 看 automount
root@gtdq:/data# journalctl -u data-share.automount -b --no-pager
9月 22 13:14:10 gtdq systemd[1]: Set up automount data-share.automount.
9月 22 13:14:50 gtdq systemd[1]: data-share.automount: Got hangup/error on autofs pipe from kernel. Likely our automount point has been unmounted by someone or something else?
9月 22 13:14:50 gtdq systemd[1]: data-share.automount: Failed with result 'unmounted'.
9月 22 13:16:12 gtdq systemd[1]: Set up automount data-share.automount.
9月 22 13:16:20 gtdq systemd[1]: data-share.automount: Got automount request for /data/share, triggered by 403478 (ls)
9月 22 13:16:31 gtdq systemd[1]: data-share.automount: Got automount request for /data/share, triggered by 403545 (ls)
9月 22 13:16:44 gtdq systemd[1]: data-share.automount: Got automount request for /data/share, triggered by 403750 (ls)
9月 22 13:16:56 gtdq systemd[1]: data-share.automount: Deactivated successfully.
9月 22 13:16:56 gtdq systemd[1]: Unset automount data-share.automount.
9月 22 13:18:25 gtdq systemd[1]: Set up automount data-share.automount.
9月 22 13:18:33 gtdq systemd[1]: data-share.automount: Got automount request for /data/share, triggered by 404130 (ls)
9月 22 13:18:50 gtdq systemd[1]: data-share.automount: Deactivated successfully.
9月 22 13:18:50 gtdq systemd[1]: Unset automount data-share.automount.
9月 22 13:19:14 gtdq systemd[1]: Set up automount data-share.automount.
9月 22 13:19:21 gtdq systemd[1]: data-share.automount: Got automount request for /data/share, triggered by 404367 (ls)
9月 22 13:21:41 gtdq systemd[1]: data-share.automount: Got automount request for /data/share, triggered by 404549 (mount.cifs)
9月 22 13:22:13 gtdq systemd[1]: data-share.automount: Got automount request for /data/share, triggered by 404615 (mount.cifs)
9月 22 13:23:25 gtdq systemd[1]: data-share.automount: Got automount request for /data/share, triggered by 404918 (ls)
9月 22 13:23:41 gtdq systemd[1]: data-share.automount: Deactivated successfully.
9月 22 13:23:41 gtdq systemd[1]: Unset automount data-share.automount.
9月 22 13:27:07 gtdq systemd[1]: data-share.automount: Path /data/share is already a mount point, refusing start.
9月 22 13:27:07 gtdq systemd[1]: Failed to set up automount data-share.automount.
9月 22 13:27:35 gtdq systemd[1]: Set up automount data-share.automount.
9月 22 13:27:37 gtdq systemd[1]: data-share.automount: Got automount request for /data/share, triggered by 405737 (ls)
9月 22 13:38:55 gtdq systemd[1]: data-share.automount: Got automount request for /data/share, triggered by 406664 (ls)
9月 22 13:46:03 gtdq systemd[1]: data-share.automount: Got automount request for /data/share, triggered by 407143 (ls)
9月 22 13:49:03 gtdq systemd[1]: data-share.automount: Got automount request for /data/share, triggered by 407428 (ls)
# 查看 CIFS 断线、重连等内核日志
journalctl -k -b | grep -iE 'cifs|smb'
#或者
dmesg -T | grep -iE 'cifs|smb'
# 查看指定时间段
journalctl -k \
--since "2026-09-22 12:00:00" \
--until "2026-09-22 14:00:00" \
| grep -iE 'cifs|smb'
## 同时看 systemd
journalctl -u data-share.mount \
--since "2026-09-22 12:00:00" \
--until "2026-09-22 14:00:00"
# 实时盯着日志
## 终端1
journalctl -kf | grep -iE 'cifs|smb'
## 终端2
journalctl -fu data-share.mount
### 然后人为断开 NAS 网络
# 查看当前 CIFS 连接状态
cat /proc/fs/cifs/DebugData
cat /proc/fs/cifs/Stats
findmnt -T /data/share -o TARGET,SOURCE,FSTYPE,OPTIONS
总结
Ubuntu 上挂载 NAS 时,使用:
CIFS
+
/etc/fstab
+
x-systemd.automount
相比简单的开机直接挂载,更适合 NAS、文件服务器等存在网络依赖的场景。
整个方案最关键的是理解:
/etc/fstab
↓
systemd-fstab-generator
↓
data-share.automount
↓
等待目录访问
↓
data-share.mount
↓
mount.cifs
↓
NAS
其中:
data-share.automount
负责“什么时候触发”,而:
data-share.mount
负责“真正挂载”。
实际运维时,建议始终使用:
findmnt -T /data/share
确认真正的文件系统来源,而不是通过 ll 判断。
对于使用自定义 SMB 端口的环境,还必须特别注意:
port=1445
手工 mount 和 /etc/fstab 两边都不能遗漏。
最后需要注意,automount 可以减少开机阶段对 NAS 的强依赖,但它并不能消除所有网络文件系统的阻塞风险。对于重要业务,应同时做好 NAS 可用性监控、应用 I/O 错误处理以及数据完整性保护。
446



被折叠的 条评论
为什么被折叠?



