set-nas-mount-opts.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. # Make the NAS mount boot-proof on one node, keeping the protocol that works there.
  3. #
  4. # Used on dgx1/2/3/4/8 on 2026-11-11 (phase 1 of flare-storage-nas.md).
  5. #
  6. # ./set-nas-mount-opts.sh <nfs-vers> [remount yes|no]
  7. # ./set-nas-mount-opts.sh 4.1 # dgx2, dgx3, dgx4, dgx8
  8. # ./set-nas-mount-opts.sh 4.0 no # dgx1 (4.1 hangs there; live mount was fine)
  9. #
  10. # Why a script and not a sed over the nas.lan:/sna line: the protocol version lives
  11. # in that same line, so a blanket rewrite silently forces 4.1 onto nodes that cannot
  12. # mount it (dgx1 hangs on a fresh 4.1 mount, with one clean client and nconnect=1).
  13. # The entry is rewritten by its mount-point field instead.
  14. #
  15. # Note: `nofail` never appears in live mount options (it is an fstab/systemd
  16. # option), so verify the applied change with `timeo=100`, not with `nofail`.
  17. set -e
  18. export LC_ALL=C
  19. VERS="${1:?usage: $0 <nfs-vers> [remount yes|no]}"
  20. REMOUNT="${2:-yes}"
  21. sudo cp -a /etc/fstab "/etc/fstab.bak-$(date +%F-%H%M)"
  22. sudo python3 - "$VERS" <<'PY'
  23. import sys
  24. vers = sys.argv[1]
  25. path, out, hit = "/etc/fstab", [], False
  26. for line in open(path).read().splitlines(True):
  27. f = line.split()
  28. if len(f) >= 3 and f[1] == "/mnt/nas":
  29. opts = ("rw,hard,nofail,x-systemd.mount-timeout=30,rsize=1048576,wsize=1048576,"
  30. "timeo=100,retrans=3,noatime,nodiratime,actimeo=600,nconnect=8,vers=" + vers)
  31. out.append("nas.lan:/sna\t/mnt/nas\tnfs4\t%s\t0\t0\n" % opts)
  32. hit = True
  33. else:
  34. out.append(line)
  35. assert hit, "no /mnt/nas entry in fstab"
  36. open(path, "w").write("".join(out))
  37. PY
  38. grep "/mnt/nas" /etc/fstab
  39. sudo systemctl daemon-reload
  40. if [ "$REMOUNT" = yes ]; then
  41. # A plain umount (never -l): it fails safely when something holds the mount, and
  42. # it is the only thing that actually clears stale NFS client IDs.
  43. if sudo umount /mnt/nas 2>/dev/null; then echo "umount ok"; else echo "umount skipped (busy?)"; fi
  44. timeout 40 sudo mount /mnt/nas && echo "mount ok"
  45. fi
  46. findmnt -no OPTIONS /mnt/nas | grep -qo 'timeo=100' \
  47. && echo "VERIFIED timeo=100 live" \
  48. || echo "NOT live yet (fstab only; takes effect on next mount)"