Linux 命令“mount -a”如何工作?

Rau*_*auf 12 linux partition mount fstab

在 中添加新的挂载点后/etc/fstab,我们通常会执行mount -a以反映更改(如果我们想绕过重启),并且df -kh输出会显示新的挂载点。

如何mount -a工作/影响已安装的分区,这些分区引用了 /etc/fstab文件?它是先卸载然后挂载这些分区,还是因为它们已经挂载而忽略它们?

ste*_*eve 19

它跳过已经安装的。

https://github.com/karelzak/util-linux/blob/master/sys-utils/mount.c#L185-L193

while (mnt_context_next_mount(cxt, itr, &fs, &mntrc, &ignored) == 0) {

    const char *tgt = mnt_fs_get_target(fs);

    if (ignored) {
        if (mnt_context_is_verbose(cxt))
            printf(ignored == 1 ? _("%-25s: ignored\n") :
                          _("%-25s: already mounted\n"),
                   tgt);
    }
    // ...
}
Run Code Online (Sandbox Code Playgroud)


dar*_*urf 5

它将忽略已安装的分区。

同时,你可以mount -o remount /dev/xxx在已经挂载的分区上做一个,即使用户正在使用这个分区也不会有任何问题