The following patch seems to do the trick after some _very_ limited testing.
diff -u ./grml-chroot /usr/sbin/grml-chroot
--- ./grml-chroot 2009-04-04 07:31:55.614147651 +0000
+++ /usr/sbin/grml-chroot 2009-04-04 07:30:55.290805628 +0000
@@ -9,6 +9,7 @@
PROG_NAME_=$(basename $0)
DEST_=""
MOUNTED_="" # all mounted destinations
+STATEDIR="tmp/grml-chroot"
function die
{
@@ -26,6 +27,16 @@
EOT
}
+function isMounted
+{
+ local dir="$1"
+ if < /proc/mounts cut -d\ -f 2 | grep -q "$dir"; then
+ return 0
+ else
+ return 1
+ fi
+}
+
function storeMounts
{
local to_append_="$1"
@@ -44,12 +55,14 @@
local all_options_=""
- if [[ $options_ == "--bind" ]]; then
- all_options_="--bind $type_"
- else
- all_options_="-t $type_ none"
+ if ! isMounted ${DEST_}/$dest_; then
+ if [[ $options_ == "--bind" ]]; then
+ all_options_="--bind $type_"
+ else
+ all_options_="-t $type_ none"
+ fi
+ mount $all_options_ "${DEST_}/$dest_" && storeMounts "$dest_"
fi
- mount $all_options_ "${DEST_}/$dest_" && storeMounts "$dest_"
}
function umount_all
@@ -87,9 +100,14 @@
mountit "proc" "proc"
mountit "sysfs" "sys"
mountit "/dev" "dev" "--bind"
+mkdir -p "$DEST_/$STATEDIR"
+touch "$DEST_/$STATEDIR/$$"
if (( $# < 1 )); then
chroot "$DEST_"
else
chroot "$DEST_" "$@"
fi
-umount_all
+rm "$DEST_/$STATEDIR/$$"
+if rmdir $DEST_/$STATEDIR 2>/dev/null; then
+ umount_all
+fi |