2

I have a problem with a mountpoint being too busy to unmount. Normally, lsof or fuser would tell me what process is using it, but this is a bind mount, so lsof and fuser show what is using both the original mountpoint, and the bind mountpoint.

Ex:

Mount the filesystems:

$ sudo mkdir /mnt/mount /mnt/bind
$ sudo mount /dev/sdb1 /mnt/mount
$ sudo mount -o bind /mnt/mount /mnt/bind

Start a process that keeps /mnt/mount too busy to unmount

$ sudo dd if=/dev/zero of=/mnt/mount/testfile bs=1 oflag=dsync

Check what fuser says

$ sudo fuser -m /mnt/mount
/mnt/mount:           4022
$ sudo fuser -m /mnt/bind
/mnt/bind:            4022

Check what lsof says

$ sudo lsof +D /mnt/mount
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
dd      4022 root    1w   REG   8,17    28545   12 /mnt/mount/testfile

$ sudo lsof +D /mnt/bind
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
dd      4022 root    1w   REG   8,17    40682   12 /mnt/bind/testfile

Try to unmount both

$ sudo umount -v *
umount: /mnt/bind (/mnt/mount) unmounted
umount: /mnt/mount: target is busy

If you follow the same steps, but tell dd to write the file to /mnt/bind/testfile instead, unmounting /mnt/mount will be successful, but unmounting /mnt/bind will fail.

Clearly it makes a difference which mountpoint the process (dd in this case) is using, but lsof and fuser do not differentiate. Is there something that does?

  • 1
    Did you try lsof -pn | grep /mnt/bind and lsof -pn | grep /mnt/mount ? – wurtel Dec 1 '14 at 11:11
1

Thanks to wurtel, this became apparent:

While both fuser and lsof as used in my question both show the same process using both mountpoints, after either of those commands tell you the PID, running:

lsof -p $PID

does reveal exactly which mountpoint is being used. A bit of grepping and you're set.

  • @mikeserv: Maybe I'm using it wrong, but -M does not appear to help. Do you have an example of how to use it to tell if a process is writing to /mnt/mount or /mnt/bind? – Tal Dec 5 '14 at 8:07
  • thats cause its the wrong one - got it mixed up with -m. -M only works if the named file arg is a mountpoint but behaves identically otherwise - only listing process using that specific arg. -m, on the other hand, lists all process using any file on a mounted filesystem. With -v it prints to stderr a ps like list of things they might be doing with the files - m specifies a mount point. So try fuser -v /mnt/point and fuser -vm /mnt/point and hopefully youll see what i mean. – mikeserv Dec 5 '14 at 8:20
  • But you know what - i dont think that does what youre asking anyway. lsof definitely does, of course. w/ fuser maybe like fuser -vMm $(findmnt -UnRloTARGET /mnt/point) - but there findmnt does moat of the work anyway. – mikeserv Dec 5 '14 at 8:54
  • Neither fuser -v, fuser -vm, or fuser -vMm $(findmnt -UnRloTARGET /mnt/point) appear to be able to tell the difference between dd writing to /mnt/mount and dd writing to /mnt/bind. So far, the only way that works seems to be lsof -p – Tal Dec 9 '14 at 2:01
  • yeah - typically lsof will have the leg-up there - it's a more complicated tool. I'm sure what the difference is between your mnts bind and mnt - you haven't said - but I 'm not surprised if lsof provides more information. – mikeserv Dec 9 '14 at 2:10

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.