NFS Stale File Handles can be one of the most frustrating problems when it comes to network-attached storage (NAS). In this guide, we’ll talk about methods you can use to equip your NFS clients to recover automatically from stale file handle errors.
What is an NFS filehandle?
Basically, an NFS filehandle is a pointer on the NFS server to the actual file (or directory). In most instances, this pointer is an amalgamation of an inode, disk device, and inode generation of the referenced file on the server. As such, the filehandle is essentially meaningless to the NFS client that has an NFS share mounted.
What does «NFS Stale File Handle» error mean?
Again, filehandles are essentially meaningless to the client that is mounting an NFS share. Even if the client could decode the filehandle, the client doesn’t have direct access to the file system or disks on the NFS server and therefore that filehandle with its inode, disk, and inode generation data mean nothing to it. More importantly, an NFS client has no idea what other operations are going on with the files/directories it has mounted, so when a filehandle becomes invalid (or «stale»), the NFS server returns a «stale file handle» error in response to the client.
What causes an NFS «stale file handle» error?
We’ve established that a filehandle (which represents a file on a NFS server) contains information about the file’s inode, disk device, and inode generation on the NFS server. We’ve also established that a «stale file handle» error means that this reference is out-of-date or otherwise invalid.
So what could cause this reference to go out of date and no longer be valid? I.e. What causes an NFS stale file handle error?
The answer is any change in the mounted file’s underlying inode, disk device, or inode generation on the NFS server causes an NFS stale filehandle.
How To Automatically Fix NFS Stale File Handle Errors
When it comes to NFS stale file handle errors, an «ounce of prevention is worth a pound of cure». It’s always best to understand how your NFS shares are being used, but that’s another topic for another time. Besides, unfortunately, these errors can’t always be prevented.
So here’s how to better equip your NFS clients to automatically resolve stale file handle errors when they happen (and they will).
First, if you’re here for just a one-off fix, you can resolve the issue with:
umount -l /path/to/NFS/mount/here
But let’s say you don’t to want to have to actively seek out stale NFS mounts and want your Linux NFS client to just handle it automatically. Here’s what to do.
- Create a new script:
nano /home/engineer/Desktop/staleHandleDestroyer
- Copy and paste the following:
#! /bin/bash
list=$(df 2>&1 | grep 'Stale file handle' | awk '{print ""$2"" }' | tr -d :)
for directory in $list
do
umount -l "$directory"
mount -a
done
It’s hard to create a one-size-fits-all script because a lot of it depends on how the client is accessing the NFS share, but this should work for the majority of Linux/Ubuntu/Debian installations. If you want to discuss your specific use case, please comment below!
- Make it executable:
sudo chmod +x /home/engineer/Desktop/staleHandleDestroyer
- Add it as a root cron job:
sudo crontab -e
*/5 * * * * /home/engineer/Desktop/staleHandleDestroyer
The above cron job will run every five minutes, searching for stale file handles. If it finds a stale file handle, it will automatically unmount them (lazy umount is safest, so that’s what I use above) and then attempt to remount. If five minutes is too long for you, then you can use * * * * * /home/engineer/Desktop/staleHandleDestroyer instead which will run q1m (every minute).
If that’s still too long for you, then we should talk about preventing this from happening in the first place…
Additional Resources
- Managing NFS and NIS by Mike Eisler
The most complete and definitive resource on understanding the Network File System (NFS) anywhere. Covers everything from networking fundamentals, NFS theory (including design and operation), security, and NFS troubleshooting and performance. Definitely worth buying and having on hand.
- Setting Up and Securing an unRAID NFS Server
- Forum Topics on NFS
And as always, if you need any help or want to discuss your specific NFS deployment, drop a comment below!
And if you have a question or want to discuss anything else, be sure to check out The Engineer’s Workshop forums!
Learn how to resolve mount.nfs: Stale file handle error on the Linux platform. This is a Network File System error that can be resolved from the client or server end.

