我也遇见了
Failed to start mount-command.service: Unit mount-command.service has a bad unit file setting.
See system logs and 'systemctl status mount-command.service' for details.
最后用chatgpt解决了
🛠 在 Unraid 下飞牛云 OS 开机自动挂载 9p 共享的可靠方案
📦 背景
在 Unraid 中通过 virtio+9p 把目录共享到虚拟机(飞牛云 OS)。常规做法:
- 在
/etc/fstab
添加挂载项(需 noauto
)
- 用 systemd service 开机执行
mount -a -O noauto
但实际中常遇到:开机时 virtio 设备还没准备好,导致挂载失败。
✅ 最可靠的解决思路
创建一个脚本:
- 检测挂载点是否已挂载
- 如果没挂载就尝试挂载
- 最多尝试 30 秒,每秒尝试一次
再通过 systemd service 开机自动执行脚本。
📝 步骤
1️⃣ 编辑 /etc/fstab
添加挂载配置:
photo /vol1/1000/photo 9p trans=virtio,version=9p2000.L,noauto,nobootwait,rw 0 0
- photo 是在虚拟机配置里 target dir 的名字
- /vol1/1000/photo 是飞牛云 OS 内的挂载点路径
- noauto 表示开机时不自动挂载,需要手动 mount
2️⃣ 编写挂载脚本
创建脚本:
sudo nano /usr/local/bin/mount-photo.sh
内容:
#!/bin/bash
TARGET=/vol1/1000/photo
# 最多尝试 30 次,每次间隔 1 秒
for i in {1..30}; do
if mountpoint -q "$TARGET"; then
echo "$TARGET 已经挂载"
exit 0
else
echo "未挂载,尝试挂载..."
mount "$TARGET" && exit 0
fi
sleep 1
done
echo "挂载失败"
exit 1
赋予执行权限:
sudo chmod +x /usr/local/bin/mount-photo.sh
3️⃣ 创建 systemd 服务
sudo nano /etc/systemd/system/mount-photo.service
内容:
[Unit]
Description=Mount photo on startup
After=local-fs.target network.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/mount-photo.sh
[Install]
WantedBy=multi-user.target
4️⃣ 启用并测试
sudo systemctl daemon-reload
sudo systemctl enable mount-photo.service
sudo systemctl start mount-photo.service
sudo systemctl status mount-photo.service
5️⃣ 重启验证
重启:
sudo reboot
查看挂载是否成功:
mountpoint /vol1/1000/photo
成功的话会返回:
/vol1/1000/photo is a mountpoint
✅ 效果
- 开机时等待 virtio 设备准备好
- 持续检测并尝试挂载
- 保证重启后也能成功挂载