Last active
May 16, 2018 19:56
-
-
Save bamanzi/2889335 to your computer and use it in GitHub Desktop.
chroot wrapper
This file contains hidden or 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
NEWROOT=`dirname $(readlink -f $0)` | |
read -n1 -p "chroot to $NEWROOT? (y/n) :" ack | |
[ foo"$ack" == fooy ] || exit -1 | |
echo " " | |
function mount_if_not() { | |
dir=$1 | |
mount | grep $NEWROOT$dir >/dev/null | |
if [ $? -eq 0 ]; then | |
echo Skipping mounting $dir | |
else | |
echo "Bind $dir to $NEWROOT$dir" | |
mount --bind $dir $NEWROOT$dir | |
fi | |
} | |
## for references | |
# /dev/sda2 on / type ext3 (rw,acl,user_xattr) | |
# proc on /proc type proc (rw) | |
# sysfs on /sys type sysfs (rw) | |
# devtmpfs on /dev type devtmpfs (rw,mode=0755) | |
# tmpfs on /dev/shm type tmpfs (rw,mode=1777) | |
# devpts on /dev/pts type devpts (rw,mode=0620,gid=5) | |
# fusectl on /sys/fs/fuse/connections type fusectl (rw) | |
# securityfs on /sys/kernel/security type securityfs (rw) | |
# none on /var/lib/ntp/proc type proc (ro,nosuid,nodev) | |
# /dev/mapper/datavg01-data01 on /data01 type ext4 (ro) | |
mount_if_not /proc | |
mount_if_not /sys | |
mount_if_not /dev | |
mount_if_not /dev/shm | |
mount_if_not /dev/pts | |
cp -f /etc/resolv.conf ${TARGET}/etc/ | |
echo $NEWROOT > $NEWROOT/etc/debian_chroot | |
chroot $NEWROOT | |
function umount_dir () { | |
dir=$1 | |
echo "Unbind $NEWROOT$dir" | |
umount $NEWROOT$dir | |
} | |
read -n1 -p "Umount mapped filesystems (y/n) :" ack | |
echo " " | |
if [ foo"$ack" == fooy ]; then | |
umount_dir /proc | |
umount_dir /sys | |
umount_dir /dev/pts | |
umount_dir /dev/shm | |
umount_dir /dev/ | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment