admin | 世界杯冰岛
对 /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 中的主要信息如下:
mount 与 unmount 程序使用 /etc/mtab 维护当前已经挂载的文件系统列表现在的 linux 系统将 /etc/mtab 设定为一个指向 /proc/mounts 的链接文件而非普通文件以前的 /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 仍旧能够正常工作,不需要任何额外的修改、适配。