Bug 818498

Summary: "mount --rbind /sys /whereever" cannot be undone due to systemd
Product: [openSUSE] openSUSE Tumbleweed Reporter: Forgotten User 7XRNh5WElB <forgotten_7XRNh5WElB>
Component: BasesystemAssignee: E-mail List <bnc-team-screening>
Status: RESOLVED FIXED QA Contact: E-mail List <qa-bugs>
Severity: Normal    
Priority: P5 - None CC: fcrozat
Version: 13.1 Milestone 1   
Target Milestone: 13.1 Milestone 1   
Hardware: x86-64   
OS: Other   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Forgotten User 7XRNh5WElB 2013-05-04 11:54:50 UTC
User-Agent:       Mozilla/5.0 (X11; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0

If I bind-mount "/sys" somewhere else, with
> mount --rbind /sys /mnt/mysys
and then try to successively unmount everthing within /mnt/mysys, some unmounts fail.  lsof says its systemd's fault.

In contrast if I simulate the rbind with a for-loop which bind-mounts every mount point under /sys manually, everything can be unmounted later.

Reproducible: Always

Steps to Reproduce:
########################################################
#!/bin/bash

dev="/sys"
dir="/mnt/mysys"
mkdir --parents $dir

# "Manual" recursive bind mount
echo Mounting $dev on $dir ...
mount --bind "$dev/" "$dir/"
for k in `cut -d' ' -f 2 /proc/mounts | \
             grep -E "^$dev/" | sed "s|^$dev/||" | sort`
do
  echo Mounting $dev/$k on $dir/$k ...
  mount --bind "$dev/$k" "$dir/$k"
done

echo ; sleep 1

# Recursive unmount
echo Unmounting recursively from $dir ...
cut -d' ' -f 2 /proc/mounts | grep -E "^$dir" | \
                            sort -r | xargs -trn1 umount

echo ; sleep 1

# Recursive bind mount with --rbind
echo rbind-mounting $dev ...
mount --rbind "$dev/" "$dir/"

echo ; sleep 1

# Recursive unmount
echo Unmounting recursively from $dir ...
echo Watch out for errors ...
cut -d' ' -f 2 /proc/mounts | grep -E "^$dir" | \
                            sort -r | xargs -trn1 umount
########################################################
Actual Results:  
Unmounting of /mnt/mysys/fs/cgroup/systemd and all mount points above fails.
"lsof +f -- /mnt/mysys/fs/cgroup/systemd" says:
> COMMAND PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
> systemd   1 root    6r   DIR   0,18        0 2907 /sys/fs/cgroup/systemd/system



Bug 804575 also reports some problems with rbind and systemd --- maybe they are related.  Bug 804575 is marked as fixed and I couldn't reproduce it on my system, so I susptect the behaviour above is a new bug.

The given script was tested with an up-to-date system (as of today), inside VirtualBox, hosted by openSUSE 12.2.

I was under the impression that observed the same problem with /dev, but I wasn't able to reproduce it with the script above.
Comment 1 Forgotten User 7XRNh5WElB 2013-05-21 12:16:45 UTC
This bug is also present in current Factory (KDE live CD build 0466).
I'm updating Product/OS.
Comment 2 Frederic Crozat 2013-05-21 16:12:55 UTC
mounts are being shared by default (see http://cgit.freedesktop.org/systemd/systemd/commit/?id=b3ac5f8cb98757416d8660023d6564a7c411f0a0 ) and --rbind is propagating mounts in /sys to /mnt/mysys (which are not "different mounts"), so you would need to unmount everything in /mnt/mysys in the reserve order.

This should be fixed with next util-linux (2.23): http://karelzak.blogspot.com.br/2013/04/umount8-mount8-and-nsenter1.html.

Another simple solution for you could be to set / with private mounts: http://permalink.gmane.org/gmane.comp.sysutils.systemd.devel/10575
Comment 3 Forgotten User 7XRNh5WElB 2013-05-21 18:08:28 UTC
Thanks for the references.
I'm not sure if I fully understand you.

> and --rbind is propagating mounts in /sys to
> /mnt/mysys (which are not "different mounts"),
Does that mean "mount --rbind" should be the same as multiple "mount --bind"?  The man page suggests that, but my script above indicates that there is in fact a difference.

> so you would need to unmount everything
> in /mnt/mysys in the reserve order.
That's what I'm doing (see the script in my bug report).  Yet the unmounts fail after "mount --rbind".

> Another simple solution for you could be to set / with private mounts:
> http://permalink.gmane.org/gmane.comp.sysutils.systemd.devel/10575
OK, "mount --make-private /sys/fs/cgroup" solves the problem.  I don't understand what this does and why it is needed.  According to the mount man page, this is about "mirrors of mounts", but I've never used such things --- at least not knowingly.
Comment 4 Frederic Crozat 2013-05-22 09:18:58 UTC
(In reply to comment #3)
> Thanks for the references.
> I'm not sure if I fully understand you.
> 
> > and --rbind is propagating mounts in /sys to
> > /mnt/mysys (which are not "different mounts"),
> Does that mean "mount --rbind" should be the same as multiple "mount --bind"? 
> The man page suggests that, but my script above indicates that there is in fact
> a difference.
> 
> > so you would need to unmount everything
> > in /mnt/mysys in the reserve order.
> That's what I'm doing (see the script in my bug report).  Yet the unmounts fail
> after "mount --rbind".

The difference is caused by rbind + / being setup to use shared mounts by default (so /mnt/mysys and /sys are virtually the same, therefore causing unmount /mnt/mysys impossible)


> > Another simple solution for you could be to set / with private mounts:
> > http://permalink.gmane.org/gmane.comp.sysutils.systemd.devel/10575
> OK, "mount --make-private /sys/fs/cgroup" solves the problem.  I don't
> understand what this does and why it is needed.  According to the mount man
> page, this is about "mirrors of mounts", but I've never used such things --- at
> least not knowingly.

systemd is setting / as "shared mounts" by default (to ease container usage). And using rbind is doing some kind of "mirrors of mounts"..

Closing as fixed.