Is there a way to programatically control harddrive activity lights on linux?
Just like in the main question, is there a way to do this? (Other than inducing a high io load) Maybe some facility deep down in the kernel that controls this?
I'm looking to write a little script to identify failed drives in my software raid array. (Blinking the activity light in a certain repeating patte开发者_JAVA技巧rn, etc.)
I read about all the good ideas here: https://serverfault.com/questions/64239/physically-identify-the-failed-hard-drive unfortunately I didn't tag any of my drives and they're all sandwiched together so looking at serial numbers is out.
Activity lights are generally hard-wired to the motherboard's disk controller. There is no OS facility for directly controlling them.
However, if you know which drive is problematic in software, and it is not mounted (just to be safe), you could probably dd
either to or from it (I expect not the entire drive is bad?) to blink the light. For example:
#!/bin/bash
badDrive=$1
while true ; do
dd -if "$badDrive" -of "/dev/null" -bs 512 -count 204800 conv=noerror >/dev/null 2>&1
sleep 2
done
This will read 100MiB from the drive ignoring read errors, sleep two seconds, and then do it again. Pass in the hard disk device path, like /dev/sda
.
You'll need to figure out a way to kill the script before inserting a new drive, though. Otherwise you'll have really bad performance and it may cause other problems.
You could, in your program, call his
baddrive(Checkdrivestatus)
and limit it to 10 cycles.
this way you could run flashbaddrive, it in turn would checkdrivestatus and pass it to baddrive to flash the failed drive for 10 seconds or so and cut out.
I would imagine you would have to look at mdadm to see what the interface is like programmatically, but it would do the trick from the command line.
On hard disk caddies they typically run off of the sata/scsi/ide interface or off of a plug on the controller card.
Do you know where the light originates? You could do a search for model information, query the disk in question directly on and off. If the drive has failed often you can still pull this off of the circuit board.
another strategy is to access the disks sequentially /dev/sda, sdb, sdc, sde, sdf, etc... and you can see if the light sticks, or if it does not light up. a totally dead drive may kill the light depending on how the controller is set to access it.
精彩评论