我注意到有一次,当我关闭我的家庭服务器,而我的桌面通过 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
您可能不需要所有这些,具体取决于您的系统的工作方式。