无法通过 Wi-Fi 正确安装网络驱动器(cifs 错误 -101)

无法通过 Wi-Fi 正确安装网络驱动器(cifs 错误 -101)

注:本文转载自https://askubuntu.com/questions/1427248/cant-mount-network-drive-properly-over-wi-fi因为那是题外话

我正在尝试在 Lubuntu 16.4 Raspberry Pi 版本上安装网络驱动器。我想澄清一下,我可以使用 mount 命令来安装它。问题在于将其安装在启动上。我已经修改了/etc/fstab。通过以太网时它可以正常工作。

但是,当仅安装 USB 无线适配器时,网络驱动器无法安装(错误代码 -101)。

我怀疑这是由于 Lubuntu 从 fstab 挂载驱动器之前没有初始化 Wi-Fi 适配器造成的。

我能做些什么?

答案1

感谢您的提示,@Cagri!

我也看过

将 _netdev,noauto,x-systemd.automount 添加到我的网络驱动器选项似乎已经解决了该问题。

唯一的副作用是,网络驱动器在文件管理器中出现两次。

答案2

我遇到了同样的问题,我找到了一个非常好的解决方案,使用 automount 和 systemd

这里解释一下:https://ppfeufer.de/linux-on-demand-nfs-and-samba-cifs-connections-with-systemd-automount/

安装所需的包

sudo apt-get install samba cifs-utils nfs-common 

创建挂载点

sudo mkdir -p /mnt/network/myshare

创建凭证文件

sudo nano /etc/samba/credentials

与里面:

username=your_username
password=your_password

然后

sudo chmod 600 /etc/samba/credentials

创建 Systemd 单元文件

sudo nano /etc/systemd/system/mnt-network-myshare.mount

示例:CIFS

[Unit]
Description = My Share mount
Requires = dbus-org.freedesktop.nm-dispatcher.service
After = network-online.target
Wants = network-online.target
 
[Mount]
What = //example.server/myshare
Where = /mnt/network/myshare
Options = credentials=/etc/samba/credentials,vers=3.1.1,uid=your_username,iocharset=utf8,file_mode=0655,dir_mode=0655,noperm
Type = cifs
TimeoutSec = 30
 
[Install]
WantedBy = multi-user.target

示例:NFS

[Unit]
Description = My Share mount
Requires = dbus-org.freedesktop.nm-dispatcher.service
After = network-online.target
Wants = network-online.target
 
[Mount]
What = example.server:/myshare
Where = /mnt/network/myshare
Options = defaults
Type = nfs
TimeoutSec = 30
 
[Install]
WantedBy = multi-user.target

自动安装

sudo nano /etc/systemd/system/mnt-network-myshare.automount

[Unit]
Description = Automount for My Share
ConditionPathExists = /mnt/network/myshare
 
[Automount]
Where = /mnt/network/myshare
TimeoutIdleSec = 0
 
[Install]
WantedBy = multi-user.target



Test

sudo systemctl daemon-reload

sudo systemctl start mnt-network-myshare.mount
sudo systemctl status mnt-network-myshare.mount

输出像这样

 mnt-network-myshare.mount - My Share mount
   Loaded: loaded (/etc/systemd/system/mnt-network-myshare.moun; static; vendor preset: enabled)
   Active: active (running) since Fri 2022-04-29 10:10:03 CEST; 1min 1s ago
    Where: /mnt/network/myshare
     What: //example.server/myshare
  Process: 13005 ExecMount=/bin/mount //example.server/myshare /mnt/network/myshare -t cifs -o vers=3.1.1,credentials=/home/your_username/.mount-credentials/myshare,iocharset=utf8,rw,x-systemd.automount,uid=1000 (code=exited, status=0/SUCCESS)
    Tasks: 0 (limit: 4915)
   CGroup: /system.slice/mnt-smb-sambashare.mount
 
Apr 29 10:10:03 your_pc systemd[1]: Mounting My Share mount...
Apr 29 10:10:03 your_pc systemd[1]: Mounted My Share mount.

您也可以测试自动挂载

sudo systemctl start mnt-network-myshare.automount
sudo systemctl status mnt-network-myshare.automount

启用自动挂载文件以在启动时启动

sudo systemctl enable mnt-network-myshare.automount

相关内容