Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 516980 - sys-apps/systemd-212-r5 unmounts the sources of rbind mounts
Summary: sys-apps/systemd-212-r5 unmounts the sources of rbind mounts
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo systemd Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-07-12 16:58 UTC by Khumba
Modified: 2014-08-26 01:25 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge --info (emerge-info.txt,5.69 KB, text/plain)
2014-07-12 16:59 UTC, Khumba
Details
rbind-test.sh (rbind-test.sh,188 bytes, text/x-sh)
2014-07-12 16:59 UTC, Khumba
Details
rbind-test.openrc.out (rbind-test.openrc.out,1.09 KB, text/plain)
2014-07-12 17:00 UTC, Khumba
Details
rbind-test.systemd.out (rbind-test.systemd.out,1.49 KB, text/plain)
2014-07-12 17:00 UTC, Khumba
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Khumba 2014-07-12 16:58:51 UTC
I'm using mount --rbind to prepare a chroot.  When I'm done using the chroot,
I'd like to be able to unmount the bind mounts I made for it.  I'm trying to use
the solution suggested in various places of unmounting the rbound mounts in
reverse order.  I'm running sys-apps/systemd-212-r5, and while this works when I
boot with sys-apps/openrc-0.12.4, it behaves incorrectly under systemd: some
targets fail to unmount, and the targets that do get unmounted, are also
unmounted from their original locations.  (...causing havoc with systemd if /sys
is unmounted, so much that systemd won't even shut down.)

To demonstrate the problem via /dev:
~ # mkdir foo
~ # ./rbind-test.sh
~ # rmdir foo

rbind-test.openrc.out is the output of OpenRC behaving as desired.

rbind-test.systemd.out is the output of systemd:
- /root/foo/pts fails to unmount.
- /root/foo/{shm,mqueue,hugepages} are all unmounted from /dev.

I tested this from a root tty shell immediately after boot.  lsof | grep foo
showed nothing.  /etc/mtab is a symlink to /proc/self/mounts.

emerge --info shows a hardened kernel, but this also happens on sys-kernel/gentoo-sources-3.12.21-r1.
Comment 1 Khumba 2014-07-12 16:59:17 UTC
Created attachment 380638 [details]
emerge --info
Comment 2 Khumba 2014-07-12 16:59:51 UTC
Created attachment 380640 [details]
rbind-test.sh
Comment 3 Khumba 2014-07-12 17:00:08 UTC
Created attachment 380642 [details]
rbind-test.openrc.out
Comment 4 Khumba 2014-07-12 17:00:24 UTC
Created attachment 380644 [details]
rbind-test.systemd.out
Comment 5 Khumba 2014-07-12 17:06:00 UTC
Forgot to mention: using mount --bind to manually mount subdirectories, unmounting under systemd works okay:

~ # mount --bind /dev foo
~ # mount --bind /dev/pts foo/pts
~ # mount --bind /dev/shm foo/shm
~ # mount | grep -e /dev -e /foo | grep -v /sda
devtmpfs on /dev type devtmpfs (rw,nosuid,size=1869668k,nr_inodes=467417,mode=755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
mqueue on /dev/mqueue type mqueue (rw,relatime)
devtmpfs on /root/foo type devtmpfs (rw,nosuid,size=1869668k,nr_inodes=467417,mode=755)
devpts on /root/foo/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620)
tmpfs on /root/foo/shm type tmpfs (rw,nosuid,nodev)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
~ # umount foo/pts
~ # umount foo/shm
~ # umount foo
~ # mount | grep -e /dev -e /foo | grep -v /sda
devtmpfs on /dev type devtmpfs (rw,nosuid,size=1869668k,nr_inodes=467417,mode=755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
mqueue on /dev/mqueue type mqueue (rw,relatime)
Comment 6 Mike Gilbert gentoo-dev 2014-07-12 18:06:20 UTC
This seems to be some quirk of shared subtrees. systemd mounts everything as shared by default. See mount(8) for more info.

If you run this before trying to umount the bind mounts, it should work ok.

mount --make-rprivate /foo

You can also make this the default using a simple oneshot service unit.

http://lists.freedesktop.org/archives/systemd-devel/2013-February/008586.html

I'm not sure if this umount behavior with recursive shared bind mounts is a bug, or intentional behavior. However, that would be a topic for a kernel mailing list.
Comment 7 Khumba 2014-08-26 01:25:39 UTC
I had completely missed the different subtree mount modes, thanks for the insight.  Reading /usr/src/linux/Documentation/filesystems/sharedsubtree.txt, it sounds like umounts being propagated is intended for 'shared' mounts.

Also thanks for the reference to making this system-wide -- I should look into this, but for now I've settled on this to unmount:

mount | cut -d' ' -f3 | while read mountpoint; do
    if [[ $mountpoint = ${chrootBase}* ]]; then
        mount --make-rprivate "$mountpoint"
    fi
done
mount | cut -d' ' -f3 | tac | while read mountpoint; do
    if [[ $mountpoint = ${chrootBase}* ]]; then
        umount "$mountpoint"
    fi
done

Closing, as I'm not trying to change systemd in this bug :).