如何解决 “mount.nfs: Stale file handle”错误
NFS

> 
> 了解如何解决 Linux 平台上的 `mount.nfs: Stale file handle` 错误。这个 NFS 错误可以在客户端或者服务端解决。
> 
> 
> 


![](/data/attachment/album/201804/09/214625b5d8hqh1re1b1uhs.jpg)


当你在你的环境中使用网络文件系统时，你一定不时看到 `mount.nfs：Stale file handle` 错误。此错误表示 NFS 共享无法挂载，因为自上次配置后有些东西已经更改。


无论是你重启 NFS 服务器或某些 NFS 进程未在客户端或服务器上运行，或者共享未在服务器上正确输出，这些都可能是导致这个错误的原因。此外，当这个错误发生在先前挂载的 NFS 共享上时，它会令人不快。因为这意味着配置部分是正确的，因为是以前挂载的。在这种情况下，可以尝试下面的命令：


确保 NFS 服务在客户端和服务器上运行良好。



```
#  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...

```

如果 NFS 共享目前挂载在客户端上，则强制卸载它并尝试在 NFS 客户端上重新挂载它。通过 `df` 命令检查它是否正确挂载，并更改其中的目录。



```
# 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

```

在上面的挂载命令中，服务器可以是 NFS 服务器的 IP 或[主机名](https://kerneltalks.com/linux/all-you-need-to-know-about-hostname-in-linux/)。


如果你在强制取消挂载时遇到像下面错误：



```
# 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

```

然后你可以用 `lsof` 命令来检查哪个进程或用户正在使用该挂载点，如下所示：



```
# 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)

```

如果你在上面的示例中看到共有 4 个 PID 正在使用该挂载点上的某些文件。尝试杀死它们以释放挂载点。完成后，你将能够正确卸载它。


有时 `mount` 命令会有相同的错误。接着使用下面的命令在客户端重启 NFS 服务后挂载。



```
#  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  ]

```

另请阅读：[如何在 HPUX 中逐步重启 NFS](http://kerneltalks.com/hpux/restart-nfs-in-hpux/)


即使这没有解决你的问题，最后一步是在 NFS 服务器上重启服务。警告！这将断开从该 NFS 服务器输出的所有 NFS 共享。所有客户端将看到挂载点断开。这一步将 99％ 解决你的问题。如果没有，请务必检查 [NFS 配置](http://kerneltalks.com/linux/nfs-configuration-linux-hpux/)，提供你修改的配置并发布你启动时看到的错误。


上面文章中的输出来自 RHEL6.3 服务器。请将你的评论发送给我们。




---


via: <https://kerneltalks.com/troubleshooting/resolve-mount-nfs-stale-file-handle-error/>


作者：[KernelTalks](https://kerneltalks.com) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
*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.*

![](https://z5.kerneltalks.com/wp-content/uploads/2020/06/nfs_error-2.png)

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 ](https://kerneltalks.com/linux/all-you-need-to-know-about-hostname-in-linux/)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](https://kerneltalks.com/hpux/restart-nfs-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](https://kerneltalks.com/linux/nfs-configuration-linux-hpux/) 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.

Thanks guys, for breaking the NFS mount problem down for me, it resolved my problem.