Strange behaviour with mount --bind

Bug #1574514 reported by Daniel
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
linux (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

The following problem appears with Ubuntu wily 15.10 and xenial 16.04:

I bind-mount my rootfs to a temporary folder. I explicitly use --bind and NOT --rbind. The result is as expected: I only see the files which are in the rootfs, any other mounts are invisible in this directory. But when I mount another directory later, It automatically also gets mounted in my temporary directory.

Example (tested with the Live CD xubuntu-16.04-desktop-amd64.iso):

root@xubuntu:~# mkdir /mnt/source
root@xubuntu:~# mkdir /mnt/target
root@xubuntu:~# mount --bind / /mnt/source
root@xubuntu:~# ls /mnt/source/mnt/target/
root@xubuntu:~# mount -t tmpfs none /mnt/target
root@xubuntu:~# touch /mnt/target/testfile
root@xubuntu:~# ls /mnt/source/mnt/target/
testfile

The testfile in the last line SHOULD NOT APPEAR because /mnt/source/mnt/target/ should not be mounted.

I don't find an explanation for this behaviour.

I found this because I wanted to run:

tar cpC /mnt/source/ . | tar xpC /mnt/target/

The command began to cyclic copy /mnt/source/mnt/target/mnt/target/mnt/target/mnt/target/

This scenario always worked in the past versions of Ubuntu and Debian

ProblemType: Bug
DistroRelease: Ubuntu 16.04
Package: linux-image-4.4.0-21-generic 4.4.0-21.37
ProcVersionSignature: Ubuntu 4.4.0-21.37-generic 4.4.6
Uname: Linux 4.4.0-21-generic x86_64
ApportVersion: 2.20.1-0ubuntu2
Architecture: amd64
AudioDevicesInUse:
 USER PID ACCESS COMMAND
 /dev/snd/controlC0: xubuntu 1766 F.... pulseaudio
CasperVersion: 1.376
Date: Mon Apr 25 08:40:52 2016
IwConfig:
 enp0s3 no wireless extensions.

 lo no wireless extensions.
LiveMediaBuild: Xubuntu 16.04 LTS "Xenial Xerus" - Release amd64 (20160420.1)
Lsusb:
 Bus 001 Device 002: ID 80ee:0021 VirtualBox USB Tablet
 Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
MachineType: innotek GmbH VirtualBox
ProcEnviron:
 TERM=xterm
 PATH=(custom, no user)
 LANG=en_US.UTF-8
 SHELL=/bin/bash
ProcFB:

ProcKernelCmdLine: file=/cdrom/preseed/hostname.seed boot=casper initrd=/casper/initrd.lz quiet splash --- keyboard-configuration/layoutcode=ch
PulseList: Error: command ['pacmd', 'list'] failed with exit code 1: No PulseAudio daemon running, or not running as session daemon.
RelatedPackageVersions:
 linux-restricted-modules-4.4.0-21-generic N/A
 linux-backports-modules-4.4.0-21-generic N/A
 linux-firmware 1.157
RfKill:

SourcePackage: linux
UpgradeStatus: No upgrade log present (probably fresh install)
dmi.bios.date: 12/01/2006
dmi.bios.vendor: innotek GmbH
dmi.bios.version: VirtualBox
dmi.board.name: VirtualBox
dmi.board.vendor: Oracle Corporation
dmi.board.version: 1.2
dmi.chassis.type: 1
dmi.chassis.vendor: Oracle Corporation
dmi.modalias: dmi:bvninnotekGmbH:bvrVirtualBox:bd12/01/2006:svninnotekGmbH:pnVirtualBox:pvr1.2:rvnOracleCorporation:rnVirtualBox:rvr1.2:cvnOracleCorporation:ct1:cvr:
dmi.product.name: VirtualBox
dmi.product.version: 1.2
dmi.sys.vendor: innotek GmbH

Revision history for this message
Daniel (hackie) wrote :
Revision history for this message
Brad Figg (brad-figg) wrote : Status changed to Confirmed

This change was made by a bot.

Changed in linux (Ubuntu):
status: New → Confirmed
Revision history for this message
Daniel (hackie) wrote :

I just found this mail which describes a problem which has the same root: http://www.spinics.net/lists/linux-fsdevel/msg92569.html:

root@xubuntu:~# mkdir tmp1
root@xubuntu:~# mkdir tmp2
root@xubuntu:~# mount -o bind /dev tmp1
root@xubuntu:~# ls tmp1/pts
root@xubuntu:~# mount -o bind /dev/pts tmp1/pts
root@xubuntu:~# ls tmp1/pts
0 1 2 3 4 5 6 ptmx
root@xubuntu:~# mount -o bind /dev tmp2
root@xubuntu:~# ls tmp1/pts tmp2/pts
tmp1/pts:
0 1 2 3 4 5 6 ptmx

tmp2/pts:
root@xubuntu:~# mount -o bind /dev/pts tmp2/pts
root@xubuntu:~# ls tmp1/pts tmp2/pts
tmp1/pts:
0 1 2 3 4 5 6 ptmx

tmp2/pts:
0 1 2 3 4 5 6 ptmx
root@xubuntu:~# grep pts /proc/mounts
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
devpts /root/tmp1/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
devpts /mnt/source/root/tmp1/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
devpts /root/tmp2/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
devpts /mnt/source/root/tmp1/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
devpts /root/tmp1/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
devpts /mnt/source/root/tmp2/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0

# now you see: pts got mounted to tmp1 again and even to /mnt/source from the first test - why???

root@xubuntu:~# umount tmp1/pts

# tmp1/pts should now be empty after unmounting, but it is mounted twice so the files are still visible. on the other hand: why did tmp2/pts unmount???:

root@xubuntu:~# ls tmp1/pts tmp2/pts
tmp1/pts:
0 1 2 3 4 5 6 ptmx

tmp2/pts:
root@xubuntu:~# umount tmp1/pts

# umount was possible a second time

root@xubuntu:~# ls tmp1/pts tmp2/pts
tmp1/pts:

tmp2/pts:

root@xubuntu:~#

Revision history for this message
Seth Forshee (sforshee) wrote :

This has to do with the propagation behavior of the bind mount.

# mount --bind src dest
# findmnt -o+PROPAGATION | grep dest
├─.../dest shared

Shared propagation means that mounts and unmounts in any of the mirrors propagate to the others. To change this:

# mount --make-private dest
# findmnt -o+PROPAGATION | grep dest
├─.../dest private
# mount ... src/mnt
# touch src/mnt/foo
# ls src/mnt
foo lost+found
# ls dest/mnt

dest/mnt will have the same contents as before the mount in src.

I think I remember something about the default behavior changing with the switch to systemd, from private to shared, but I can't remember for sure. If you're seeing a different behavior than in older, upstart-based releases of Ubuntu that may be why.

Marking this bug invalid because the kernel's behavior is exactly what's expected.

Changed in linux (Ubuntu):
status: Confirmed → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.