BTS

Issue659

Title grml-chroot does not properly handle multiple chroots
Priority wish Status wont-fix
Superseder Nosy List gebi, mru, zugschlus
Assigned To Topics

Created on 2009-04-05.19:49:46 by zugschlus, last changed 2012-01-13.02:09:34 by mika.

Messages
msg4248 (view) Author: mika Date: 2012-01-13.02:09:34
After another round of discussion we sadly had to decide this isn't really
bullet proof though.

Quoting Gebi from the according discussion on IRC (with his permission):
    
02:48 < gebi> you know that /tmp was to bind mounted too if you want to use X?
02:49 < gebi> not a good idea to use a bind mounted /tmp inside of the chroot
for saving state which ultimatly goes back to the base image
02:50 < gebi> mrud: but you e.g HAVE to mount --bind /tmp chroot/tmp to use X in
chroot
02:51 < gebi> so it would be no fun to use chroot/tmp as state dir for
grml-chroot, because on unmounting your files would not be there anymore
02:51 < gebi> because hidden by the mount --bind

So unless someone provides a tested and bullet proof solution we've to close
this with won't fix.
msg4247 (view) Author: mika Date: 2012-01-13.01:28:47
https://github.com/grml/grml-scripts/tree/mika/grml_chroot_multi provides the
slightly adjusted patch.

If that's what we want and everyone can live with it we could merge it into master.
msg3847 (view) Author: mru Date: 2011-06-13.02:37:13
Any progress? Can we just include the patch by Marc? Maybe we can just write the 
state to /run instead of the chroot?
msg3242 (view) Author: zugschlus Date: 2010-06-29.06:52:47
On Sat, Feb 27, 2010 at 11:41:30PM +0000, Michael Prokop wrote:
> Michael Prokop <mika@grml.org> added the comment:
> 
> Gebi, you mentioned that you'd like to do something about this one, right?
> Marc, do you have any code that could help Gebi in resolving this issue in your 
> interests?

Nothing beyond the patch that is already in the issue.

Greetings
Marc

-- 
-----------------------------------------------------------------------------
Marc Haber         | "I don't trust Computers. They | Mailadresse im Header
Mannheim, Germany  |  lose things."    Winona Ryder | Fon: *49 621 72739834
Nordisch by Nature |  How to make an American Quilt | Fax: *49 3221 2323190
msg3036 (view) Author: mika Date: 2010-02-27.23:41:30
Gebi, you mentioned that you'd like to do something about this one, right?
Marc, do you have any code that could help Gebi in resolving this issue in your 
interests?

thanks && regards,
-mika-
msg2170 (view) Author: zugschlus Date: 2009-04-09.07:12:06
> It's not a bug, it's a feature!

I disagree and will fork a local grml-chroot.

> grml-chroot handles multiple joins to the same chroot just fine.

No.

> The first grml-chroot instance will mount and unmount, all other will not 
touch anything.

So it doesn't properly handle the case where the first chroot terminates before 
others. That's surprising behavior.

> It'd really prefer to not write to the chroot.

On grml, you can keep the state outside the chroot, for example in /var. my 
patch keeps the state inside the chroot since it keeps one from messing around 
with generating a directory name for the state of _this_ chroot.

Greetings
Marc
msg2132 (view) Author: mika Date: 2009-04-06.07:53:15
* Michael Gebetsroither <bts@bts.grml.org> [20090406 09:49]:

> It's not a bug, it's a feature!

> grml-chroot handles multiple joins to the same chroot just fine.
> The first grml-chroot instance will mount and unmount, all other will not touch
> anything.

> It'd really prefer to not write to the chroot.

No matter what's the conclusion, please document the behaviour in
the manpage, thx.

regards,
-mika-
msg2131 (view) Author: gebi Date: 2009-04-06.07:49:12
It's not a bug, it's a feature!

grml-chroot handles multiple joins to the same chroot just fine.
The first grml-chroot instance will mount and unmount, all other will not touch
anything.

It'd really prefer to not write to the chroot.
msg2129 (view) Author: mika Date: 2009-04-06.06:48:23
Thanks Marc, assigning the bugreport to gebi.

thx && regards,
-mika-
msg2128 (view) Author: zugschlus Date: 2009-04-05.20:05:56
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
msg2127 (view) Author: zugschlus Date: 2009-04-05.19:49:44
grml-chroot does not properly handle the situation when the user decides to 
chroot into the same chroot multiple times (for example, in different windows). 
When the first chroot terminates, the unconditional umount leaves the other 
chroots without mounted /proc, /dev etc.

I would suggest touching a file inside the chroot prior to the chroot, removing 
that file after the chroot command has terminated, and only umounting the 
filesystems if no other file is in there.

Greetings
Marc
History
Date User Action Args
2012-01-13 02:09:34mikasetstatus: fixed-in-git -> wont-fix
topic: - release-stopper
messages: + msg4248
nosy: mru, gebi, zugschlus
2012-01-13 01:28:47mikasetstatus: needs-progress -> fixed-in-git
topic: + release-stopper
messages: + msg4247
nosy: + gebi, mru
2011-11-07 11:55:23chsetstatus: chatting -> needs-progress
nosy: - ch
assignedto: ch ->
2011-11-07 11:51:26chsetnosy: + ch, - gebi
assignedto: gebi -> ch
2011-06-13 02:37:13mrusetnosy: gebi, zugschlus
messages: + msg3847
2010-06-29 06:52:47zugschlussetnosy: gebi, zugschlus
messages: + msg3242
2010-02-27 23:41:30mikasetnosy: gebi, zugschlus
messages: + msg3036
2009-04-09 07:12:08zugschlussetnosy: gebi, zugschlus
messages: + msg2170
2009-04-06 07:53:16mikasetnosy: gebi, zugschlus
messages: + msg2132
2009-04-06 07:49:13gebisetnosy: gebi, zugschlus
messages: + msg2131
2009-04-06 06:48:24mikasetassignedto: gebi
messages: + msg2129
nosy: + gebi
2009-04-05 20:05:57zugschlussetstatus: unread -> chatting
messages: + msg2128
2009-04-05 19:49:46zugschluscreate