I have an nfs mount on a debian12 system running systemd252, i need this to be mounted at startup before zfs but after network-online.target
, so i tried using /etc/fstab
but that keeps loading before network-online.target
(even when using x-systemd.before= etc). I've also tried putting a script in /etc/network/if-up.d/nfs
that mounts nfs, but zfs loads before that.
So, i tried making a mount service with systemd;
# /etc/systemd/system/nfs.mount
[Unit]
Description=nfs
DefaultDependencies=no
Conflicts=umount.target
Before=local-fs.target umount.target zfs-import.target
After=swap.target network-online.target
Requires=network-online.target #it doesn't work with and without this line
[Mount]
What=0.0.0.0:/ # generic info
Where=/nfs
Type=nfs
Options=ro,async,nfsvers=4,nosuid
[Install]
WantedBy=multi-user.target
This seems to load before network-online.target
because it errors and says: "mount.nfs: Network is unreachable", i've also tried making multiple other services but before,after and requires never seem to work. How would i achieve loading network,nfs,zfs in order?
EDIT: It seems like network-online.target
reports being reached too early, nfs.mount
does get started right after, which means that "after=" works. I tried adding a delay with ExecStartPre=/usr/bin/sleep 10
but this delays it for 2 whole minutes.
EDIT2: I fixed it by changing the service;
# /etc/systemd/system/mount-nfs.service
[Unit]
Description=Mount nfs after network but before docker
DefaultDependencies=no
Before=docker.service
After=network-online.target remote-fs.target
Wants=network-online.target
[Service]
Type=oneshot
RemainAfterExit=no
ExecStartPre=/usr/bin/sleep 15
ExecStart=/usr/bin/mount 0.0.0.0:/ /nfs
ExecStart=/usr/sbin/zfs mount -a
[Install]
WantedBy=multi-user.target
Added after=remote-fs.target
because of this blog post,
wants=network-online.target
because of this doc,
and replaced before=zfs-import.target
by just mounting with zfs mount -a
So in the end, the main post title was solved. (I'm not posting an answer to my own question because i technically worked around the problem instead of fully fixing it)