It happens all the time doesn’t it? You need to unmount a CD or you want to pack away the external drive but when you try to umount it you get the dreaded “device is busy” message. Wouldn’t it be great if Linux actually told you what was keeping the drive busy? Here we are in 2008, I’m using Ubuntu Gutsy, and that message hasn’t changed in all the years I’ve used Linux.
# umount /media/disk/
umount: /media/disk: device is busy
umount: /media/disk: device is busy
First thing you’ll do will probably be to close down all your terminals and xterms but here’s a better way. You can use the fuser command to find out which process was keeping the device busy:
# fuser -m /dev/sdc1
/dev/sdc1: 538
# ps auxw|grep 538
donncha 538 0.4 2.7 219212 56792 ? SLl Feb11 11:25 rhythmbox
Rhythmbox is the culprit! Close that down and umount the drive. Problem solved!
Another handy one is:
umount -l /dev/sdwhatever
This does a lazy umount which immediately detaches the drive from the filesystem, and then cleans up the mess afterwards. This is especially handy if it’s a networked file system (NFS etc) and the network has gone down.
Niall you rock! I’ve tried the -f (force) option but that never worked w/ nfs volumes. -l works everytime.
Funnily enough, screwing up NFS mounts is how I learned about “mount -l /mnt/xxx” 🙂
Im right there with you. I had two NFS mounts being presented and some how autofs crisscrossed the mounts. I still can’t figure out how that happened though because the autofs config file had the server and directories specified correctly.
Naill, Thank you for the advice
the “umount -l /mnt/sdb1†woked nicely 🙂
Thanks Nail, it works for me. it resolves my probs.
Thanks Nail!
Thanks a lot Niall.
Niall, you rock dude!
That one works!
To this day what annoys me is that they haven’t changed the behavior of unmount to automatically pull up the PID of what’s locking the device when it trips a device is busy message.
It’s not enough that it tells you the device is busy, it should tell you why it’s busy.
I think that this is the way how simple special linux tools work. Someone would prefer some complex tool, which would display blocking processes, give chance to kill them, or filter the list and kill just some of them… A lot can be done. But KISS, umount just umounts, it does not conversate a lot with user. Process list can be very long, but you do not start umount to get some list of processes. You start it to umount… If it can not, it says it can not. You know what to do (find blocking processes, check their state, think about them, ask mom, kill some, let some running… and finally umount -l 🙂 You can do a lot, but umount is a simple tool for umounting, not for listing processes. Should it list pids? Or names? Or complex lines like ps -ef does?…. There already are appropriate tools like fuser and ps to do this for you, why umount should? Think about this. But I understand, listing pids would be useful, maybe with -v switch. Maybe even umount does not know pids 😀 I did not check sources.
Mark:
It’s Linux, you can totally go write the code to do that if you want!
-David
This advice pops up regularly in open source circles and is never helpful. It’s an elitist remark designed to dismiss.
Steve: No, it is not. It is not helpful, but it is a true fact and the point is you are waiting for someone else to do exactly that. Sometimes you need to do it yourself, or go ask someone that can so that your request is actually taken into consideration. If you really need it, offer someone something in return.
great. i always wanted to know this 😀 fcking busy devices. gah
Nice trick! 🙂
umount -l /dev/sdwhatever
God bless you, kind stranger!
it works
Gr8!!!
Thanx…….
thanks for the culprit finding way..
till now i relied heavily on the lazy monuting trick i learned some yrs ago.
thanks for this.
in return a friendly stumble from my side.
You can add -v to the fuser command line switches – that will cause it to nicely print all the processes holding the locks. This way you can save yourself the effort of grepping through the process list.
On a related note, you can use the pgrep command to filter running processes. For example, to look at all of root’s processes, you can use:
pgrep -l -u root
-l tells pgrep to also list the process name instead of just the PID.
If you don’t like how mount & umount work, don’t bitch! Fix it your damn self!
@El Chupa Pollo
if you do possess such qualities to modify it then you cna go forward and if you don’t possess then you don’t also deserve to say this to others.
Perfect! This would have saved me yesterday!!!
umount -l /dev/sdwhatever
Wonderful! I have mine setup to automatically mount the NFS file shares from an XP machine (using /etc/fstab and SMBFS) and if the network goes down or the computer is powered off, then nautilus hangs whilst it tries to find it…
This looks like it should stop this from needing a computer reboot 😉
Good work!
i use
umount -lfr /mnt/sambamountofboxthatsshutdown
l for lazyness
f for forced unmount for unreachable networked storage
r for just in case unmounting fails remount as readonly
That ad in the middle of the post is really annoying! Thumble down!
Great advice! I’m still somewhat of a Linux Newb but it’s so damn easy to get advice, it’s a pleasure to run Ubuntu! Best online community ever!
Hi,
i dont know how much this will help, but this might prove to be a good solution/tip?
http://www.linuxquestions.org/questions/linux-hardware-18/device-busy-cannot-unmount-334133/page2.html#post3313235
Nope, fuser doesn’t show anything…
Hmmm, I guess something was busy on it when I was trying before, but the umount worked and I’ll never what was going on …
Unfortunately, ‘fuser’ does not show everything that can produce a ‘device is busy’ message.
If you are running NFS and/or automounter on RHEL, you need to shut these down manually first:
cd /etc/init.d
sh autofs stop
sh nfs stop
Don’t know why these are not reported by fuser.
You can try fuser -m if fuser does not show anything. In special cases it helps.
In my case, I had an NFS mount blocking the umount of a filesystem, where fuser -m and lsof did not show what was blocking it.
I suspect this is because I was using nfs-kernel-server, which runs in kernel-space and thus cannot show up as a PID using the filesystem.
Thank you for the advice
the “umount -l /mnt/winxp” woked nicely 🙂
Thanks for the tip, fuser worked great for me!
umount -l /dev/sdwhatever
great,
thanks.
Didn’t work for me. fuser -v is not a valid switch and all i get from fuser -m is
fuser: can’t read cdev at 0x0
Phew, glad I had written this post. My little boy switched one of the UPSes protecting my external drives this morning. Both drives were still mounted somehow but I unmounted them just in case.
Luckily fuser -vm was able to tell me that bash was keeping one of the drives busy. I eventually figured out it was my screen session that was the culprit. fsck showed errors on one so I’m glad I umounted.
sounds great! i will try next time.
Thanks…it worked well for me…
@El Chupa Pollo
Typical Linux-zealot response to any criticism. Go fuck yourself.
Thanks kind ppl, the umount -l works like a charm!
I’ve always used #fuser -m /[mountpoint]
Then, kill the process ID, but this works great especially on NFS
Another tip:
I used fuser (with and without the -m option) but nothing was listed as accessing the mount I wanted to get rid of.
Until I realized that I had another mount (a .ISO mounted loop), which was located on the volume I wanted to unmount (Duh!)
for example:
/dev/cciss/c0d0p1 on /mnt/ext-array type ext3 (rw,errors=remount-ro)
/mnt/ext-array/ISO/ubuntu.iso on /mnt/ubuntu type iso9660 (rw,loop=/dev/loop0)
That second mount was preventing me from unmounting the first one and fuser didn’t report it.
Hope it helps.
What’s hilarious is I mounted my main 500GB drive as read only then was like “Why the hell ain’t I able to unmount it and make it readable?” I glanced at this entry and noticed “Rythmbox” and was like, “uh I’m retarded…” it was actually open lol
Closed it then did
umount -f /dev/sda1
mount -rw /dev/sda1 /media/sda1 -t ntfs -o force
/win 🙂
Very nice. I have been looking for this command for 16 years. It might have been there, but you helped me find it. You rock.
Great tip, I was looking for this.
Awesome man… great tip. Was in the middle of a change window at work and couldn’t figure out who was tying up the mount. Worked like a charm!! Saved my butt.
fuser didn’t show the culprit but this is very handy, thanks.
Here’s a routine I always incorporate into scripts when dealing with umounting devices. It always works for me. Any comments anyone? (I’m quite new to this scripting lark!!)
unmount_usb_memory_device()
{
echo “Waiting for USB device to become free for unmount…”
#——————————————————————————————————
# Get the first 10 characters of the current working directory. If these
# match the variable usb_mount_point, then we cannot umount the device
# without first changing directory (use the home directory)…
#——————————————————————————————————
current_directory=$(pwd | cut -c 1-11)
if [ ${current_directory} = ${usb_mount_point} ]
then
echo “Changing directory away from $usb_mount_point…”
cd
echo “Current directory is now $(pwd)”
fi
umount ${usb_mount_point}
df | grep $usb_mount_point >/dev/null
if [ $? -eq 0 ]
then
#————————————————————————————————
# Mount point is still in ‘df’ output, therefore the umount has failed…
#————————————————————————————————
…code here as required…
else
#————————
# Umount successful…
#————————
echo “$usb_mount_point unmounted successfully.”
echo “Please remove USB device from ${server_name}.”
echo “”
fi
}
Looks good. I think umount will probably return an error value you could check too?
Thanks Donncha – good idea. Can’t believe I didn’t think of doing that!
> To this day what annoys me is that they haven’t changed the behavior of
> unmount to automatically pull up the PID of what’s locking the device when it
> trips a device is busy message.
> It’s not enough that it tells you the device is busy, it should tell you why it’s
> busy.
As they, say use
fuser -vm /dev/sdc1
Niall, God (if he does exists and is ‘black’ as it stated in Malcolm-X movie) bless you, brother. You are a life saver.
-God
Well, I was having less subtle problems than listed above… my current dir was on the drive I was trying to umount. Duh.
Hmm… the Title is really not right! I searched for an way to unmount Busy things and dont how to find out why they are Busy… That are 2 pair of shoes!
Glad I “Googled IT”. Thats been a nagging problem with USB drives on a backup server. USB drive gets renamed, suddenly backups coming in do not come in. A week goes by, I notice.
For anyone in that boat I suggest editing fstab and using the UUID thing-magig, that way the usb drive will always mount as the same device, even if you change the USB port while its running.
e.g.
ls /dev/disk/by-uuid -lah
(this shows you the unique identifier of the drive)
[root@localhost disk]# ls /dev/disk/by-uuid -lah
total 0
drwxr-xr-x 2 root root 80 Oct 7 10:18 .
drwxr-xr-x 6 root root 120 Oct 7 10:13 ..
lrwxrwxrwx 1 root root 10 Oct 7 10:18 7807fc33-d8db-4aa8-b30b-570e49b8c3ef -> ../../sdc1
lrwxrwxrwx 1 root root 10 Oct 7 10:13 d57760e8-2ea6-49b1-b8c9-d828394ace66 -> ../../sda1
—
Then you grab the unique ID and put it into fstab:
[root@localhost disk]# cat /etc/fstab
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/VolGroup00/LogVol01 swap swap defaults 0 0
UUID=7807fc33-d8db-4aa8-b30b-570e49b8c3ef /media/disk ext4 defaults 0 0
And no more surprises.
Sorry, people are probably wondering what this has to do with device being busy. Say you unplug the usb drive and put it in a diffent port, it now becomes unmountable (in CentOS at least). umount -l unmounts it, then you remount /media/disk. The computer then calls it sdc1 instead of sdb1.
e.g.
[root@localhost disk]# ls -l
ls: reading directory .: Input/output error
total 0
[root@localhost disk]# umount -l /media/disk
[root@localhost disk]# mount /media/disk
[root@localhost disk]# ls -l
ls: reading directory .: Input/output error
total 0
[root@localhost disk]# cd /
[root@localhost /]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
300753144 2987768 282241536 2% /
/dev/sda1 101086 18462 77405 20% /boot
tmpfs 484528 0 484528 0% /dev/shm
/dev/sdd1 1922858352 200048 1824982704 1% /media/disk
[root@localhost /]# cd /media/disk
[root@localhost disk]# ls -l
total 36
drwxr-xr-x 2 root root 4096 Oct 7 09:14 11
drwxr-xr-x 2 root root 4096 Oct 7 09:15 124
drwxr-xr-x 2 root root 4096 Oct 7 09:14 24
drwxr-xr-x 2 root root 4096 Oct 7 09:14 74
drwxr-xr-x 2 root root 4096 Oct 7 09:15 84
drwx—— 2 root root 16384 Oct 7 09:11 lost+found
tks Niall , you save my life 🙂