Skip to content

Instantly share code, notes, and snippets.

@maluta
Created February 4, 2010 16:12
Show Gist options
  • Save maluta/294806 to your computer and use it in GitHub Desktop.
Save maluta/294806 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Mount a source directory or fs type $i in destination mount point $j
# using options $k
#
# i j k
mdirs=(
"unionfs" "/opt/unionfs" "-t unionfs -o dirs=/opt/sandbox:/=ro"
"/dev" "/opt/unionfs/dev" "--bind"
"devpts" "/opt/unionfs/dev/pts" "-t devpts"
"shm" "/opt/unionfs/dev/shm" "-t tmpfs"
"sysfs" "/opt/unionfs/sys" "-t sysfs"
"proc" "/opt/unionfs/proc" "-t proc"
"/tmp" "/opt/unionfs/tmp" "--bind"
"/dev/sda6" "/opt/unionfs/opt" "-t ext3"
)
mount_unionfs()
{
mdir_size=${#mdirs[*]}
i=0; j=1; k=2
while [ "$i" -lt "$mdir_size" ]; do
if [ -z "$(mount | grep -w ${mdirs[$j]})" ]; then
echo "Mounting ${mdirs[$j]}"
sudo /bin/mount ${mdirs[$k]} ${mdirs[$i]} ${mdirs[$j]}
fi
i=$((i + 3)); j=$((j + 3)); k=$((k + 3))
done
}
umount_unionfs()
{
mdir_size=${#mdirs[*]}
j=$((mdir_size - 2))
while [ "$j" -gt "0" ]; do
if [ -n "$(mount | grep -w ${mdirs[$j]})" ]; then
echo "Umounting ${mdirs[$j]}"
sudo /bin/umount ${mdirs[$j]} 2> /dev/null
fi
j=$((j - 3))
done
}
mount_unionfs
sudo /usr/sbin/chroot /opt/unionfs /bin/su --shell /bin/bash --login $USER
umount_unionfs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment