#!/bin/sh arch=aarch64 rootpath=/home/jejb/tmp ctrl=/run/build-container while true; do case $1 in --arch) arch=$2; shift; shift ;; --rootpath) rootpath=$2; shift; shift ;; *) break;; esac done ctroot=$rootpath/$arch root=$ctrl/root-$arch if [ "$1" == "in-ct" ]; then mount --bind $ctroot $root mkdir $root$ctrl for f in /dev /dev/pts /proc /sys /home $ctrl /var/tmp /etc/resolv.conf; do mount --bind $f ${root}${f} mount --make-rprivate ${root}${f} done mount --bind /usr/bin/qemu-$arch $root/qemu-$arch cd $root mkdir old-root pivot_root . old-root mount --make-rprivate /old-root umount -l /old-root # spawn an undying process into the mount namespace as me to keep it alive sleep 365d & pid=$! # create a link to allow entry ln -s /proc/$pid/ns/mnt $ctrl/$arch else if [ -e $ctrl/$arch ]; then echo "Error: $ctrl/$arch exists, is container running?" exit 1; fi if [ ! -d $ctrl ]; then mkdir $ctrl || exit 1 fi if grep -q "$ctrl tmpfs" /proc/self/mounts; then : else mount -t tmpfs none $ctrl || exit 1 fi mount --make-rprivate $ctrl mkdir $root unshare --mount $0 --arch $arch --rootpath $rootpath in-ct rmdir $root fi