Search code examples
javalinuxdiskmount

How to reliably detect disk is down on Linux via Java


Is there a good way to detect that particular disk went offline on server on Linux, via Java?

I have an application, that due to performance reasons, writes to all disks directly (without any RAID in middle).

I need to detect if Linux would unmount any disk due to disk crash during run-time, so I would stop using it. The problem is that each mount has a root directory, so without proper detection, the application will just fill-up the root partition.

Will appreciate any advice on this.


Solution

  • In Linux, everything is accessible through text files. I don't really understand what is the exact information you require, but check /proc/diskstat, /proc/mounts, /proc/mdstat (for raids), etc...