/etc/mtab与/proc/mounts

2024-03-11 10:58
文章标签 proc etc mounts mtab

本文主要是介绍/etc/mtab与/proc/mounts,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

现在的 Linux 系统里一般都有这么三个文件:/etc/fstab,/etc/mtab,和 /proc/mounts,比较容易让人迷惑。简单解释一下。

This file provides a list of all mounts in use by the system:

[cpp] view plain copy
  1. rootfs / rootfs rw 0 0   
  2. /proc /proc proc rw,nodiratime 0 0 none   
  3. /dev ramfs rw 0 0   
  4. /dev/mapper/VolGroup00-LogVol00 / ext3 rw 0 0   
  5. none /dev ramfs rw 0 0   
  6. /proc /proc proc rw,nodiratime 0 0   
  7. /sys /sys sysfs rw 0 0   
  8. none /dev/pts devpts rw 0 0   
  9. usbdevfs /proc/bus/usb usbdevfs rw 0 0   
  10. /dev/hda1 /boot ext3 rw 0 0   
  11. none /dev/shm tmpfs rw 0 0   
  12. none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0   
  13. 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.

1、/etc/fstab 是只读不写的,它仅仅是开机时的配置文件,它提供的是系统上挂载设备的静态信息,比如 mount -a 就会挂载 /etc/fstab 里面指定的文件系统。

2、/etc/mtab 是供 mount/umount 进行读写的,是相对动态的。读的话,比如你在挂载一个文件系统时缺少一个参数,它就会自动去/etc/mtab 或者 /etc/fstab 里去查,如果找到的话,只要一个参数也够。写的话,比如你umount了一个文件系统,umount 就会删掉/etc/mtab 里面的相关记录。
[cpp] view plain copy
  1. With linux >= 2.6.26, /proc/mounts contains all of the information in   
  2. /etc/mtab, plus more.  The mount system call can now pass all of the mount   
  3. options to the kernel, so no information is missing in /proc/mounts.  This   
  4. has obviously useful benefits such as read-only root, and the state in   
  5. /etc/mtab never gets out of sync with reality (there are a number of open   
  6. bugs against mount where this occurs).  
  7.   
  8.   
  9. Additionally, with the addition of per-process namespaces with CLONE_NEWNS to   
  10. clone(2), each process has its own set of mounts, and as such a system-wide   
  11. /etc/mtab is useless: it's only valid in one of the potentially many   
  12. namespaces and can quickly get into a horrible mess.  At this point,   
  13. /etc/mtab *must* be a symlink to avoid breakage.  Note that /proc/mounts is   
  14. now a symlink to /proc/self/mounts for this reason: each process has  
  15. potentially different mounts.  
3、看似上面的这两个文件已经够用了,但是新的情况出现了。Linux 内核引入了一个 mount namespace,是给container用的。因为这个的出现,Linux 不得不引入 /proc/mounts。为什么呢?因为记录 mount 信息的 /etc/mtab 是全局的,也就是说,就算你的某个进程有自己的 namespace,但只要还和外面共享同一个 /etc/mtab,那么,里面进行umount/mount操作的信息也会被记录到/etc/mtab里,外面也会看到!凌乱了!由此可见,我们不能有全局的mtab,肿么办呢?/proc/mounts 出来了,有人可能觉得它也是全局的啊!可你仔细看一下的话会发现,它其实是到 /proc/self/mounts 的一个符号链接!如此以来,container 里面的 /proc/mounts 和外面的当然就不会一样了!聪明啊!

所以,/etc/mtab 已经过时了,应该被抛弃,或者直接符号链接到/proc/mounts。同理,查看系统上挂载的文件系统的话,直接调用无参数的mount也是不妥的,因为那样也是读 /etc/mtab。我们应该使用 util-linux-ng 提供的一个新命令: findmnt,它是读的 /proc/self/mountinfo。

这篇关于/etc/mtab与/proc/mounts的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/797617

相关文章

linux配置DNS解析设置之配置文件“/etc/resolv.conf “

