It happens many times you try to unmount a disk partition or mounted CD/DVD disk and if you try to unmount device, which is accessed by other users, then you will get error umount: /xxx: device is busy. However, Linux/FreeBSD comes with fuser command to kill forcefully mounted partition.
Understanding device error busy error
What happens basically, is that Linux / UNIX will not allow you to unmount a device that is busy. There are many reasons for this (such as program accessing partition or open file) , but the most important one is to prevent data loss.
Try the following command to find out what processes have activities on the device/partition. If your device name is /dev/sdb1, enter the following command as root user:
# lsof | grep '/dev/sda1'
Output:
vi 4453 vivek 3u BLK 8,1 8167 /dev/sda1
Above output tells that user vivek has a vi process running that is using /dev/sda1. All you have to do is stop vi process and run umount again. As soon as that program terminates its task, the device will no longer be busy and you can unmount it with the following command:
# umount /dev/sda1
Following disussion allows you to unmout device and partition forcefully using Linux commands.
Linux fuser command to forcefully unmount a disk partition
Suppose you have /dev/sda1 mounted on /mnt directory then you can use fuser command as follows:
WARNING! These examples may result into data loss if not executed properly (see "Understanding device error busy error" for more information).Type the command to unmount /mnt forcefully:
# fuser -km /mnt
Where,
- -k : Kill processes accessing the file.
- -m : Name specifies a file on a mounted file system or a block device that is mounted. In above example you are using /mnt
Linux umount command to unmount a disk partition
You can also try umount command with –l option:
# umount -l /mnt
Where,
- -l : Also known as Lazy unmount. Detach the filesystem from the filesystem hierarchy now, and cleanup all references to the filesystem as soon as it is not busy anymore. This option works with kernel version 2.4.11+ and above only.
If you would like to unmount a NFS mount point then try following command:
# umount -f /mnt
Where,
- -f: Force unmount in case of an unreachable NFS system
Caution: Using these commands or option can cause data loss for open files; programs which access files after the file system has been unmounted will get an error.
See also:
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop













{ 7 comments… read them below or add one }
Very useful, thank you.
thanks
fuser -km {file / filesystem}
If you have NFS mount file then it will now work.
Sometimes fuser and lsof fail. One option that works for me is remounting read-only, and then doing a lazy unmount:
mount -o ro,remount /dev/sdb3
umount -l /dev/sdb3
I have a cronjob that needs to mount an external hdd and then unmount after it backup to my external hdd.
This is how my backup.pl inside my cron.daily looks like:-
system (“/etc/rc.d/init.d/sendmail stop”);
system (“/usr/sbin/cmuExport -d”);
system (“/etc/rc.d/init.d/sendmail start”);
system (“mkdir /mnt/usbdisk”);
system (“mount -t ext3 /dev/sdb1/mnt/usbdisk”);
system (“/bin/tar -zcvf /home/cmu/localhost.tar.gz/home/cmu/localhost”);
system (“mv /home/cmu/localhost.tar.gz/mnt/usbdisk”);
system (“umount -l /dev/sdb1/mnt/usbdisk”);
But it doesn’t unmount it. The error message says:-
umount: /mnt/usbdisk: not mounted
umount: /mnt/usbdisk: not mounted
I need help, please thank you.
First: Why are you using perl script instead of bash script if all calls are system’s? You can just delete “system” before all of your strings and rename backup.pl to backup.sh. At least this will be easier to debug.
Second: You have an error in umount command. Here command you needed:
“umount -l /dev/sdb1″.
In fact your command must work for your /dev/sdb1. Error was coz system trying to find block device “/mnt/usbdisk”, but this is a mount point.
@ nixcraft
As you said
# lsof | grep ‘/dev/sda1′
what about if we have a cifs mounted partition ?