nfs-kernel-server trying to share before zfs mount finishes

crackers819903

New Member
Mar 20, 2022
8
4
3
43
is there a way to make nfs-kernel-server wait til zfs mount finishes on reboot? every time i reboot the server, i end up with my NFS shares dead until i log in myself and manually start the service, because it's trying to share something that doesn't exist (i can see in the logs that my zpools haven't been mounted yet when NFS is trying to share them).

i've tried everything i can think of: editing the service files trying to wait for zfs.target, using RequiresMountsFor=, nothing has worked. even tried running a @reboot cron to start it after 60 seconds...no dice. how can i get this to work so that i don't need to log in manually every time i reboot the server (which isn't feasible since i usually schedule reboots for overnight)?
 
Do not put your ZFS filesystems in /etc/exports but use the sharenfs property instead:

https://linuxhint.com/share-zfs-filesystems-nfs/

i am. that's how i am doing it, and it works fine when the server is up. that isn't the issue. the issue is that even with sharing it that way, it seems the NFS server is trying to share it before ZFS has finished mounting it on a reboot. it fails to start nfs-kernel-server on reboot every single time.

the only way i've come across to resolve this for now is adding a reboot cron to restart nfs-kernel-server 60 seconds after reboot...but that feels hacky. i figured there has to be a better / more correct way...
 
Last edited:
The systemd unit for the NFS server should wait for local filesystems to be mounted. Is that not the case for ZFS?
it does not appear to be. on boot, i am constantly presented with the nfs-kernel-server in a failed state because it cannot find my zfs mounts.

if i then log in and start it myself, it works fine (because the mounts are now present). the cron i set to run 60 seconds after reboot and then restart the nfs-kernel-server seems to have taken care of this...but without it, the NFS server is crashed unless i log in and start it myself after the ZFS mounts finish.

and i'm not talking about this happening occasionally...it happens literally every single time.
 
The nfs-kernel-server.service unit looks like this here:

INI:
# /lib/systemd/system/nfs-server.service
[Unit]
Description=NFS server and services
DefaultDependencies=no
Requires=network.target proc-fs-nfsd.mount
Requires=nfs-mountd.service
Wants=rpcbind.socket
Wants=nfs-idmapd.service

After=local-fs.target
After=network.target proc-fs-nfsd.mount rpcbind.socket nfs-mountd.service
After=nfs-idmapd.service rpc-statd.service
Before=rpc-statd-notify.service
# GSS services dependencies and ordering
Wants=auth-rpcgss-module.service
After=rpc-gssd.service gssproxy.service rpc-svcgssd.service

# start/stop server before/after client
Before=remote-fs-pre.target

Wants=nfs-config.service
After=nfs-config.service

[Service]
EnvironmentFile=-/run/sysconfig/nfs-utils

Type=oneshot
RemainAfterExit=yes
ExecStartPre=/usr/sbin/exportfs -r
ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS
ExecStop=/usr/sbin/rpc.nfsd 0
ExecStopPost=/usr/sbin/exportfs -au
ExecStopPost=/usr/sbin/exportfs -f

ExecReload=/usr/sbin/exportfs -r

[Install]
WantedBy=multi-user.target

I.e. it should be started after local-fs.target. The zfs-mount.service should be executed before reaching local-fs.target:

INI:
# /lib/systemd/system/zfs-mount.service
[Unit]
Description=Mount ZFS filesystems
Documentation=man:zfs(8)
DefaultDependencies=no
After=systemd-udev-settle.service
After=zfs-import.target
After=systemd-remount-fs.service
Before=local-fs.target
ConditionPathIsDirectory=/sys/module/zfs

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/zfs mount -a

[Install]
WantedBy=zfs.target
 
Last edited:
The nfs-kernel-server.service unit looks like this here:

INI:
# /lib/systemd/system/nfs-server.service
[Unit]
Description=NFS server and services
DefaultDependencies=no
Requires=network.target proc-fs-nfsd.mount
Requires=nfs-mountd.service
Wants=rpcbind.socket
Wants=nfs-idmapd.service

After=local-fs.target
After=network.target proc-fs-nfsd.mount rpcbind.socket nfs-mountd.service
After=nfs-idmapd.service rpc-statd.service
Before=rpc-statd-notify.service
# GSS services dependencies and ordering
Wants=auth-rpcgss-module.service
After=rpc-gssd.service gssproxy.service rpc-svcgssd.service

# start/stop server before/after client
Before=remote-fs-pre.target

Wants=nfs-config.service
After=nfs-config.service

[Service]
EnvironmentFile=-/run/sysconfig/nfs-utils

Type=oneshot
RemainAfterExit=yes
ExecStartPre=/usr/sbin/exportfs -r
ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS
ExecStop=/usr/sbin/rpc.nfsd 0
ExecStopPost=/usr/sbin/exportfs -au
ExecStopPost=/usr/sbin/exportfs -f

ExecReload=/usr/sbin/exportfs -r

[Install]
WantedBy=multi-user.target

I.e. it should be started after local-fs.target. The zfs-mount.service should be executed before reaching local-fs.target:

INI:
# /lib/systemd/system/zfs-mount.service
[Unit]
Description=Mount ZFS filesystems
Documentation=man:zfs(8)
DefaultDependencies=no
After=systemd-udev-settle.service
After=zfs-import.target
After=systemd-remount-fs.service
Before=local-fs.target
ConditionPathIsDirectory=/sys/module/zfs

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/zfs mount -a

[Install]
WantedBy=zfs.target

I'm aware of all of that...but it just doesn't work. it fails on boot every single time.

I tried editing the nfs service to get it to wait for zfs.target. that didn't work either.

the only thing I've been able to get to work is the cron that restarts the nfs-kernel-server service 60 seconds after reboot.
 
I'm late to the thread, but I found this because I was having similar problems. In my case the issue was that I was starting nfs-kernel-server.service before DNS was available (DNS being provided by a Proxmox VM that hasn't started yet) and I was doing zfs set sharenfs... by name rather than IP. If you're having the same issue, running systemctl show nfs-server.service would show "exportfs: Failed to resolve..." messages. Exporting by IP instead of name is one solution to this problem.
 
I'm aware of all of that...but it just doesn't work. it fails on boot every single time.

I tried editing the nfs service to get it to wait for zfs.target. that didn't work either.

the only thing I've been able to get to work is the cron that restarts the nfs-kernel-server service 60 seconds after reboot.
Hello,
i have exactly the same problem than you. Do you find a solution about this ?

I'm exporting nfs share with zfs using IP (no DNS used in my case).

I have exactly the same nfs-server.service and zfs-mount.service files.


Code:
server systemd[1]: Starting NFS server and services...
server exportfs[2967]: exportfs: Failed to stat /data/dataset1: No such file or directory
server exportfs[2967]: exportfs: Failed to stat /data/dataset2: No such file or directory
server systemd[1]: nfs-server.service: Control process exited, code=exited, status=1/FAILURE
server systemd[1]: nfs-server.service: Failed with result 'exit-code'.
server systemd[1]: Stopped NFS server and services.

If I restart manually the nfs-server with systemd, it works...

Thanks
 
Last edited:

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!