Linux – Two *different* mountpoints having the *same* absolute path (bind-mount problem)

bind-mountlinuxmountunmounting

Scenario

  • a NFS share is mounted on /mnt/temp/dir (and other shares are mounted in subdirectories),
  • I umount everything there but supposedly, it doesn't work well (maybe I start with umount /mnt/temp/dir instead of umounting "nested" shares like /mnt/temp/dir/subdir* first),
  • I do mount -o bind /data/temp /mnt/temp,
  • I do mount /mnt/temp/dir,
  • I do mount /mnt/temp/dir/subdir1… and it works well.

Note: /mnt/temp is initially hosted on the root (/) filesystem /dev/sda6, and /data is another filesystem from /dev/sda8.

Problem

I cannot delete the /mnt/temp/dir directory on the root filesystem:

# mount -o bind / /test/root
# rmdir /test/root/mnt/temp/dir
rmdir: failed to remove `dir': Device or resource busy

Some explaination

/mnt/temp/dir is mounted twice, probably once on the root fs, and once on the /data fs.

Here is cat /proc/mounts:

nfsserver:/some/share/ /mnt/temp/dir nfs rw,relatime(...) 0 0
nfsserver:/some/share/ /mnt/temp/dir nfs rw,relatime,(...) 0 0

More interesting, here is cat /proc/1/mountinfo:

29 20 0:18 / /mnt/temp/dir rw,relatime - nfs nfsserver:/some/share/ rw,(...)
33 31 0:18 / /mnt/temp/dir rw,relatime - nfs nfsserver:/some/share/ rw,(...)

See, the two numbers at the beginning are different.

Kernel doc says for these two fields:

(1) mount ID:  unique identifier of the mount (may be reused after umount)
(2) parent ID:  ID of parent (or of self for the top of the mount tree)

They also have different parents 20 and 31 (root fs and /data fs), see:

20 1 8:6 / / rw,relatime - ext4 /dev/sda6 rw,(...)
31 20 8:8 /temp /mnt/temp rw,relatime - ext4 /dev/sda8 rw,(...)

If I try to umount /mnt/temp/dir, I get 2 error messages:

umount.nfs: /mnt/temp/dir: device is busy
umount.nfs: /mnt/temp/dir: device is busy

Question

How can I umount the "bad" one (mount ID 29)?

Even the umount(2) system call takes a path for argument, and not a "mount ID".

Best Answer

This is untested, but it'll at least bypass the “device is busy” problem.

Move one the mount point to a different location. That way, there won't be any more confusion between the two mount points.

mkdir /foo
mount --move /mnt/temp/dir /foo
Related Question