Last active
November 22, 2016 06:30
-
-
Save vishalbiswas/09c76fa44dcea2205f3d6a935d2794ee to your computer and use it in GitHub Desktop.
script for easy chrooting. adapted from an answer on stackoverflow which I can't find anymore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -z "$1" ]; then | |
echo "Usage: $0 CHROOT_PATH [PROGRAM]" | |
exit 1 | |
fi | |
CHROOT_PATH="$1" | |
PROGRAM="$2" | |
BIND_DIRS="/proc /dev /dev/pts /dev/shm" | |
start() | |
{ | |
for DIR in $BIND_DIRS; do | |
echo "Binding $DIR to ${CHROOT_PATH}${DIR}" | |
mkdir -p "${CHROOT_PATH}${DIR}" | |
mount --bind "$DIR" "${CHROOT_PATH}${DIR}" | |
done | |
} | |
stop() | |
{ | |
# Unmount in reverse order | |
for DIR in `echo "$BIND_DIRS" | sed -e 's/ /\n/g' | tac`; do | |
echo "Ubinding ${CHROOT_PATH}${DIR}" | |
umount "${CHROOT_PATH}${DIR}" | |
done | |
} | |
start | |
echo "Chroot..." | |
export LC_ALL=C | |
me=`whoami` | |
chroot --userspec=$me:$me "$CHROOT_PATH" "$PROGRAM" | |
stop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment