meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
datarecovery:bad_sectors [2020/12/16 12:47] niziakdatarecovery:bad_sectors [2020/12/16 13:19] (current) niziak
Line 59: Line 59:
 Ready script to automate above: Ready script to automate above:
 [[https://serverfault.com/questions/461203/how-to-use-hdparm-to-fix-a-pending-sector|How to use hdparm to fix a pending sector?]] [[https://serverfault.com/questions/461203/how-to-use-hdparm-to-fix-a-pending-sector|How to use hdparm to fix a pending sector?]]
 +Fixed version:
 +<code bash>
 +#!/bin/bash -u
 +baddrive=/dev/sdb
 +badsect=974041815
 +while true; do
 +  echo Testing from LBA $badsect
 +  smartctl -t select,${badsect}-max ${baddrive} 2>&1 >> /dev/null
 +
 +  echo "Waiting for test to stop (each dot is 5 sec)"
 +  while [ "$(smartctl -a ${baddrive} | awk '/Self-test execution status:/ {print $5}')" = "249)" ]; do
 +    echo -n .
 +    sleep 5
 +  done
 +  echo
 +
 +  echo "Waiting for test to stop (each dot is 5 sec)"
 +  while [ "$(smartctl -l selftest ${baddrive} | awk '/^# 1/{print substr($5,1,9)}')" != "Completed" ]; do
 +    echo -n .
 +    sleep 5
 +  done
 +  echo
 +
 +  badsect=$(smartctl -l selftest ${baddrive} | awk '/# 1  Selective offline   Completed/ {print $10}')
 +  [ $badsect = "-" ] && exit 0
 +
 +  echo Attempting to fix sector $badsect on $baddrive
 +  hdparm --repair-sector ${badsect} --yes-i-know-what-i-am-doing $baddrive
 +  echo Continuning test
 +done
 +
 +</code>
 +
  
 For ZFS with RAIDZ filesytem, SCRUB is needed to replace bad data: For ZFS with RAIDZ filesytem, SCRUB is needed to replace bad data: