You are not logged in.

#1 2026-03-31 10:50:01

zkab
Member
Registered: 2025-04-18
Posts: 13

Long time to mount NFS when switching between LAN and WiFi

I want to switch between LAN and WiFi for my laptop by unplug/plug the cable.
The laptop also mount NFS shares.
I wrote a script '99-network-switch' that I stored in '/etc/NetworkManager/dispatcher.d'

#!/usr/bin/zsh

INTERFACE=$1
ACTION=$2

# Definiera LAN & WiFi interface namn (Kolla med 'ip link')

WIRED_INF="enp4s0u2u4" 
WIFI_INF="wlan0"

case "$ACTION" in
    up)
        if [ "$INTERFACE" = "$WIRED_INF" ]; then
            nmcli radio wifi off	# Kabel ansluten & koppla bort WiFi

	    umount -l /nfs/Raivo
            umount -l /nfs/Anne
            mount -t nfs -o timeo=14,_netdev nasse:/volume1/FARBAUTE-NASSE /nfs/Raivo
            mount -t nfs -o timeo=14,_netdev nasse:/volume1/Anne-NAS/Anne  /nfs/Anne

        elif [ "$INTERFACE" = "$WIFI_INF" ]; then
            				# WiFi ansluten & mounta bara
            umount -l /nfs/Raivo
            umount -l /nfs/Anne            
            mount -t nfs -o timeo=14,_netdev nasse:/volume1/FARBAUTE-NASSE /nfs/Raivo
            mount -t nfs -o timeo=14,_netdev nasse:/volume1/Anne-NAS/Anne  /nfs/Anne
        fi
        ;;
    down)
        if [ "$INTERFACE" = "$WIRED_INF" ]; then
            nmcli radio wifi on		# Kabel ej ansluten & slå på WiFi för att tillåta auto-connect
            sleep 5			# Vänta några sekunder för WiFi att handskaka för mount

            umount -l /nfs/Raivo
            umount -l /nfs/Anne
            mount -t nfs -o timeo=14,_netdev nasse:/volume1/FARBAUTE-NASSE /nfs/Raivo
            mount -t nfs -o timeo=14,_netdev nasse:/volume1/Anne-NAS/Anne  /nfs/Anne

        fi
        ;;
esac

My NFS mount I have in fstab:

nasse:/volume1/FARBAUTE-NASSE     /nfs/Raivo nfs _netdev,noauto,x-systemd.automount,x-systemd.mount-timeout=10,timeo=14,x-systemd.idle-timeout=1min,user 0 0
nasse:/volume1/Anne-NAS/Anne      /nfs/Anne  nfs _netdev,noauto,x-systemd.automount,x-systemd.mount-timeout=10,timeo=14,x-systemd.idle-timeout=1min,user 0 0

When I unplug/plug the cable the laptop switches correctly between LAN and WiFi but it takes almost 2 minutes before I can see the NFS shares in my file manager.
The 'journalctl' gives following:

Mar 31 11:53:25 rk-dell systemd[1]: nfs-Raivo.mount: Deactivated successfully.
Mar 31 11:53:25 rk-dell systemd[1]: nfs-Anne.mount: Deactivated successfully.
Mar 31 11:54:57 rk-dell nfsrahead[10517]: setting /nfs/Raivo readahead to 128
Mar 31 11:54:57 rk-dell nfsrahead[10525]: setting /nfs/Anne readahead to 128
Mar 31 11:54:57 rk-dell nfsrahead[10542]: setting /nfs/Raivo readahead to 128
Mar 31 11:54:58 rk-dell nfsrahead[10549]: setting /nfs/Anne readahead to 128

Where have I missed?

Offline

#2 2026-03-31 13:50:49

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 74,253

Re: Long time to mount NFS when switching between LAN and WiFi

https://wiki.archlinux.org/title/NFS#Us … dispatcher
In contrast to the wiki I'd not use "-l" at all, you want the share to unmount before the connection breaks and you want the clean up both sides before that happens.
Then don'try to mount anything at all - x-systemd.automount will re-mount the share on accessing the path.

Right now your dispatcher script looks racy - when the wired connection goes down you start the radio, wait 5s - during that time the wifi connection will be established the share un-and remounted, then the un/mount of the original script will ideally tail that and unideally run straight into the ongoing action.

Online

#3 2026-03-31 14:48:17

twelveeighty
Member
Registered: 2011-09-04
Posts: 1,446

Re: Long time to mount NFS when switching between LAN and WiFi

To add to seth's comment: you ALSO want to make sure you flush / sync any cached data before you pull the cable. Traditionally, NFS is/was notoriously bad for gracefully handling frequent disconnects and reconnects. I do not know if that has improved over the years, but I would NEVER trust pulling a cable if I have an important file open on an NFS share with pending changes.

Offline

Board footer

Powered by FluxBB