Setup NFS Share on Debian

I did practically everything described here.

However, for automating the whole process with fstab on both client & server, this provided important extra information, esp. about bind-mounting existing filesystems into a dedicated NFS folder, and also about /etc/fstab entries.

That's it really; it was much easier than I expected. I should have switched away from sshfs earlier. But I do not yet trust NFS enough to allow remote access, for that I still use sshfs.

Automatic Mount Handling on a Wifi-connected Laptop

All this works perfectly on my desktop computer. But my laptop uses the same NFS set-up on a wireless connection, and whenever the home network is disconnected every application that accesses part of the NFS mount just hangs.

Again, the glorious ArchWiki has the solution. I opted for the NetworkManager dispatcher. Unfortunately, I had to adapt it quite a bit.


  • completely removed NFS mounts from /etc/fstab.
  • rewrote the script to un/mount them directly.
  • made it differentiate between pre-down and down events. I found out that manually disconnecting the Wifi triggers a down event, and not a pre-down event as one might expect (man NetworkManager).

# Find your connection UUID with "nmcli con show" in terminal.
# All NetworkManager connection types are supported: wireless, VPN, wired...

if [[ "$CONNECTION_UUID" == "$WANTED_CON_UUID" ]]; then

# 2 array members make one mount, equivalent to the first 2 fields in an fstab entry
fs=("device1" "dir1" "device2" "dir2" .....) # mounts
# mount options (not umount)
opts=("-o" "option=value")

# Script parameter $1: NetworkManager connection name, not used
# Script parameter $2: dispatched event

        case "$2" in
                echo "$1 $2 - Regular Mount - ${fs[@]}"
                while (( i<${#fs[@]} )); do mount -v -t nfs ${opts[@]} "${fs[$((i++))]}" "${fs[$((i++))]}"; done
                echo "$1 $2 - Regular Umount - ${fs[@]}"
                while (( i<${#fs[@]} )); do umount -v "${fs[i]}"; ((i+=2)); done
                echo "$1 $2 - Forced Umount - ${fs[@]}"
                while (( i<${#fs[@]} )); do umount -v -lf "${fs[i]}"; ((i+=2)); done

Edit as required. Works immediately. You can test it with

journalctl -b -f -u NetworkManager-dispatcher.service

It's rather chatty - you can remove the -vs from the mount/umount commands.