Can't get mount namespaces to behave as expected
Can't get mount namespaces to behave as expected
Posted Mar 5, 2015 9:25 UTC (Thu) by mkerrisk (subscriber, #1978)In reply to: Can't get mount namespaces to behave as expected by apollock
Parent article: Namespaces in operation, part 4: more on PID namespaces
@apollock: yes, I recently commented on this in another article in this series. Basically, some distros (e.g., Fedora) these days enable mount propagation by default, which means that when you mount /proc in the new mount namespace, you do indeed clobber /proc in the initial mount namespace.
So, in the new namespace, you need to disable propagation of mount events on /, either by making it a private mount (prevents propagation in both directions) or by making it a slave mount (allows propagation of mounts events under / into the new namespace, but doesn't propagate events outside the new namespace. So, for example, in the shell session under the heading Mounting a procfs filesystem (revisited), we should add one further shell command:
# ./ns_child_exec -p -m ./simple_init init$ mount --make-slave / # <== NEW init$ mount -t proc proc /proc init$ ps a
For more info about mount propagation, see the kernel source file Documentation/filesystems/sharedsubtree.txt and the mount(8) man page.
