Identify files/processes that prevent remounting read-only

filesmountopen filesprocess

My system runs Debian Testing, and / is generally mounted as read-only.

The main problem with this is, every time I install something or update the system, I cannot remount the filesystem (I get the error: mount: / is busy) as read-only again.

Used command:mount -o remount,ro /dev/mapper/sda9_crypt /

I have searched for processes and file-locks (with lsof/fuser), but I have no idea what I have to specifically search for.

I do not want to reset the system after an update, just to be able to get it remounted read-only.
Therefore, I look for the key processes that I need to kill to make this possible.

Best Answer

In the output of lsof /, in addition to files opened for writing (w suffix in the FD column), look for files marked (deleted). Files outside /var, /tmp (and /run, etc.) and home directories usually don't remain open for writing for a long time. But after an upgrade of some software, there may be some executable, library or data file that's still in use (open for reading or executing) by a running process that was started before the upgrade.

When a file is deleted but still open, that actually only removes its directory entry. The file itself is only deleted when it has no directory entry and it isn't open. That last part of deletion can't happen on a filesystem that's mounted read-only, so such a half-deleted file prevents remounting the filesystem as read-only just like a file open for writing does.

Related Question