I had the following setup:
A NUC running debian 13 configured with a DHCP static lease. A NAS drive serving multiple file shares over CIFS.
The problem was that whenever the nuc booted, the file shares were not mounted automatically. I followed several of the ‘recommended’ approaches
_netdevdidn’t make any difference- Configuring systemd mount on first use (x-systemd.automount) – I didn’t try this because it wasn’t what I really wanted. Also I’ve heard it causes issues when using the mount within namespaces.
- Using systemd-mount(1) units to mount the share including specifying
After=network-online.target– no difference
Ultimately I think the problem lay with the fact that the network-online.target had completed before dhcpcd had completed. Leaving subsequent units in a state where networking was “up” there’s a race condition since dhcp had not completed retrieving an address. This could be seen in systemctl status media-mount.mount with the following line:
mount[954]: mount error: could not resolve address for <nasdrive>.....
I think the “correct” solution for this is dbus integration for dhcpcd so that systemd can be notified when network autoconfiguration has been completed. I’ve had a look and it’s available as a separate package for some distros and it’s unclear if it is shipped by debian. I’ll have more of a dig and update this post if I find anything.
My Solution
The solution that worked for me was to move the NUC off DHCP and on to a static address whilst continuing to use the systemd-mount(1) style mounts. Although this worked it did not fix the problem entirely. DNS was still failing and I needed to change the mount to use IP rather than DNS.
So all in all it’s a bit sloppy. I feel like there’s a better solution for all of this but it’s not obvious.
Here is my working unit
# /etc/systemd/system/media-mount.mount
[Unit]
Description = mount
After = network-online.target
[Mount]
What = //192.168.1.2/mount
Where = /media/mount
Type = cifs
Options = credentials=/etc/mount.creds,vers=2.0,uid=user,gid=user
[Install]
WantedBy = multi-user.target
And then mount with systemctl enable --now media-mount.mount
Leave a Reply