When you are using the Network File System in your environment, you must have seen mount.nfs: Stale file handle error at times. This error denotes that the NFS share is unable to mount since something has changed since the last good known configuration.
Whenever you reboot the NFS server or some of the NFS processes are not running on the client or server or share is not properly exported at the server; these can be reasons for this error. Moreover, it’s irritating when this error comes to a previously mounted NFS share. Because this means the configuration part is correct since it was previously mounted. In such case once can try the following commands:
Make sure NFS service are running good on client and server.
# service nfs status rpc.svcgssd is stopped rpc.mountd (pid 11993) is running... nfsd (pid 12009 12008 12007 12006 12005 12004 12003 12002) is running... rpc.rquotad (pid 11988) is running...
If NFS share currently mounted on the client, then un-mount it forcefully and try to remount it on NFS client. Check if its properly mounted by df command and changing directory inside it.
# umount -f /mydata_nfs # mount -t nfs server:/nfs_share /mydata_nfs #df -k ------ output clipped ----- server:/nfs_share 41943040 892928 41050112 3% /mydata_nfs
In above mount command, server can be IP or hostname of NFS server.
If you are getting error while forcefully un-mounting like below :
# umount -f /mydata_nfs umount2: Device or resource busy umount: /mydata_nfs: device is busy umount2: Device or resource busy umount: /mydata_nfs: device is busy
Then you can check which all processes or users are using that mount point with lsof command like below:
# lsof |grep mydata_nfs
lsof: WARNING: can't stat() nfs file system /mydata_nfs
Output information may be incomplete.
su 3327 root cwd unknown /mydata_nfs/dir (stat: Stale NFS file handle)
bash 3484 grid cwd unknown /mydata_nfs/MYDB (stat: Stale NFS file handle)
bash 20092 oracle11 cwd unknown /mydata_nfs/MPRP (stat: Stale NFS file handle)
bash 25040 oracle11 cwd unknown /mydata_nfs/MUYR (stat: Stale NFS file handle)
If you see in above example that 4 PID are using some files on said mount point. Try killing them off to free mount point. Once done you will be able to un-mount it properly.
Sometimes it still gives the same error for mount command. Then try mounting after restarting NFS service at the client using the below command.
# service nfs restart Shutting down NFS daemon: [ OK ] Shutting down NFS mountd: [ OK ] Shutting down NFS quotas: [ OK ] Shutting down RPC idmapd: [ OK ] Starting NFS services: [ OK ] Starting NFS quotas: [ OK ] Starting NFS mountd: [ OK ] Starting NFS daemon: [ OK ] Starting RPC idmapd: [ OK ]
Also read : How to restart NFS step by step in HPUX
Even if this didn’t solve your issue, final step is to restart services at the NFS server. Caution! This will disconnect all NFS shares which are exported from the NFS server. All clients will see the mount point disconnect. This step is where 99% of you will get your issue resolved. If not then NFS configurations must be checked, provided you have changed configuration and post that you started seeing this error.
Outputs in above post are from RHEL6.3 server. Drop us your comments related to this post.
Материал из Пингвиньи радостей
Перейти к: навигация, поиск
Статья о пакете Nfs-common
Nfs-common это пакет реализующий NFS-клиента в Linux и предоставляющий общие файлы для NFS-сервера.
Nfs-common используется для подключения к NFS-серверу например Nfs-kernel-server.
В пакет включены программы: lockd, statd, showmount, nfsstat, gssd и idmapd.
Установка
Пакет присутствует в хранилище пакетов debian.
Для установки пакета
- в командной строке: следует выполнить команду # apt-get install nfs-common
- в графическом режиме: воспользоваться специализированной программой управления пакетами
После установки пакет готов к использованию.
Некоторые часто используемые программы
# /etc/init.d/nfs-common restart - перезапуск nfs-клиента # mount.nfs IP-SERVER:/share /mnt/ - монтирование ресурса /share сервера IP-SERVER в точку /mnt # showmount - отображение подключённых клиентов # nfsstat -s - отображение статистику nfs-клиента
Для автоматического подключения NFS-ресурсов через файл /etc/fstab
- в файл /etc/fstab добавляется строка
# устройство точка монтирования тип ФС параметры dump fsckorder IP-SERVER:/share /mnt nfs rsize=1024,wsize=1024,hard,intr 0 0
Замечание: Подробное описание параметров монтирования ресурсов по протоколу NFS приведено в статье Mount.
Устранение ошибки Stale NFS file handle
При возникновении ошибки Stale NFS file handle следует установить раздельный fsid=num в файле /etc/exports сервера nfs для ресурсов находящихся на одном UUID, например на одном разделе жёсткого диска.
Литература
- NFSv4
Справочная информация
- 03.04.2014: Nfs-common: создание статьи о пакете реализующем NFS-клиента