0

I'm trying to get davfs2 to mount a WebDAV folder automatically on debian stretch at boot.

It seems that systemd attempts to mount the folder with mount.davfs before the DHCP client has an IP address (which of course fails), even with the _netdev mount option in /etc/fstab. (Without _netdev, mounting also fails but so does the entire boot process and I'm dropped into a root shell during boot.)

What magic can I give davfs so that it only tries to mount after we've gotten an IP address with DHCP? (And why isn't this the default...)

As can be seen from the journalctl output below, davfs2 attempts to mount before the DHCPACK and NFS mounts successfully after the DHCPACK. So NFS behaves, but davfs2 fails.

> grep davfs /etc/fstab
https://example.com/remote.php/webdav/ /home/peter/pmorch davfs user,rw,auto,_netdev 0 0

> sudo journalctl --since 13:20:48 | grep -P 'davfs|pmorch|DHCP|ISO'
Jan 18 13:20:49 snowden dhclient[669]: Internet Systems Consortium DHCP Client 4.3.5
Jan 18 13:20:49 snowden sh[657]: Internet Systems Consortium DHCP Client 4.3.5
Jan 18 13:20:49 snowden sh[657]: DHCPDISCOVER on ens18 to 255.255.255.255 port 67 interval 3
Jan 18 13:20:49 snowden dhclient[669]: DHCPDISCOVER on ens18 to 255.255.255.255 port 67 interval 3
Jan 18 13:20:49 snowden systemd[1]: Mounting /mnt/ISO-Dev...
Jan 18 13:20:49 snowden systemd[1]: Mounting /home/peter/pmorch...
Jan 18 13:20:49 snowden systemd[1]: Mounting /mnt/ISO...
Jan 18 13:20:49 snowden mount.davfs[751]: davfs2 1.5.4
Jan 18 13:20:49 snowden systemd[1]: home-peter-pmorch.mount: Mount process exited, code=exited status=1
Jan 18 13:20:49 snowden systemd[1]: Failed to mount /home/peter/pmorch.
Jan 18 13:20:49 snowden systemd[1]: home-peter-pmorch.mount: Unit entered failed state.
Jan 18 13:20:50 snowden dhclient[669]: DHCPREQUEST of 172.22.216.172 on ens18 to 255.255.255.255 port 67
Jan 18 13:20:50 snowden sh[657]: DHCPREQUEST of 172.22.216.172 on ens18 to 255.255.255.255 port 67
Jan 18 13:20:50 snowden sh[657]: DHCPOFFER of 172.22.216.172 from 172.22.216.251
Jan 18 13:20:50 snowden dhclient[669]: DHCPOFFER of 172.22.216.172 from 172.22.216.251
Jan 18 13:20:50 snowden dhclient[669]: DHCPACK of 172.22.216.172 from 172.22.216.251
Jan 18 13:20:50 snowden sh[657]: DHCPACK of 172.22.216.172 from 172.22.216.251
Jan 18 13:20:52 snowden systemd[1]: Mounted /mnt/ISO-Dev.
Jan 18 13:20:52 snowden systemd[1]: Mounted /mnt/ISO.
Peter V. Mørch
  • 812
  • 7
  • 15

1 Answers1

0

As described in systemd: start service at boot time after network is really up (for WoL purpose), for some incredibly weird reason that I won't pretend to understand, the systemd target network-online (and other reasonable-sounding targets) are reached before we get a DHCP IP address. (That just seems wrong).

My guess is that this is the reason why fstabs _netdev tries to mount it too early.

Instead, I've removed the line from /etc/fstab entirely and now done:

systemctl enable systemd-networkd.service systemd-networkd-wait-online.service

And created /etc/systemd/system/home-peter-pmorch.mount:

[Unit]
Description=Mount pmorch WebDAV Service
After=systemd-networkd-wait-online.service
Wants=systemd-networkd-wait-online.service

[Mount]
What=https://example.com/remote.php/webdav/
Where=/home/peter/pmorch
Options=uid=peter,gid=peter,file_mode=0664,dir_mode=2775,grpid
Type=davfs
TimeoutSec=15

[Install]
WantedBy=multi-user.target

Now it gets mounted at boot time. And after a network problem I can no longer do mount -a but must

sudo systemctl start home-peter-pmorch.mount

But now at least it works.

Peter V. Mørch
  • 812
  • 7
  • 15