Hi Peter, CC: util-linux-ng mailing list On Fri, Jul 24, 2009 at 04:41:06PM +0400, Peter Volkov wrote: > Hi, Karel. I found strange behavior of mount -o bind. If I create two > directories, 1 and 2, after bind-mount 1 to 2 and after that issue mount > 2 - 1 will be mounted twice on 2: > > # mkdir 1 2 > # mount -o bind 1 2 > # mount 2 > # mount | grep 2 > /root/1 on /root/2 type none (rw,bind) > /root/1 on /root/2 type none (rw,bind) This is very old (10+years) feature (but undocumented). The mount(8) is trying to found mountpoint/device in fstab and then in mtab. I guess the original purpose for this feature is user-friendly "mount /node -o remount". Unfortunately, the code does not check for MS_REMOUNT flag and consults mtab in all cases. (The code is consulting fstab/mtab before mount options parsing.) > The same if I do mount 1: > # mount 1 > # mount | grep 2 > /root/1 on /root/2 type none (rw,bind) > /root/1 on /root/2 type none (rw,bind) > /root/1 on /root/2 type none (rw,bind) > > Looks like mount is consulting /etc/mtab for some reason, which is at > least non-expected behavior (or is not-documented). > > BTW if I substitute /etc/mtab with symlink on /proc/mounts I get > expected error: > > # LC_ALL=C mount 2 > mount: /dev/sda3 already mounted or /root/2 busy Sure, /proc/mounts does not provide proper information about bind mounds, so your "mount 2" is interpreted as "mount /dev/sda3 /root/2" -- it's not possible to mount the same device on the same mountpoint two times. This restriction does not exist for bind mounts. > mount: according to mtab, /dev/root is already mounted on /root/2 > > Is this a bug or /me missing something? It's bug in the mount.8 man page -- this behaviour should be documented. Patches are welcomed :-) Karel -- Karel Zak <kzak@xxxxxxxxxx> -- To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html