macOS 15.7的Finder访问Ubuntu Samba容易卡的优化
1. 引言
macOS 的 Finder 在访问 Ubuntu 的 Samba 时,默认会:
- 读取每个文件的 metadata(xattr、权限、创建时间)
- 请求缩略图或 QuickLook 预览
- 尝试写入 .DS_Store 文件(存储视图状态)
而 Ubuntu 的 Samba 默认配置在响应这些 metadata 请求时非常慢(特别是 fruit: 模块未优化时),于是 Finder 等待超时、卡死。
2. 解决方案
1、macOS 端优化
编辑 /etc/nsmb.conf:
sudo vim /etc/nsmb.conf
加入以下内容:
[default]
signing_required=no
directory_cache_timeout=10
soft=yes
notify_off=yes
aio=no
streams=no
minauth=none
解释:
signing_required=no关闭 SMB 签名(Ubuntu 默认允许关闭),显著提升速度。directory_cache_timeout缩短缓存周期。soft=yes让 Finder 不会因单次请求超时而整机卡住。notify_off=yes关闭 Finder 的目录变动监听,防止阻塞。aio=no禁用异步 I/O,可避免 Finder 假死。streams=no禁止 NTFS 流(macOS 不需要),减少 metadata 查询。
执行以下命令(永久关闭 Finder 在网络卷上生成缓存与预览):
defaults write com.apple.desktopservices DSDontWriteNetworkStores true
defaults write com.apple.finder FXPreferredViewStyle Nlsv
defaults write com.apple.finder QLEnableXRayFolders -bool false
然后重启 Finder:
killall Finder
2、Ubuntu Samba 端调整
编辑 /etc/samba/smb.conf:
sudo vim /etc/samba/smb.conf
加入内容:
[global]
server min protocol = SMB2
server signing = auto
fruit:metadata = stream
fruit:posix_rename = yes
fruit:veto_appledouble = no
fruit:nfs_aces = no
ea support = yes
veto files = /._*/.DS_Store/
delete veto files = yes
spotlight = no
strict locking = no
aio read size = 0
aio write size = 0
socket options = TCP_NODELAY
解释:
fruit:*系列是为 macOS 兼容优化的模块(Apple SMB 特性支持)。veto files防止 Finder 生成 .DS_Store,减少写入卡顿。aio read/write size = 0关闭异步 IO(配合 macOS)。socket options = TCP_NODELAY减少延迟。strict locking = no防止 Finder 因锁冲突冻结。
保存并重启 Samba:
sudo systemctl restart smbd
3. 效果预期
完成以上配置后:
- Finder 打开共享目录速度明显提升
- 不再频繁转菊花或卡死
- 传输速度恢复正常(100MB/s+ 局域网)
- .DS_Store、.AppleDouble 文件不会再污染服务器