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!

You might also like

If you like this post then please subscribe to my full RSS feed. You can also click here to subscribe by email. There are also my fabulous photos to explore too!

"How to umount when the device is busy", 3 out of 5 based on 47 ratings.

74 thoughts on “How to umount when the device is busy

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

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

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

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

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

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

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

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

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

  6. 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!

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

  8. 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!

  9. 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 …

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

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

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

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

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

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

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

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

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

  18. 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!!)

    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} ]
    echo “Changing directory away from $usb_mount_point…”
    echo “Current directory is now $(pwd)”

    umount ${usb_mount_point}

    df | grep $usb_mount_point >/dev/null
    if [ $? -eq 0 ]
    # Mount point is still in ‘df’ output, therefore the umount has failed…
    …code here as required…
    # Umount successful…
    echo “$usb_mount_point unmounted successfully.”
    echo “Please remove USB device from ${server_name}.”
    echo “”

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

  20. Niall, God (if he does exists and is ‘black’ as it stated in Malcolm-X movie) bless you, brother. You are a life saver.


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

  22. 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!

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

    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.

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


    [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
    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

  25. cheers for the -l switch….tried other ones and they didn’t work.
    had a issue with a broken nfs mount and it seems the nfs service was not running on the server.
    anyway, sorted that, and the -l switch worked like a charm :)

Leave a Reply

Loading Facebook Comments ...