How to programmatically detect sata drive unplug in SuSE Linux?

1k Views Asked by At

Does anyone know of a method I can use to programmatically detect if a SATA hard drive has been unplugged? Our file system is mounted in READ-ONLY mode when we need to detect the removal of the drive. We noticed the other day that we were able to unplug a hard drive and everything continued to run without a hitch until the next time we attempted to read from a file on disk.

1

There are 1 best solutions below

0
On

Parsing the output of dmesg is a bad idea for several reasons, not the least of which it being inefficient and dependent on the format that the printk in the kernel happens to use.

On modern Linux systems, hardware changes are usually handled through udev which, in turn, will propagate change events up through D-BUS.

You may want to search how the insert and removal of memory sticks is handled; the methods should be fairly similar.