Skip to content

Instantly share code, notes, and snippets.

@dbeecham
Created November 19, 2019 10:58
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dbeecham/183c122059f7ba288397e8c3320234d3 to your computer and use it in GitHub Desktop.
Save dbeecham/183c122059f7ba288397e8c3320234d3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
if test ! -d ./overlay; then
read -p "No overlay found here. Want to create one? (y/N)" yn
case $yn in
[Yy]* ) install -d overlay/upperdir && install -d overlay/workdir && install -d overlay/mnt; break;;
* ) exit;;
esac
fi
if test ! -d ./overlay/upperdir; then
echo "Missing overlay/upperdir. Broken overlay?"
exit
fi
if test ! -d ./overlay/workdir; then
echo "Missing overlay/workdir. Broken overlay?"
exit
fi
if test ! -d ./overlay/mnt; then
echo "Missing overlay/mnt. Broken overlay?"
exit
fi
echo "Entering own mount namespace..."
sudo unshare -m sh -c "echo 'Mounting local overlay...' && \
mount -t overlay overlay -o upperdir=$(pwd)/overlay/upperdir,workdir=$(pwd)/overlay/workdir,lowerdir=/ $(pwd)/overlay/mnt && \
mount -o bind /sys overlay/mnt/sys && \
mount -t proc none overlay/mnt/proc && \
mount -o bind /dev overlay/mnt/dev && \
mount -o bind /dev/pts overlay/mnt/dev/pts && \
echo 'chrooting...' && \
sudo chroot overlay/mnt sh -c 'export action=\"(chroot) \"; cd $(pwd) && sudo -E -u $(whoami) $SHELL'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment