Hi Robert, Unfortunately it is not NFS. I know about umount -f for nfs, But is not my case. Regarding umount -l, that in my opinion is a very dangeros option when somabody has a cluster or a shared storage. When you do an NFS mount, it sometimes shows 'device is busy” status, in such case we need to perform force unmount in a graceful way. There are different ways and options we can try out if normal nfs unmount fails. In our scenario, we have created /var/linoxide directory for the mount.
Linux: Which process is causing 'device busy' when doing umount?
flybywireflybywire
closed as off-topic by Jean-François Fabre♦, Munim Munna, Machavity, gre_gor, too honest for this siteMay 16 '18 at 20:49
This question appears to be off-topic. The users who voted to close gave this specific reason:
- 'Questions about general computing hardware and software are off-topic for Stack Overflow unless they directly involve tools used primarily for programming. You may be able to get help on Super User.' – Jean-François Fabre, Munim Munna, Machavity, gre_gor, too honest for this site
12 Answers
Look at the lsof command (list open files) -- it can tell you which processes are holding what open. Sometimes it's tricky but often something as simple as
sudo lsof | grep (your device name here)
could do it for you.MarkusQMarkusQ
Just in case... sometimes happens that you are calling umount from the terminal, and your current directory belongs to the mounted filesystem.
alvataralvatar
You should use the
fuser
command.Eg.
fuser /dev/cdrom
will return the pid(s) of the process using /dev/cdrom
.If you are trying to unmount, you can kill theses process using the
-k
switch (see man fuser
).Community♦
BenBen
Check for open loop devices mapped to a file on the filesystem with 'losetup -a'. They wont show up with either lsof or fuser.
JayJay
Also check
/etc/exports
. If you are exporting paths within the mountpoint via NFS, it will give this error when trying to unmount and nothing will show up in fuser
or lsof
.MalvineousMalvineous
(as lists the processes using files on the mount mounted at /mountpoint. Particularly useful for finding which process(es) are using a mounted USB stick or CD/DVD.
masmas
lsof and fuser are indeed two ways to find the process that keeps a certain file open.If you just want umount to succeed, you should investigate its -f and -l options.
AnonymousAnonymous
That's exactly why the 'fuser -m /mount/point' exists.
BTW, I don't think 'fuser' or 'lsof' will indicate when a resource is held by kernel module, although I don't usually have that issue..
Carter Galle
lsof and fuser didn't give me anything either.
After a process of renaming all possible directories to .old and rebooting the system every time after I made changes I found one particular directory (relating to postfix) that was responsible.
It turned out that I had once made a symlink from /var/spool/postfix to /disk2/pers/mail/postfix/varspool in order to minimise disk writes on an SDCARD-based root filesystem (Sheeva Plug).
With this symlink, even after stopping the postfix and dovecot services (both ps aux as well as netstat -tuanp didn't show anything related) I was not able to unmount /disk2/pers.
When I removed the symlink and updated the postfix and dovecot config files to point directly to the new dirs on /disk2/pers/ I was able to successfully stop the services and unmount the directory.
Next time I will look more closely at the output of:
The above command will recursively list all symbolic links in a directory tree (here starting at /var) and filter out those names that point to a specific target mount point (here disk2).
captchacaptcha
Open files
Processes with open files are the usual culprits. Display them:
There is an advantage to using
/dev/<device>
rather than /mountpoint
: a mountpoint will disappear after an umount -l
, or it may be hidden by an overlaid mount.fuser
can also be used, but to my mind lsof
has a more useful output. However fuser
is useful when it comes to killing the processes causing your dramas so you can get on with your life.List files on
<mountpoint>
(see caveat above):Interactively kill only processes with files open for writing:
After remounting read-only (
mount -o remount,ro <mountpoint>
), it is safe(r) to kill all remaining processes:Mountpoints
The culprit can be the kernel itself. Another filesystem mounted on the filesystem you are trying to
umount
will cause grief. Check with:For loopback mounts, also check the output of:
Anonymous inodes (Linux)
Anonymous inodes can be created by:
- Temporary files (
open
withO_TMPFILE
) - inotify watches
- [eventfd]
- [eventpoll]
- [timerfd]
These are the most elusive type of pokemon, and appear in
lsof
's TYPE
column as a_inode
(which is undocumented in the lsof
man page).They won't appear in
lsof +f -- /dev/<device>
, so you'll need to:For killing processes holding anonymous inodes, see: List current inotify watches (pathname, PID).
Tom HaleTom Hale
If you still can not unmount or remount your device after stopping all services and processes with open files, then there may be a swap file or swap partition keeping your device busy. This will not show up with
fuser
or lsof
. Turn off swapping with:You could check beforehand and show a summary of any swap partitions or swap files with:
or:
As an alternative to using the command
sudo swapoff -a
, you might also be able to disable the swap by stopping a service or systemd unit. For example:or:
In my case, turning off swap was necessary, in addition to stopping any services and processes with files open for writing, so that I could remount my root partition as read only in order to run
fsck
on my root partition without rebooting. This was necessary on a Raspberry Pi running Raspbian Jessie. Simon GouldSimon Gould
Filesystems mounted on the filesystem you're trying to unmount can cause the
target is busy
error in addition to any files that are in use. (For example when you mount -o bind /dev /mnt/yourmount/dev
in order to use chroot
there.)To find which file systems are mounted on the filesystem run the following:
mount | grep '/mnt/yourmount'
To find which files are in use the advice already suggested by others here:
lsof | grep '/mnt/yourmount'
Slobodan PejicSlobodan Pejic
Not the answer you're looking for? Browse other questions tagged linuxshelldevicemountumount or ask your own question.
I mounted a remote file system using sshfs (version 2.8.4)
but unmounting it fails
Any ideas as to what might be causing this error and how one might fix it?
ctufflictuffli
7 Answers
Some program is using a file in the filesystem you're trying to unmount. It could be a file opened for reading or writing, a current directory, or a few more obscure cases. It could even be due to a directory on the filesystem being a mount point.
To investigate, run
lsof +f -- example
. It will tell what the process(es) are using the filesystem. Make your own judgement as to whether to make them close files, kill them, or defer the unmount operation.GillesGilles
ChrisChris
I just had this problem and could not
kill -9
the process reading from the mounted filesystem. kill -9
did not work even after fusermount -zu /mount/point
or umount -l /mount/point
(which worked). The only thing that worked was pkill -9 sshfs
.ctnctn
I often see 'device busy' with sshfs when I have a terminal window open to a directory on the sshfs share. Exiting the terminal or changing directories to a local share then running fusermount -u solves my problems.
CJ TravisCJ Travis
Running Ubuntu,
man fusermount
tells about a -z
option, which is documented as “lazy unmount”. It seems to be related, but needs a confirmation, which is given by this other man page: fusermount (man.he.net), which says “lazy unmount (works even if resource is still busy)”. One must use it with the -u
, the -z
option alone, will produce an error. I tried the -z
option, and can confirm it do the trick, but this precisely too much looks like a trick: what does it do exactly? Make it be unmounted automatically as soon as the directory is not busy any‑more? I don't know, not documented, so unsafe.So here is another option, more verbose, but safer: tries to unmount until it successes, as many time as needed, in a loop.
There is a minimal progress feedback, so that one know what's going on and don't believe it's hanged.
This option is acceptable from a shell script; for command line interaction, the use of the
-z
option is more handy, but one must probably be aware the man page does not document it and there may be doubt about what it exactly do.Hibou57Hibou57
ReaperSoonReaperSoon
If you already ensured no process is still using the filesystem before trying 'regular' umounting:
fuser -vm /mount/point
and/orlsof /mount/point
to find them,- quit/kill/do_something_with_them so that they don't use
/mount/point
anymore,
Try:
pkill -KILL sshfs
and thenfusermount -u /mount/point
.
It helped me when I lost network connection and couldn't umount the unresponsive sshfs mount point.
Also, if you want sshfs to automatically umount when network connection is lost, informing applications using sshfs of an I/O error (so that they don't get stuck infinitely), mount with:
sshfs -o ServerAliveInterval=15 remote-srv:/remote/dir /local/mountpoint
When no data is exchanged, your
ssh
client will check every 15 seconds if it can get a response from the server. If 3 checks fail, it will disconnect and umount. TotorTotor