… and some other observations. Warning: use at your own risk!

I used to keep some of my photo backups on an external Seagate 500G drive which I also use for travel. Today however as I tried to access it I noticed some problems so I quickly ran:

smartctl -t long /dev/sdb
#followed by
smartctl -l selftest
#the result
Extended offline    Completed: <strong>read failure</strong>       90%       109         <strong>414996448</strong>

I started using this useful guide to correct the problems by repeatedly running smartctl, calculating the offset, finding the file with debugfs, forcing reallocation with dd and so on. However it seems there are a lot of bad blocks and even I realize the disk is quite gone I decided to write a small script to test the hole disk and try to fix it. Here it is:

<pre lang="bash">#!/bin/bash

DEV=/dev/sdb
MNT=/dev/sdb1 #assuming a single partition
START=2048 #which starts at 2048
BS=4096 #block size 4096

while : ; do
    smartctl -l selftest $DEV | egrep '# 1' | grep 'Completed: read failure'
    if [ $? -eq 0 ] ; then
	lba=$(smartctl -l selftest $DEV | egrep '# 1' | cut -c78-86)
	pos=$(echo "($lba-$START)*512/$BS" | bc)
	echo Read failure at $lba. Writting at $pos
	dd if=/dev/zero of=$MNT bs=$BS count=1 seek=$pos
	sync
	#smartctl --test long $DEV
        smartctl -t select,$lba-max $DEV
    else
        echo Still ok
    fi
    sleep 1m
done

Also as a note. The disk will spin down of it’s own after some time and the test will be “Aborted by host”. Use sdparm to change the STANDBY param:

sdparm -a /dev/sdb
/dev/sdb: Seagate Portable 0130
Power condition mode page:
PM_BG 0 [cha: n, def: 0, sav: 0]
STANDBY_Y 0 [cha: n, def: 0, sav: 0]
IDLE_C 0 [cha: n, def: 0, sav: 0]
IDLE_B 0 [cha: n, def: 0, sav: 0]
IDLE 0 [cha: n, def: 0, sav: 0]
<strong>STANDBY 1</strong> [cha: y, def: 1, sav: 1]
ICT 0 [cha: n, def: 0, sav: 0]
SCT 3000 [cha: y, def:3000, sav:3000]
SAT ATA Power condition mode page:
APMP 0 [cha: n, def: 0, sav: 0]
APM 0 [cha: n, def: 0, sav: 0]
root@purple:~# sdparm --clear STANDBY -6 /dev/sdb
/dev/sdb: Seagate Portable 0130
root@purple:~# sdparm -a /dev/sdb
/dev/sdb: Seagate Portable 0130
Power condition mode page:
PM_BG 0 [cha: n, def: 0, sav: 0]
STANDBY_Y 0 [cha: n, def: 0, sav: 0]
IDLE_C 0 [cha: n, def: 0, sav: 0]
IDLE_B 0 [cha: n, def: 0, sav: 0]
IDLE 0 [cha: n, def: 0, sav: 0]
<strong>STANDBY 0</strong> [cha: y, def: 1, sav: 1]
ICT 0 [cha: n, def: 0, sav: 0]
SCT 4294967286 [cha: y, def:3000, sav:3000]
SAT ATA Power condition mode page:
APMP 0 [cha: n, def: 0, sav: 0]
APM 0 [cha: n, def: 0, sav: 0]

Warning: use at your own risk!

Comments:

len -

You are right, but it was more of an exercise in pride :)


Etravel -

Actually, I hope you have a backup of that backup, since the bad blocks will keep on extending.