I need to mount NFS shares on my laptop when I am in the office and plugged into a wired Ethernet connection (via a dock). Is there a reliable way to automatically mount and unmount NFS shares in this scenario?
I'm running Arch Linux. I tried the NetworkManager dispatcher method described here: NFS - ArchWiki
Using that method, my system will freeze (hang, become unresponsive) when I try to connect to any WiFi access point outside the office.
All of my NFS mounts use these options:
nfsserver:/path/one/ /path/one nfs _netdev,defaults,noatime,nodiratime,soft,retrans=6,timeo=20,retry=0,rsize=32768,wsize=32768,proto=tcp 0 0
The full instructions I used from the link above are pasted here:
Enable and start the NetworkManager-dispatcher.service.
The following script safely unmounts the NFS shares before the relevant network connection is disabled by listening for the pre-down and vpn-pre-down events:
Note: This script ignores mounts with the noauto option.
Place this script at /etc/NetworkManager/dispatcher.d/30-nfs.sh
#!/bin/bash # Find the connection UUID with "nmcli con show" in terminal. # All NetworkManager connection types are supported: wireless, VPN, wired... WANTED_CON_UUID="CHANGE-ME-NOW-9c7eff15-010a-4b1c-a786-9b4efa218ba9" if [[ "$CONNECTION_UUID" == "$WANTED_CON_UUID" ]]; then # Script parameter $1: NetworkManager connection name, not used # Script parameter $2: dispatched event case "$2" in "up") mount -a -t nfs4,nfs ;; "pre-down");& "vpn-pre-down") umount -l -a -t nfs4,nfs >/dev/null ;; esac fi
Make the script executable with chmod and create a symlink inside /etc/NetworkManager/dispatcher.d/pre-down to catch the pre-down events:
# ln -s /etc/NetworkManager/dispatcher.d/30-nfs.sh /etc/NetworkManager/dispatcher.d/pre-down.d/30-nfs.sh
In order to make this script actually work, I had to modify the case statement for the pre-down event as follows:
Before that change, no script action was taken in response to the pre-down event. After the change, script responds to events appropriately. However, as I said, my laptop freezes whenever I try to connect to WiFi access points outside of the office.
I can't find anything in the logs that seems related to this. But I have enough experience with NFS to guess that this issue is exactly what happens when NFS mounts are not available. Furthermore, the problem only started after I started using the method described above. Previously, I was connecting manually via SSHFS and I did not have a freezing problem.
I also briefly tried the following method:
However, that method looked really sketchy and dated, so I gave up on it quickly. Because this seems to be a common need, I expect there is a known, reliable solution. However, I can't seem to find one.