在 Linux 系统中,/etc/resolv.conf 文件用于配置系统的 DNS 解析设置。它定义了如何将主机名(例如 www.example.com)转换为 IP 地址。主要功能包括: 主要功能 DNS 服务器地址:指定系统用于查询域名的 DNS 服务器。你可以在该文件中列出一个或多个 DNS 服务器的 IP 地址。 示例内容: conf 复制代码 nameserver 8.

解决git error: could not lock config file C:/Program Files/Git/mingw64/etc/gitconfig: Permission denie

昨天电脑中毒重装了系统,安装了 git 之后  设置了账户 ,邮箱 在 git clone 的时候报错, 界面如下: 然后重新用户,邮箱, 出现了这个问题,百度了很久也没解决,今天早上想着这个英文的意思 好像是权限不够,然后 我就去提示的这个文件夹下面 给了全部的权限,本人是window10 系统  给的是everyone 所有 之后在  git config --syste

Linux C 内核编程 /proc 编程例子

直接上代码 proc_demo.c内核版本: 5.4.0-150-generic #include <linux/module.h>#include <linux/sched.h>#include <linux/proc_fs.h>#include <linux/seq_file.h>#include <linux/uaccess.h>#include <linux/slab.h>s

浅析linux下的/etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc文件

浅析linux下的/etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc文件 /etc/profile:此文件为 系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.  并从/etc/profile.d目录的配置文件中搜集shell的设置.  /etc/bashrc:为每一个运行bash shell的用户执行此文件.当bas

etc/profile和/etc/environment的比较

先将export LANG=zh_CN加入/etc/profile ,退出系统重新登录,登录提示显示英文。 将/etc/profile 中的export LANG=zh_CN删除,将LNAG=zh_CN加入/etc/environment,退出系统重新登录,登录提示显示中文。 用户环境建立的过程中总是先执行/etc/profile然后在读取/etc/environment。为什么

/etc/profile和 . profile 文件

两个重要的profile文件 在UNIX/Xenix系统中有两个对用户而言必不可少的文件——etc目录下的profile文件和 用户主目录($HOME)下的.profile文件。前者是系统文件,对系统下全体用户起作用,后者是 用户自己的"私人"文件。 这两个文件的功能类似于DOS系统下的Autoexec.bat文件,不同之处在于Autoexec.bat文 件可以为空,而这两个

Ubuntu配置文件/etc/profile说明

对于/etc/profile这个文件,是系统启动是要自动执行的文件,任何一个用户登录系统都会执行这个文件。这个文件里面的配置,是全局配置。所以,如果你需要让你的变量让所有的用户都能使用的话,那么可以考虑在此配置文件里面添加。比如JAVA_HOME变量的配置。但是,尽量的,我们不要去修改这个配置文件,因为这个是系统的配置文件。我们尽量的修改我们自己独立配置文件。在可能的时候,或者重新配置的时候

Linux中全局变量配置,/etc/profile.d还是/etc/profile

全局环境变量可以放在 /etc/profile 或 /etc/profile.d/ 中,但两者的使用方式和目的有所不同: /etc/profile 作用: /etc/profile 是一个系统范围的启动脚本,在用户登录时执行。它主要用于设置全局环境变量和配置,适用于所有用户。 适用情况: 当你需要在所有用户登录时设置全局环境变量或其他全局配置时,可以将这些设置放在 /etc/profile

linux系统下从/proc中找回误删除的控制文件

--linux系统下从/proc中找回误删除的控制文件SYS@PROD3> select name from v$controlfile;NAME----------------------------------------------------------------------------------------------------/home/oracle/db1/control0

linux系统修改/etc/profile,修改错了,再打开乱码

执行vim /etc/profile, 在文件末尾增加两行配置,可能是$符号写错了,输入:x保存,提示输入密码(help cm),然后输入两次cm  执行source /etc/profile  提 示文件错误字段 执行cat profile结果如下: 这有没有办法还原啊? echo $PATH所有路径都正常。