relocated failed sector using hdparm
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 28 Dec 2011 23:39:34 +0000 (23:39 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 28 Dec 2011 23:39:34 +0000 (23:39 +0000)
git-svn-id: svn://svn.rot13.org/sysadmin-cookbook@285 191e9f34-6774-4a6d-acfc-7664dacd4a2a

recepies/smart/smart-relocate-sector.sh [new file with mode: 0755]

diff --git a/recepies/smart/smart-relocate-sector.sh b/recepies/smart/smart-relocate-sector.sh
new file mode 100755 (executable)
index 0000000..3a3ce0e
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/sh -x
+
+DRIVE=$1
+
+test -z "$DRIVE" && echo "usage: $0 /dev/sda" && exit
+
+smartctl -a $DRIVE > /tmp/smart.0
+
+sector=`smartctl -a $DRIVE | grep 'Completed: read failure' | head -1 | awk '{ print $10 }'`
+
+if [ ! -z "$sector" ] ; then
+
+       echo $sector
+       hdparm --read-sector $sector $DRIVE
+       smartctl -a $DRIVE > /tmp/smart.1
+       hdparm --write-sector $sector --yes-i-know-what-i-am-doing $DRIVE
+       smartctl -a $DRIVE > /tmp/smart.2
+
+       smartctl -t long $DRIVE
+
+       echo "when smartctl test finishes, re-check your arrays with:"
+       cat /proc/mdstat | grep sdd | cut -d' ' -f1 | xargs -i echo "echo check > /sys/block/{}/md/sync_action"
+
+fi
+