有任何方法可以查看或操作任意进程的挂载命名空间吗?
例如,一个具有NFS服务器本地挂载的码头容器正在运行。它可以从容器内部看到,但在外部,主机不知道它。对于网络命名空间,这是可行的。例如管道工程
但是,对于挂载命名空间,我没有看到任何相关信息。是否有一个API或sysfs层公开以查看这些挂载并操作或创建新的挂载?
发布于 2014-11-06 00:53:49
是。您可以查看它的/proc/$PID/mountinfo,或者可以使用findmnt -N开关-- findmnt --help说:
-N, --task <tid> /proc/<tid>/mountinfo文件)findmnt还跟踪PROPAGATION标志,该标志是一个mountinfo字段,该字段准确地报告此信息-进程共享该挂载。
此外,您可以始终nsenter任何类型的名称空间您喜欢-当然,只要您有正确的权限。
nsenter --help
Usage:
nsenter [options] <program> [args...]
Options:
-t, --target <pid> target process to get namespaces from
-m, --mount [=<file>] enter mount namespace
-u, --uts [=<file>] enter UTS namespace (hostname etc)
-i, --ipc [=<file>] enter System V IPC namespace
-n, --net [=<file>] enter network namespace
-p, --pid [=<file>] enter pid namespace
-U, --user [=<file>] enter user namespace
-S, --setuid <uid> set uid in user namespace
-G, --setgid <gid> set gid in user namespace
-r, --root [=<dir>] set the root directory
-w, --wd [=<dir>] set the working directory
-F, --no-fork do not fork before exec'ing <program>
-h, --help display this help and exit
-V, --version output version information and exit
For more details see nsenter(1).发布于 2019-12-10 19:24:23
内核还为给定pid/tid:/proc//root/的挂载命名空间的特定情况提供了简单的直接访问。
这是指向该进程的根( / )目录的链接,包括所有挂载点(它显示为指向/的符号链接,但实际上解析到进程‘/,就像/proc/<pid>/fd/中已删除文件的行为符号链接)。
例如,如果主机和/或容器之间没有可用的环境和命令(例如: no ),就可以方便地复制这些文件。在使用nsenter时,这是不可能的,至少以后没有一个专门的软件不依赖于fork/exec。
https://unix.stackexchange.com/questions/165588
复制相似问题