Commit de364f1a authored by Vitaly Lipatov's avatar Vitaly Lipatov

add hdd utils

parent 9b010a12
#!/bin/sh
# TODO: use ddrescue log
# ddrescue -n in /dev/null logfile
if [ -z "$1" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
echo "Usage:"
echo "fix_disk [--fix]
exit
fi
TESTONLY=
FORCE=
LIST=
[ "$1" = "--fix" ] && { TESTONLY=$1 ; shift ; }
[ "$1" = "--force" ] && FORCE=$1
[ "$1" = "--list" ] && LIST=$1
test_block()
{
local DEV=$1
local block=$2
hdparm --read-sector $block $DEV >/tmp/rs
RS=$?
head -n3 /tmp/rs
return $RS
}
fix_block()
{
DEV=$1
block=$2
# FIXME: possible badblocks always returns true
# badblocks -b 512 -v -s $DEV $block $block && { echo "Already OK, skipped..." ; [ -z "$FORCE" ] && return ; }
test_block $DEV $block && { echo "Already OK, skipped..." ; [ -z "$FORCE" ] && return ; }
if [ -z "$TESTONLY" ] ; then
echo "Test only"
return
fi
# for i in 1 2 3 ; do
# badblocks -b 512 -f -v -w $DEV $block $block
# sleep 1
# done
hdparm --yes-i-know-what-i-am-doing --repair-sector $block $DEV
# badblocks -b 512 -v -s $DEV $block $block && { echo "Read OK now!" ; return ; }
test_block $DEV $block && { echo "Read OK now!" ; return ; }
echo "Something still wrong with $block on $DEV"
}
# by dmesg
# FIXME: which device??
#BLOCKLIST=$(
#Buffer I/O error on device sda, logical block 32607659
#dmesg | grep "logical block " | sed -e "s|.*Buffer I/O error on device \(sd[a-z]\), logical block \([0-9]*\)|\1 \2|g" | sort -u | \
echo |
while read devname block ; do
#for i in $BLOCKLIST ; do
echo
#FIXME: logical block - 8 sectors (on 64 bit) or 4 sectors (on 32 bit?)
echo "List $block bad block on /dev/$devname ..."
#echo "Fixing $block block on /dev/$devname ..."
#fix_block /dev/$devname $block
done
[ -n "$LIST" ] && exit
dmesg | grep "end_request: I/O error" | sed -e "s|.*end_request: I/O error, dev \(sd[a-z]\), sector \([0-9]*\)|\1 \2|g" | sort -u | \
while read devname block ; do
#for i in $BLOCKLIST ; do
echo
echo "Fixing $block block on /dev/$devname ..."
fix_block /dev/$devname $block
done
#!/bin/sh
INDEV=/dev/sdb
OUTDEV=/dev/sdc
read_sector()
{
local DEV=$1
local block=$2
hdparm --read-sector $block $DEV >$3
RS=$?
#head -n3 /tmp/rs
return $RS
}
is_dirty_sector()
{
cat $1 | sed -e "s|0000 0000 0000 0000 0000 0000 0000 0000||g" -e "s|reading.*||g" | \
grep -v "^$" > $1.out
test -s $1.out
}
echo
i=596500
while true ; do
i=$(($i+1))
[ $(($i%100)) = 0 ] && echo -e -n "\rSector $i"
read_sector $INDEV $i /tmp/INrs || continue
read_sector $OUTDEV $i /tmp/OUTrs || exit
subst "s|/dev/.*||g" /tmp/INrs /tmp/OUTrs
diff -u /tmp/INrs /tmp/OUTrs && continue
# read and differs
echo -e "\nProblem with sector $i"
if is_dirty_sector /tmp/OUTrs ; then
echo "Non empty target, skipping"
#continue
else
ofb=$((512*$i))
ddrescue -d --force -i $ofb -o $ofb -c 1 -s 512 $INDEV $OUTDEV
fi
#exit
done
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment