本文主要是介绍/etc/mtab与/proc/mounts,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
现在的 Linux 系统里一般都有这么三个文件:/etc/fstab,/etc/mtab,和 /proc/mounts,比较容易让人迷惑。简单解释一下。This file provides a list of all mounts in use by the system:
- rootfs / rootfs rw 0 0
- /proc /proc proc rw,nodiratime 0 0 none
- /dev ramfs rw 0 0
- /dev/mapper/VolGroup00-LogVol00 / ext3 rw 0 0
- none /dev ramfs rw 0 0
- /proc /proc proc rw,nodiratime 0 0
- /sys /sys sysfs rw 0 0
- none /dev/pts devpts rw 0 0
- usbdevfs /proc/bus/usb usbdevfs rw 0 0
- /dev/hda1 /boot ext3 rw 0 0
- none /dev/shm tmpfs rw 0 0
- none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
- sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw 0 0
The output found here is similar to the contents of /etc/mtab
, except that /proc/mount
is more up-to-date.
The first column specifies the device that is mounted, the second column reveals the mount point, and the third column tells the file system type, and the fourth column tells you if it is mounted read-only (ro
) or read-write (rw
). The fifth and sixth columns are dummy values designed to match the format used in/etc/mtab
.
2、/etc/mtab 是供 mount/umount 进行读写的,是相对动态的。读的话,比如你在挂载一个文件系统时缺少一个参数,它就会自动去/etc/mtab 或者 /etc/fstab 里去查,如果找到的话,只要一个参数也够。写的话,比如你umount了一个文件系统,umount 就会删掉/etc/mtab 里面的相关记录。
- With linux >= 2.6.26, /proc/mounts contains all of the information in
- /etc/mtab, plus more. The mount system call can now pass all of the mount
- options to the kernel, so no information is missing in /proc/mounts. This
- has obviously useful benefits such as read-only root, and the state in
- /etc/mtab never gets out of sync with reality (there are a number of open
- bugs against mount where this occurs).
- Additionally, with the addition of per-process namespaces with CLONE_NEWNS to
- clone(2), each process has its own set of mounts, and as such a system-wide
- /etc/mtab is useless: it's only valid in one of the potentially many
- namespaces and can quickly get into a horrible mess. At this point,
- /etc/mtab *must* be a symlink to avoid breakage. Note that /proc/mounts is
- now a symlink to /proc/self/mounts for this reason: each process has
- potentially different mounts.
所以,/etc/mtab 已经过时了,应该被抛弃,或者直接符号链接到/proc/mounts。同理,查看系统上挂载的文件系统的话,直接调用无参数的mount也是不妥的,因为那样也是读 /etc/mtab。我们应该使用 util-linux-ng 提供的一个新命令: findmnt,它是读的 /proc/self/mountinfo。
这篇关于/etc/mtab与/proc/mounts的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!