Open hoyho opened 5 years ago
博主,我在Ubuntu 18.04.3 LTS上运行的时候遇到Error running pivot_root - invalid argument。 直接在shell上模拟:
# mount --bind /tmp/ns-pro/rootfs /tmp/ns-pro/rootfs
# pivot_root /tmp/ns-pro/rootfs /tmp/ns-pro/rootfs/.oldfs
报错:
pivot_root: failed to change root from /tmp/ns-pro/rootfs' to
/tmp/ns-pro/rootfs/.oldfs': Invalid argument
根据https://bugzilla.redhat.com/show_bug.cgi?id=1361043,
我尝试在pivot_root前执行“unshare -m”,然后才pass。
代码中是否也应该先进入新的namespace,然后syscall.PivotRoot?
@ql20060101 博主,我在Ubuntu 18.04.3 LTS上运行的时候遇到Error running pivot_root - invalid argument。 直接在shell上模拟:
# mount --bind /tmp/ns-pro/rootfs /tmp/ns-pro/rootfs # pivot_root /tmp/ns-pro/rootfs /tmp/ns-pro/rootfs/.oldfs
报错: pivot_root: failed to change root from
/tmp/ns-pro/rootfs' to
/tmp/ns-pro/rootfs/.oldfs': Invalid argument 根据https://bugzilla.redhat.com/show_bug.cgi?id=1361043, 我尝试在pivot_root前执行“unshare -m”,然后才pass。代码中是否也应该先进入新的namespace,然后syscall.PivotRoot?
redhat的链接也提到了Yes, due to migration to systemd we use "shared" as the default propagation for mount points.
这里用shell执行mount --bind /tmp/ns-pro/rootfs /tmp/ns-pro/rootfs
与demo是有点出入,
https://gitee.com/hoyho/ns-proc/blob/mount-5/container-fs.go#L28 这里其实用到了syscall.MS_BIND|syscall.MS_REC
,
// BIND remounts a subtree somewhere else.
BIND = unix.MS_BIND
// RBIND remounts a subtree and all possible submounts somewhere else.
RBIND = unix.MS_BIND | unix.MS_REC
MS_REC (since Linux 2.4.11) Used in conjunction with MS_BIND to create a recursive bind mount, and in conjunction with the propagation type flags to recursively change the propagation type of all of the mounts in a subtree. See below for further details.
这里通过指定mountflag 来改变了default propagation
根据文档描述http://man7.org/linux/man-pages/man8/mount.8.html:
The following commands allow one to recursively change the type of all the mounts under a given mountpoint. mount --make-rshared mountpoint mount --make-rslave mountpoint mount --make-rprivate mountpoint mount --make-runbindable mountpoint
所以我觉得可以把mount --bind 改为代码里的挂载参数(仅看文档猜测,未经实践🤪)
https://here2say.tw/39/
Hoyho's Blog,to record my coding life;D day