The normal way to find what is preventing a filesystem from being unmounted is to list the processes that have a file open on it (or a file descriptor, or their current directory, etc.):
lsof /path/to/mount/point
fuser -m /path/to/mount/point
Review the list of processes and kill them if warranted.
There are also a few ways in which the kernel itself can have something going on that prevents the unmounting, for example if there is another mount point beneath it (e.g. you can't unmount /mnt/chroot
while /mnt/chroot/proc
is mounted).
When you have bind mounts, commands such as the one above list files open via any of the paths to the filesystem. So for example fuser -m /mnt/chroot/run
lists processes that have files open on that filesystem, whether they're accessed via /run
or via /mnt/chroot/run
.
To find what is using the mount point, list the processes and the paths via which they have files open, and do some filtering on the paths. For example:
lsof /mnt/chroot/run | grep /mnt/chroot
or to get them all
lsof | grep /mnt/chroot
or you can access /proc
directly:
ls -l /proc/[0-9]*/fd/* | grep /mnt/chroot
For automated processing (assuming a recent sed
that supports -z
for null delimiters):
find /proc/[0-9]*/fd -type l -printf '%p %l/\0' |
sed -nz 's!^/proc/\([0-9]*\)/fd/[0-9]* /mnt/chroot/.*!\1!p' |
sort -nu
If you really can't find what's holding a filesystem mounted but you need to get back the mount point, you can move the mount point out of the way by creating an empty directory somewhere and running mount --move /current/mount/point /empty/directory/out/of/the/way
. You can also do a lazy unmount (umount -l
), which causes the filesystem to have no mount point at all (so files on it can't be opened anymore) but still be mounted as long as there are open files or other references on it.
fuser /mnt/chroot/proc /mnt/chroot/dev /mnt/chroot/sys /mnt/chroot/run
produce any output? – Mark Plotnick May 04 '15 at 15:09/mnt/chroot/proc: 1927 2357 2380
. That's right after I chroot inside it and exit immediately – Mas Bagol May 04 '15 at 16:03ps -p 1927 2357 2380
. Maybe those processes are running in the background and don't immediately exit when you exit the chroot. – Mark Plotnick May 04 '15 at 16:05lsof -p 1927
and see what things under/mnt/chroot/proc
it has open. – Mark Plotnick May 04 '15 at 21:37