How to remount drives which lost connection?

Bo Berglund bo.berglund at gmail.com
Sat Jun 11 22:18:45 UTC 2022


On Sat, 11 Jun 2022 16:59:06 -0400, Little Girl <littlergirl at gmail.com> wrote:

>Hey there,
>
>Bo Berglund wrote:
>
>>This Mint device seems to sometimes lose connection to an nfs share
>>on the main LAN defined in fstab as follows:
>>
>>192.168.119.216:/home/bosse/www/VIDEO /mnt/video nfs tcp,noexec,intr
>>0 0
>
>[SNIP]
>
>>I understand that I could for instance put an entry in crontab that
>>will run the sudo mount -a command at say 3 minutes following a
>>reboot, but it would be better if there is some existing argument or
>>such that can provide the functionality....
>
>Adding the "hard" option to your /etc/fstab line will make NFS keep
>trying when the connection isn't available:
>
>https://web.mit.edu/rhel-doc/5/RHEL-5-manual/Deployment_Guide-en-US/s1-nfs-client-config-options.html
>
>You might also want to poke around in the nfs, fstab, and mounts man
>pages for a whole lot of choices we're given for how NFS should be
>allowed to behave.
>

I created a small script to check the mount and try to repair if it does not
work:

#!/bin/bash
# Check if mount to server is working, if not try to reconnect
# but only if server is ping-able.
TESTFILE="/mnt/video/index.html"
PINGCMD="ping -4 -c 1 192.168.119.216  > /dev/null 2>&1"
eval "$PINGCMD"
PINGOK=$?

if [ "$PINGOK" != "0" ]; then #server is not on line
  echo "NFS server not on line, cannot connect share"
  exit 1
else
  if [ -e "${TESTFILE}" ]; then
    echo "Mount OK, no action."
    exit 0
  else
    echo "Mount is not present, trying to reconnect"
    eval "sudo mount -a"
    if [ -e "${TESTFILE}" ]; then
      echo "Reconnect successful!"
      exit 0
    else
      echo "Reconnect failed!"
      exit 1
    fi
  fi
fi

I could call this in a crontab entry running every 10 minutes or so...
Or 10 min after a reboot...


-- 
Bo Berglund
Developer in Sweden





More information about the ubuntu-users mailing list