mount -a 和 mount -o remount /dir 有什么区别?

mount -a 和 mount -o remount /dir 有什么区别?

我创建了一个新的文件系统并挂载了它:

mount /dev/sda5 /dir

然后我将有关它的信息添加到 /etc/fstab 文件中,以便文件系统始终在启动过程中挂载。

vim /etc/fstab

保存 /etc/fstab 文件后,我看到建议执行以下操作:

mount -a

或者

mount -o remount /dir

这些命令之间有什么区别?修改 /etc/fstab 文件后我应该使用哪一个?

答案1

man mount说:

   -a, --all
          Mount all filesystems (of the given types) mentioned in fstab (except for those whose line contains the noauto keyword).  The filesystems are
          mounted following their order in fstab.

   remount
          Attempt to remount an already-mounted filesystem.  This is commonly used to change the mount flags for a filesystem,  especially  to  make  a
          readonly filesystem writable.  It does not change device or mount point.

          The  remount  functionality follows the standard way the mount command works with options from fstab.  This means that the mount command only
          doesn't read fstab (or mtab) when both the device and dir are specified.

          mount -o remount,rw /dev/foo /dir

          After this call all old mount options are replaced and arbitrary stuff from fstab (or mtab) is ignored, except  the  loop=  option  which  is
          internally generated and maintained by the mount command.

          mount -o remount,rw  /dir

          After  this call mount reads fstab and merges these options with the options from the command line (-o). If no mountpoint found in fstab than
          remount with unspecified source is allowed.

这就是区别所在。

现在,修改后应该使用什么/etc/fstab?嗯,这取决于情况。如果您有许多/etc/fstab未挂载的文件系统,mount -a则将全部挂载它们。这可能不是您想要的,但也可能正是您想要的。

如果/dir尚未挂载,您可以简单地mount /dir,这将保留在中提到的其余文件系统/etc/fstab

答案2

摘自 MAN 页面:

Unix 系统中可访问的所有文件都排列在一棵大树中,即文件层次结构,根为 /。这些文件可以分布在多个设备上。mount 命令用于将某个设备上的文件系统附加到大文件树中。相反,卸载 命令将再次将其分离。

山阿(通常在启动脚本中给出)会导致 fstab 中提到的所有文件系统(具有正确的类型和/或具有或不具有正确的选项)按指示挂载,但行中包含 noauto 关键字的文件系统除外。添加 -F 选项将使挂载分叉,以便同时挂载文件系统。挂载 fstab 或 mtab 中提到的文件系统时,只需提供设备或挂载点即可。

如果是安装-o重新安装/目录,调用 mount 时使用的完整挂载选项集由以下方法确定:首先从 fstab 表中提取文件系统的挂载选项,然后应用 -o 参数指定的任何选项,最后应用 -r 或 -w 选项(如果存在)。其中一些选项仅在出现在 /etc/fstab 文件中时才有用,而其中一些选项可能在系统内核中默认启用或禁用。要检查当前设置,请查看 /proc/mounts 中的选项。

重新挂载选项尝试重新挂载已挂载的文件系统。这通常用于更改文件系统的挂载标志,尤其是使只读文件系统可写。它不会更改设备或挂载点。

重新安装功能遵循 mount 命令使用 fstab 选项的标准方式。这意味着仅当设备和目录完全指定时,mount 命令才不会读取 fstab(或 mtab)。

因此,根据 MA​​N 页,它们之间的区别在于读取 fstab 文件,修改后,如果你想挂载它们,你应该使用安装 -a否则,如果您只想挂载一个目录,您应该使用其他选项。

相关内容