[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [PATCH] Unmount all mounts in chroot

Hi, Cody :-)

On Thu, Apr 16, 2009 at 1:30 AM, Cody A.W. Somerville
<cody.somerville@canonical.com> wrote:
> Hello,
>  As discussed on IRC earlier, here is a patch that removes the hard coded
> calls to umount in functions/exit.sh and instead looks at /proc/mounts to
> determine all active mounts within a chroot and attempts to umount each one.

I did in another project time ago something similar, but you have to
keep in mind that some times there are nested mount points and you
need to unmount them in the proper order.

Some times things that you install inside of the chroot can mount stuff like:
devpts /dev/pts devpts rw,relatime 0 0
binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec 0 0

Or similar, so you need to umount /proc/sys/fs/binfmt_misc before
/proc or it will fail.

I did before just sorting in reverse order. In my system was something like:
awk "/${sources_dir_escaped}// {print \$2};" /proc/mounts | sort -r |
xargs umount

I attach an alternative patch.


diff --git a/functions/exit.sh b/functions/exit.sh
index 980d2d1..5316b54 100755
--- a/functions/exit.sh
+++ b/functions/exit.sh
@@ -18,10 +18,10 @@ Exit ()
 	# Always exit true in case we are not able to unmount
 	# (e.g. due to running processes in chroot from user customizations)
 	Echo_message "Begin unmounting filesystems..."
-	umount chroot/dev/pts > /dev/null 2>&1 || true
-	umount chroot/proc > /dev/null 2>&1 || true
-	umount chroot/selinux > /dev/null 2>&1 || true
-	umount chroot/sys > /dev/null 2>&1 || true
+	for DIRECTORY in $(awk '/\/chroot\// { print $2 }' /proc/mounts | sort -r)
+	do
+		umount ${DIRECTORY} > /dev/null 2>&1 || true
+	done
 Setup_cleanup ()

Reply to: