意外删除了 /proc/self/mounts 的软链接

可能会出现 /etc/mtab 文件的软链接被意外删除,导致 df 无法工作的情况。
它还可能通过使其无法启动而严重影响服务器。
要解决此问题,我们可以使用以下命令重新创建符号链接:

# rm -f /etc/mtab
# ln -s /proc/self/mounts /etc/mtab
on  It Road.com

如何恢复损坏或者删除的 /etc/mtab 文件

  1. 为了重新创建 /etc/mtab 文件,我们只需将 /proc/mounts 内容复制到 /etc/mtab 文件。
    换句话说,将内核的挂载表复制到挂载表文件中:
# cp /proc/mounts /etc/mtab

/proc/mounts 是所有文件系统的内核视图,而文件 /etc/mtab 是当前挂载的文件系统的配置文件。
所以 /proc/mounts 可以更准确地查看当前挂载的所有文件系统。
它还具有挂载这些文件系统时使用的完整选项集。

如何从 CentOS/RHEL 7 中损坏或者空的 /etc/mtab 文件中恢复

有时我们可能会在运行 df 命令时收到错误消息,指出 /etc/mtab 文件已损坏或者为空(已删除)。
可能是有人不小心编辑了 /etc/mtab 文件并且数据不正确。
好吧,这篇文章将恢复正确的 mtab 文件。

/etc/mtab文件有什么用

在开始之前,让我们看看什么是 mtab 文件。
/etc/mtab 是维护当前挂载的文件系统列表的文件。
因此,当我们运行“df”命令时,它会引用此文件为我们生成输出。
术语“mtab”指的是“已挂载文件系统表”。
mtab 文件有一个指向文件 /proc/self/mounts 的软链接。

# ls -lrt /etc/mtab
lrwxrwxrwx. 1 root root 17 Sep 29  2014 /etc/mtab -> /proc/self/mounts

还有另一个名为“/proc/mounts”的文件,它也软链接到文件“/proc/self/mounts”。

# ls -lrt /proc/mounts
lrwxrwxrwx. 1 root root 11 Jun 11 11:49 /proc/mounts -> self/mounts

/proc/mounts 是内核对挂载点的看法。
所以它的类型存储在系统的实时内存中。
对于 mount 的手册页:

# man mount 
...
It is possible that files /etc/mtab and /proc/mounts don’t match. The first file is based only on
the mount command options, but the content of the second file also depends on the kernel and oth
ers settings (e.g.  remote NFS server. In particular case the mount command may reports unreliable
information about an NFS mount point and the  /proc/mounts  file  usually  contains  more  reliable
information.)
日期:2020-09-17 00:13:46 来源:oir作者:oir