X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=overlay-boot;h=6577cadf387a658b182b8a928ee257ab3274f9cb;hb=6a9450df1427e9a9fb5e4810ceab4ceeef93b6f9;hp=44bc76f0ec71873e73167f347bbb988dc3533dbd;hpb=f86ce1827c0f74b3ac15598946b41477dd5a4066;p=rrq%2Foverlay-boot.git diff --git a/overlay-boot b/overlay-boot index 44bc76f..6577cad 100755 --- a/overlay-boot +++ b/overlay-boot @@ -23,6 +23,7 @@ fi subhost_config setup_veth_cables $NAME $CABLES setup_overlay "$NAME" "$LIVE" "$LOWER" "$UPPER" "$WORK" +setup_cgroup2_accounting "$NAME" "$$" exithandler() { ip netns del $NAME @@ -30,7 +31,19 @@ exithandler() { } trap "exithandler" 0 -CMD="unshare -fp --mount-proc -i -u ip netns exec $NAME chroot $LIVE /bin/sh" -echo "$CMD" -env CONFIG="$CONFIG" $INIT | $CMD -echo "EXITED $CMD" +# This process has an unshared mount namespace, so we unmount almost +# everything before chroot. Exceptions are: $LIVE and anything mounted +# below that, "/run/netns/$NAME" and its parent paths (incidentally +# including "/" as well) and "/proc". +sort -rk2,2 < /proc/mounts | while read D P A2 ; do + beginswith "$P" "$LIVE" && continue + beginswith "/run/netns/$NAME" "$P" && continue + [ "$P" = /proc ] && continue + umount "$P" +done + +echo "Starting $NAME" +env CONFIG="$CONFIG" $INIT | \ + unshare -fp --mount-proc -i -u \ + ip netns exec $NAME chroot $LIVE /bin/sh +echo "Exited $NAME"