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.
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
fstab
s_netdev
tries to mount it too early.Instead, I've removed the line from
/etc/fstab
entirely and now done:And created
/etc/systemd/system/home-peter-pmorch.mount
:Now it gets mounted at boot time. And after a network problem I can no longer do
mount -a
but mustBut now at least it works.