5

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".

  • Please provide the output of lsof /mnt/temp/dir – mrc02_kr Aug 30 '17 at 8:08
1

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
  • 1
    Instead of using the filesystem path, umount /mnt/temp/dir use the device path umount nfsserver:/some/share/. If both mounts are the same share, then mount may have to decide, arbitrarily, which one to unmount, but no matter which one it does, you'll be out of the problem and can clean it up from there. – Gypsy Spellweaver Jan 19 '17 at 8:01
  • @GypsySpellweaver This does not aid success, in unmounting an nfs mount which is underneath another mount. /sbin/umount uses the umount2() system call which simply takes a path. It may change the effect however. I haven't tested for nfs, but /sbin/umount appears able to detect when you're trying to do the impossible, and will simply print invalid argument. – sourcejedi Nov 13 '17 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.