/etc/mtab 文件

对 /etc/mtab 文件的第一印象

一直以来对 /etc/mtab 文件的认识只是了解它存储的是当前系统中挂载的分区情况,与 /etc/fstab 不同的地方在于它表示的是系统中分区挂载的实时情况,而 /etc/fstab 则一旦配置完成就不会改变。

这个理解相当肤浅,在这里从 manual 中摘录如下描述,算是补上对 /etc/mtab 欠缺的一些知识。

manual 中的信息

When mounting a filesystem mentioned in fstab or mtab, it suffices to specify on the command line only the device, or only the mount point.

The programs mount and umount traditionally maintained a list of currently mounted filesystems in the file /etc/mtab. The support for regular classic /etc/mtab is completely disabled in compile time by default, because on current Linux systems it is better to make it a symlink to /proc/mounts instead. The regular mtab file maintained in userspace cannot reliably work with namespaces, containers and other advanced Linux features. If the regular mtab support is enabled than it’s possible to use the file as well as the symlink.

上述 manual 中的主要信息如下:

  1. mount 与 unmount 程序使用 /etc/mtab 维护当前已经挂载的文件系统列表
  2. 现在的 linux 系统将 /etc/mtab 设定为一个指向 /proc/mounts 的链接文件而非普通文件
  3. 以前的 /etc/mtab 用户态文件管理方式不能与命名空间、容器及其他 linux 高级特性很好的合作

在我系统中的验证

ls -lh 查看 /etc/mtab 文件得到了如下输出信息:

longyu@debian:~$ ls -lh /etc/mtab lrwxrwxrwx 1 root root 19 Mar 23 12:45 /etc/mtab -> ../proc/self/mounts

可以看到 /etc/mtab 是指向 /proc/self/mounts 文件的一个软链接。我们可以想象在不同的容器中有不同的 /proc/self/mounts 文件,表示不同的文件系统挂载情况,这时 /etc/mtab 仍旧能够正常工作,不需要任何额外的修改、适配。

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值