오래된 nfs 핸들을 어떻게 해결할 수 있나요?

오래된 nfs 핸들을 어떻게 해결할 수 있나요?

데스크탑이 NFS를 통해 연결된 동안 홈 서버를 종료했을 때 홈 디렉토리에 들어갈 때 "오래된 NFS 핸들 경고"가 계속 표시되는 것을 한 번 발견했습니다. 이로 인해 해당 폴더를 찾는 일부 프로그램에 문제가 발생했습니다.

컴퓨터를 다시 시작하지 않고 이 문제를 어떻게 해결합니까?

데비안 스퀴즈/Wheezy

답변1

Debian Squeeze/Wheezy에서:

로컬 마운트를 강제로 마운트 해제합니다.

umount -f /mnt/dir

그런 다음 nfs를 다시 시작하십시오.

/etc/init.d/nfs-common restart

답변2

이 쉘 스크립트를 사용해보십시오. 나에게 잘 맞는다:

#!/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

시스템 작동 방식에 따라 이러한 기능이 모두 필요하지 않을 수도 있습니다.

관련 정보