在wireguard之后使用fstab或systemd挂载smb共享

在wireguard之后使用fstab或systemd挂载smb共享

我正在尝试在建立wireguard 连接后安装SMB 共享。因此我做了以下几件事:

  • 创建了wireguard配置
  • 让 systemd 在启动时启动连接 systemctl enable [email protected]
  • 将以下条目添加到 fstab
//192.168.0.10/home /mnt/smb cifs [email protected],credentials=/home/user/.smbcredentials,vers=3.0,uid=user,pid=user,users,_netdev 0 0

重新启动后,网络共享未安装。知道 fstab 中的每个条目都会转换为 systemd-unit 后,我​​检查了该单元的状态systemctl status mnt-smb.mount

● mnt-smb.mount - /mnt/smb
   Loaded: loaded (/etc/fstab; generated; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2022-02-09 16:55:28 CET; 1min 17s ago
    Where: /mnt/smb
     What: //192.168.0.10/home
     Docs: man:fstab(5)
           man:systemd-fstab-generator(8)
  Process: 496 ExecMount=/bin/mount //192.168.0.10/home /mnt/smb -t cifs -o [email protected],credentials=/home/user/.smbcredentials,vers=3.0,uid=user,gid=user,users,_netdev (code=exited, status=32)

Feb 09 16:55:28 homeserver systemd[1]: Mounting /mnt/smb...
Feb 09 16:55:28 homeserver systemd[1]: mnt-smb.mount: Mount process exited, code=exited status=32
Feb 09 16:55:28 homeserver systemd[1]: Failed to mount /mnt/smb.
Feb 09 16:55:28 homeserver systemd[1]: mnt-smb.mount: Unit entered failed state.

查阅了一下,dmesg得到以下信息:

[   17.612210] Key type cifs.spnego registered
[   17.612253] Key type cifs.idmap registered
[   17.758816] wireguard: loading out-of-tree module taints kernel.
[   17.775249] wireguard: WireGuard 0.0.20191206 loaded. See www.wireguard.com for information.
[   17.775273] wireguard: Copyright (C) 2015-2019 Jason A. Donenfeld <[email protected]>. All Rights Reserved.
[   27.752548] CIFS VFS: Error connecting to socket. Aborting operation.
[   27.752576] CIFS VFS: cifs_mount failed w/return code = -115

基于以下关于 stackoverflow 的问题,我假设 115 表示“进行中”。如果wireguard vpn 连接未启动,我也看到了相同的行为。

查看生成的单元文件:

# Automatically generated by systemd-fstab-generator

[Unit]
SourcePath=/etc/fstab
Documentation=man:fstab(5) man:systemd-fstab-generator(8)
Before=remote-fs.target

[Mount]
What=//192.168.0.10/home
Where=/mnt/smb
Type=cifs
[email protected],credentials=/home/user/.smbcredentials,vers=3.0,uid=user,gid=user,users,_netdev

如果我mount -a在登录后运行,一切都会按预期进行。所以我认为这是单位之间的时间问题。因此,我还创建了一个自己的 systemd 单元并从 fstab 中删除了该条目:

[Unit]
Description=Homeserver SMB
Before=remote-fs.target
[email protected]
[email protected]

[Mount]
Type=cifs
What=//192.168.0.10/home
Where=/mnt/smb
Options=credentials=/home/user/.smbcredentials,vers=3.0,uid=user,gid=user,users

[Install]
WantedBy=multi-user.target

将其移至/etc/systemd/system/mnt-smb.mount并通过 激活systemctl enable mnt-smb.mount。此方法在一次重启后有效,但在下次重启后停止工作。

问题:

  • 如何解决这个时间问题?
  • 哪些 systemd 选项可以在单元文件或 fstab 中使用?

答案1

我怀疑wireguard 设置的接口还没有准备好,只是因为服务已启动。您的问题可能是与此相关在这种情况下,解决方案是等待虚拟设备。

After=network.target [email protected]
Requires=sys-devices-virtual-net-wg0.device

相关内容