#!/bin/bash function mount_unionfs { # mount temporary filesystems if [ -z "$(mount -t unionfs | grep -w /mnt/union )" ]; then sudo /bin/mount -t unionfs -o dirs=/mnt/cache:/=ro unionfs /mnt/union fi if [ -n "$(mount -t unionfs | grep -w /mnt/union )" ]; then # basic system mounts if [ -z "$(mount | grep -w /mnt/union/dev)" ]; then sudo /bin/mount --bind /dev /mnt/union/dev 2> /dev/null fi if [ -z "$(mount -t devpts | grep -w /mnt/union/dev/pts)" ]; then sudo /bin/mount -t devpts devpts /mnt/union/dev/pts 2> /dev/null fi if [ -z "$(mount -t tmpfs | grep -w /mnt/union/dev/shm)" ]; then sudo /bin/mount -t tmpfs shm /mnt/union/dev/shm 2> /dev/null fi if [ -z "$(mount -t sysfs | grep -w /mnt/union/sys)" ]; then sudo /bin/mount -t sysfs sysfs /mnt/union/sys 2> /dev/null fi if [ -z "$(mount -t proc | grep -w /mnt/union/proc)" ]; then sudo /bin/mount -t proc proc /mnt/union/proc 2> /dev/null fi if [ -z "$(mount | grep -w /mnt/union/tmp)" ]; then sudo /bin/mount --bind /tmp /mnt/union/tmp 2> /dev/null fi else echo "Mount of /mnt/union failed." exit 2 fi } function umount_unionfs { # # unmount /tmp # if [ -n "$(mount | grep -w /mnt/union/tmp)" ]; then sudo /bin/umount /mnt/union/tmp 2> /dev/null fi # # unmount /proc # if [ -n "$(mount -t proc | grep -w /mnt/union/proc)" ]; then sudo /bin/umount /mnt/union/proc 2> /dev/null fi # # unmount /sys # if [ -n "$(mount -t sysfs | grep -w /mnt/union/sys)" ]; then sudo /bin/umount /mnt/union/sys 2> /dev/null fi # # unmount /dev/shm # if [ -n "$(mount -t tmpfs | grep -w /mnt/union/dev/shm)" ]; then sudo /bin/umount /mnt/union/dev/shm 2> /dev/null fi # # unmount /dev/pts # if [ -n "$(mount -t devpts | grep -w /mnt/union/dev/pts)" ]; then sudo /bin/umount /mnt/union/dev/pts 2> /dev/null fi # # unmount /dev # if [ -n "$(mount | grep -w /mnt/union/dev)" ]; then sudo /bin/umount /mnt/union/dev 2> /dev/null fi if [ -n "$(mount | grep -w /mnt/union )" ]; then sudo /bin/umount /mnt/union 2> /dev/null fi } mount_unionfs # enter the chroot sudo /usr/sbin/chroot /mnt/union /bin/su --shell /bin/bash --login $USER # umount temporary filesystems umount_unionfs