大网数据广告活动
服务器运维问答

Implications of `mount --make-private /`

· 52CE 我爱测

Currently, / has shared mount propagation: # findmnt -o TARGET,PROPAGATION / TARGET PROPAGATION / shared I am considering changing it to private to enable mount --move to work on filesystems mounted under /mnt and /media . (I wan…

问题原文

原帖链接 · Tom Hale · CC BY-SA 3.0

Currently, / has shared mount propagation:

# findmnt -o TARGET,PROPAGATION /
TARGET PROPAGATION
/      shared

I am considering changing it to private to enable mount --move to work on filesystems mounted under /mnt and /media.

(I want to use mount --move rather than the unsafe umount --lazy)

Without / being private, mount --move will complain with something like:

# mount --move /mnt/mountpoint /mnt/moved
mount: /mnt/moved: bad option; moving a mount residing under a shared mount is unsupported.
  1. Why is / shared by default?

  2. What are the implications of changing / to be private?

已采纳解答

原帖链接 · Andrii L. · CC BY-SA 3.0

The propagation flag is changed by systemd. From man 7 mount_namespaces:

systemd(1) automatically remounts all mount points as MS_SHARED on system startup. Thus, on most modern systems, the default propagation type is in practice MS_SHARED.

From https://github.com/systemd/systemd/blob/master/src/core/mount-setup.c#L406

  /* Mark the root directory as shared in regards to mount propagation. The kernel defaults to "private", but we
     * think it makes more sense to have a default of "shared" so that nspawn and the container tools work out of
     * the box. If specific setups need other settings they can reset the propagation mode to private if
     * needed. Note that we set this only when we are invoked directly by the kernel. If we are invoked by a
     * container manager we assume the container manager knows what it is doing (for example, because it set up
     * some directories with different propagation modes). */
    if (detect_container() <= 0)
            if (mount(NULL, "/", NULL, MS_REC|MS_SHARED, NULL) < 0)

The implications depend on your particular use cases. I think that most programs will continue to work. However, your change will be overwritten on reboot.

You can read more in the comment from Lennart Poettering in https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=739593

Here is a part of it:

b) If you patch systemd to go back to MS_PRIVATE for the root dir, you disable propagation to containers, and nobody can opt-in to it anymore for their specific namespace.

Advantage: you don't have to patch those few programs which currently assume the root dir is MS_PRIVATE and don't disassociate things.

Disadvantage: the apps are still broken for those who switch to MS_SHARED for /. You hence only cover the usecases where people do not dissassocitate. You break the usecase where people want the propagation to tkae place.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-08-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。