如何解決過時的 nfs 句柄?

如何解決過時的 nfs 句柄?

我注意到有一次當我關閉我的家庭伺服器而我的桌面透過NFS 連接時,我在進入我的主目錄時不斷收到“過時的NFS 句柄警告”,這導致了在這些資料夾中查找的某些程式出現問題。

如何在不重新啟動機器的情況下解決此問題?

Debian Squeeze/Wheezy

答案1

在 Debian Squeeze/Wheezy 上:

強制卸載本地掛載

umount -f /mnt/dir

然後重啟nfs

/etc/init.d/nfs-common restart

答案2

試試這個 shell 腳本。對我來說效果很好:

#!/bin/bash
# Purpose:
# Detect Stale File handle and remove it
# Script created: July 29, 2015 by Birgit Ducarroz
# Last modification: --
#

# Detect Stale file handle and write output into a variable and then into a file
mounts=`df 2>&1 | grep 'Stale file handle' |awk '{print ""$2"" }' > NFS_stales.txt`
# Remove : ‘ and ’ characters from the output
sed -r -i 's/://' NFS_stales.txt && sed -r -i 's/‘//' NFS_stales.txt && sed -r -i 's/’//' NFS_stales.txt

# Not used: replace space by a new line
# stales=`cat NFS_stales.txt && sed -r -i ':a;N;$!ba;s/ /\n /g' NFS_stales.txt`

# read NFS_stales.txt output file line by line then unmount stale by stale.
#    IFS='' (or IFS=) prevents leading/trailing whitespace from being trimmed.
#    -r prevents backslash escapes from being interpreted.
#    || [[ -n $line ]] prevents the last line from being ignored if it doesn't end with a \n (since read returns a non-zero exit code when it encounters EOF).

while IFS='' read -r line || [[ -n "$line" ]]; do
    echo "Unmounting due to NFS Stale file handle: $line"
    umount -fl $line
done < "NFS_stales.txt"
#EOF

答案3

我通常會發出這些命令(如root):

service nis restart
service autofs restart
service nfs restart
service portmap restart

您可能不需要所有這些,具體取決於您的系統的工作方式。

相關內容