Linux 101: lsof - umount : device is busy -

Sometimes when we want to "umount" a filesystem, we get a "device busy" message. The message means that the filesystem on the device is in use.

Open files in a filesystem:

The lsof command displays the files that are open on a certain filesystem:

The mount point of the filesystem could be for example : /usr .
The command displays all the processes using the filesystem. We can then use the below command to stop all the processes that are keeping the filesystem in a busy state:

lsof tool:

To be able to check which files (directories, sockets, pipes,...) are open on the system, we could use the lsof (List Open Files) command.
It displays all the files that are "tied" to the running processes on the system. The below results describe just a snippet of the output.

In the above example, FD represents the file descriptor of the files in use by the "systemd" process. Below some of the values of FD:
  • CWD : current working directory.
  • RTD : root directory.
  • TXT : text file.
  • 1u (in the above example: "1" represents the file descriptor and the "u" represents the access mode, "u" is for read write and "w" is for write access and "r" for read-only.
Open file for a specific user:

To check the open files for the user "username", we use the below command:

Processes and their open ports:

To display the processes tied to certain network ports. We use the below command and we specify the port and the protocol as arguments of the "lsof" command :

The protocol could be : TCP or UDP.


Leave as a comment: