Sometimes, when you try to unmount a disk you get an error “Cannot umount volume. An application is preventing the volume ‘…….’ from being umounted.”
For this test, I open a mp3 file then I try to unmount the disk.
taufanlubis@toshiba:/media$ sudo umount Maxtor/
umount: /media/Maxtor: device is busy
umount: /media/Maxtor: device is busy
taufanlubis@toshiba:/media$
To determine the cause of the busy device you can use ‘lsof (list of open files)’. An open file may be a regular file, a directory, a block special file, a character special file, an executing text reference, a library, a stream or a network file.
You have to use ‘lsof‘ as a superuser.
taufanlubis@toshiba:~$ sudo lsof /media/Maxtor
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
xmms 6731 taufanlubis 8r REG 8,17 3766597 77718 /media/Maxtor/Data Music/My Music-Pop/Alpha Ville- Big In Japan.mp3
taufanlubis@toshiba:~$
Now, I know why I can’t unmount my disk because there is one file that still open.
You apply the same method when you find an error ‘Could not bind to port’. For example, you want to know what applications that currently use port 80.
taufanlubis@toshiba:~$ sudo lsof -i:80
[sudo] password for taufanlubis:
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
apache2 5649 root 3u IPv4 18026 TCP *:www (LISTEN)
apache2 5739 www-data 3u IPv4 18026 TCP *:www (LISTEN)
apache2 5741 www-data 3u IPv4 18026 TCP *:www (LISTEN)
apache2 5742 www-data 3u IPv4 18026 TCP *:www (LISTEN)
apache2 5743 www-data 3u IPv4 18026 TCP *:www (LISTEN)
apache2 5744 www-data 3u IPv4 18026 TCP *:www (LISTEN)
taufanlubis@toshiba:~$
When that doesn’t work, grep for the [sh]d[a-z] device name.
But sometimes that doesn’t work and you’re left Googling your brains out trying to find the answer.