How to automatically turn off write cache after the kernel “hard resetting link”

I turned off write caching on an SATA drive using hdparm -W0 $DEV

Now, sometimes, the kernel decides, it’s a good idea to hard reset an SATA link in order to get communication to a drive back up and running (maybe it is a good idea, won’t judge it here).

However, if that happens, the drive’s write cache will be re-enabled.
Upon plugging in, I can catch an udev event to automatically run hdparm to turn off the write cache.

But I can’t find any information about how to catch this hard resetting link events to fire up hdparm again (or make sure the write cache is disabled again by some other means).

Answer

Attribution
Source : Link , Question Author : Bodo Thiesen , Answer Author : Community

Leave a Comment