Hack #92. Find Out Why You Can't Unmount a Partition
If you can't unmount a disk because it's busy, you can use the lsof and fuser commands to find open files or pesky attached processes.
The popularity of removable drives and their usability for things such as backups [Hack #50] makes mounting and unmounting partitions a fairly common activity while a system is running. Another not-so-common but more critical sysadmin activity is the need to unmount a drive in an emergency, such as when one of your users has accidentally deleted his thesis or the source code for your next-generation product, or the disk begins getting write errors and you need to initiate recovery ASAP. In either case, it's truly irritating when you can't unmount a partition because some unknown process is using it in one way or another. Shutting down a system just to unmount a disk so that you can remove or repair it is clearly overkill. Isn't there a better way? Of course there is—read on.
Background
One of the most basic rules of Linux/Unix is that you can't unmount a partition while a process is writing to or running from it. Trying to do so returns an informative but fairly useless message like the following:
$ sudo umount /mnt/music
umount: /mnt/music: device is busy
umount: /mnt/music: device is busyIn some cases, terminating the processes associated with a partition is as easy as looking through all your windows for suspended or background processes that are writing to the partition in question or using ...