Linux Mount – umount: Target is Busy

linuxmount

I have mounted /dev and immediately tried to unmount:

$ sudo mount -o rbind /dev m
$ sudo umount m
umount: /tmp/m: target is busy.
$ sudo lsof m
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
      Output information may be incomplete.
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
kdevtmpfs  55 root  cwd    DIR    0,6     4420    2 m
kdevtmpfs  55 root  rtd    DIR    0,6     4420    2 m

I have read that fuser can kill processes accessing the mount point, but I would like to understand what is happening in this simple case. Acording to the lsof output does something use the mountpoint as current working directory (cwd)?

I do not want to use lazy unmount.

Best Answer

You used rbind to mount a filesystem and submounts. In order to unmount a filesystem, you must unmount its submounts first (and the same for their submounts, recursively). But take care!

mount --make-rslave m
umount -R m

Without the first command, you risk unmounting all the sub-mounts on the source, due to mount propagation. In this case that means all the sub-mounts of /dev, which would have bad effects on your running system ;-).

Basically mount propagation is a massive pit-trap waiting for you to fall into it :-). It seems like it would have been better if bind mounts disabled it by default.


kdevtmpfs is the kernel thread that maintains devtmpfs. It does not prevent unmounting devtmpfs. This is because the kernel thread runs on a separate mount (like a bind mount). You can't see that original mount; it is in a separate mount namespace. If you want to try and work out why kdevtmpfs shows up in lsof, I don't know, maybe consider that a separate question.

Related Question