How to umount when the device is busy

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!


67 Comments

Niall (6 comments.) on February 13, 2008 at 10:46 am.

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.

Reply

Mel on March 12, 2009 at 3:14 pm.

Niall you rock! I’ve tried the -f (force) option but that never worked w/ nfs volumes. -l works everytime.

Reply

Niall (6 comments.) on March 13, 2009 at 2:37 am.

Funnily enough, screwing up NFS mounts is how I learned about “mount -l /mnt/xxx” :)

Reply

Kevin on April 22, 2012 at 3:16 am.

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.

Reply

Azeez on January 23, 2010 at 10:45 am.

Naill, Thank you for the advice
the “umount -l /mnt/sdb1” woked nicely :)

Reply

KBala (1 comments.) on February 13, 2010 at 11:44 am.

Thanks Nail, it works for me. it resolves my probs.

Reply

Hugo on August 11, 2010 at 8:42 pm.

Thanks Nail!

Reply

Suman on November 30, 2010 at 10:39 pm.

Thanks a lot Niall.

Reply

german on December 4, 2010 at 1:43 pm.

Niall, you rock dude!

Reply

Mark (22 comments.) on February 13, 2008 at 1:50 pm.

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.

Reply

Aleš Friedl on July 1, 2009 at 10:23 pm.

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 :D I did not check sources.

Reply

David on February 11, 2010 at 11:02 pm.

Mark:

It’s Linux, you can totally go write the code to do that if you want!

-David

Reply

Steve on January 4, 2012 at 5:58 pm.

This advice pops up regularly in open source circles and is never helpful. It’s an elitist remark designed to dismiss.

Reply

Christian on April 20, 2012 at 1:43 pm.

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.

Reply

Dankoozy (41 comments.) on February 14, 2008 at 7:48 pm.

great. i always wanted to know this :D fcking busy devices. gah

Reply

Patrick (2 comments.) on March 22, 2008 at 5:56 pm.

Nice trick! :)

Reply

blackbelt_jones (1 comments.) on May 29, 2008 at 7:01 am.

umount -l /dev/sdwhatever

God bless you, kind stranger!

Reply

Pj!!! on June 20, 2008 at 12:02 pm.

Gr8!!!
Thanx…….

Reply

anant shrivastava (2 comments.) on August 16, 2008 at 6:36 pm.

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.

Reply

Mihai Limbasan on August 23, 2008 at 10:30 pm.

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.

Reply

El Chupa Pollo on August 24, 2008 at 10:32 pm.

If you don’t like how mount & umount work, don’t bitch! Fix it your damn self!

Reply

anant shrivastava (2 comments.) on August 27, 2008 at 7:48 am.

@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.

Reply

Josh Davis on August 29, 2008 at 6:24 pm.

Perfect! This would have saved me yesterday!!!

Reply

S. Sheldrake (1 comments.) on September 1, 2008 at 8:18 am.

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!

Reply

Anonymous on September 2, 2008 at 8:23 pm.

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

Reply

Paolo on September 3, 2008 at 1:00 pm.

That ad in the middle of the post is really annoying! Thumble down!

Reply

Osama (1 comments.) on October 8, 2008 at 1:04 pm.

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!

Reply

ernest on October 20, 2008 at 5:52 am.

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

Reply

Daniel Norton on October 31, 2008 at 8:53 pm.

Nope, fuser doesn’t show anything…

Reply

Daniel Norton on October 31, 2008 at 8:55 pm.

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 …

Reply

DaveC on November 10, 2008 at 5:38 pm.

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.

Reply

Aleš Friedl on July 1, 2009 at 10:13 pm.

You can try fuser -m if fuser does not show anything. In special cases it helps.

Reply

Jeremy (5 comments.) on October 29, 2011 at 5:15 am.

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.

Reply

dji (1 comments.) on December 6, 2008 at 1:02 am.

Thank you for the advice
the “umount -l /mnt/winxp” woked nicely :)

Reply

Mean Gene on December 27, 2008 at 12:24 am.

Thanks for the tip, fuser worked great for me!

Reply

prabhu on January 6, 2009 at 12:55 pm.

umount -l /dev/sdwhatever

great,
thanks.

Reply

iceolate (1 comments.) on January 7, 2009 at 5:00 am.

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 0×0

Reply

Donncha (1707 comments.) on February 4, 2009 at 9:38 am.

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.

Reply

jonny rocket (1 comments.) on March 4, 2009 at 7:05 am.

sounds great! i will try next time.

Reply

Deeps on April 23, 2009 at 4:13 pm.

Thanks…it worked well for me…

Reply

Chester Oakley on April 30, 2009 at 4:29 am.

@El Chupa Pollo

Typical Linux-zealot response to any criticism. Go fuck yourself.

Reply

Soniquser on June 26, 2009 at 11:11 am.

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

Reply

Alberto Rojas on August 20, 2009 at 6:24 pm.

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.

Reply

Alex on October 18, 2009 at 6:34 pm.

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 :)

Reply

Tom Harrison (1 comments.) on November 4, 2009 at 3:42 pm.

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.

Reply

Carmen (1 comments.) on December 5, 2009 at 4:56 pm.

Great tip, I was looking for this.

Reply

Mark on December 16, 2009 at 1:28 am.

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.

Reply

Anon on December 24, 2009 at 2:12 am.

fuser didn’t show the culprit but this is very handy, thanks.

Reply

AJ on January 19, 2010 at 9:57 am.

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
}

Reply

Donncha (1707 comments.) on January 19, 2010 at 11:26 am.

Looks good. I think umount will probably return an error value you could check too?

Reply

AJ on January 19, 2010 at 12:43 pm.

Thanks Donncha – good idea. Can’t believe I didn’t think of doing that!

Reply

Antonio on January 21, 2010 at 3:43 pm.

> 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

Reply

Ted Smith on February 22, 2010 at 7:41 am.

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

Reply

Martin on March 6, 2010 at 9:48 pm.

Well, I was having less subtle problems than listed above… my current dir was on the drive I was trying to umount. Duh.

Reply

c0de (1 comments.) on April 10, 2010 at 3:00 am.

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!

Reply

Jimmah on October 7, 2010 at 3:33 pm.

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.

Reply

Jimmah on October 7, 2010 at 3:51 pm.

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

Reply

Fu MiYu on March 4, 2012 at 5:30 am.

tks Niall , you save my life :)

Reply

sina on March 30, 2012 at 11:13 pm.

thaaaaaaaaaaaaks niall i love you :)

Reply

Maverick on May 12, 2012 at 8:17 am.

abe chutiye, nahin solve ho raha :-)

Reply

Leave Your Comment

Your email will not be published or shared. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Holy Shmoly! is Stephen Fry proof thanks to caching by WP Super Cache