Sep 272019
 

It’s been a while since my last post!

I recently had to recover a dying USB stick that kept spitting out read errors. ddrescue‘s default parameters could only help so much as the flash controller would hang the instant it hit a bad read error, necessitating a unplug and replug of the USB stick before it could carry on.

I decided to hack up a little script so I could recover select areas of the USB stick first and control what blocks ddrescue was attempting. Using ddrescueview, I could see which blocks had and had not been attempted. Using the information from the Block Inspector, I could obtain a hex address of the block I wanted to start from.

Block Inspector

Copying the text from the blocks into my hex-to-decimal script gave me a block to start from.

$ ./gethex.sh 'Non-tried0x1EB10000 (491.06 MiB)0x001FCB40 (1.99 MiB)
> '
0x1EB10000
514916352

The gethex.sh script is just a simple bash script to extract the starting block from the output

#!/bin/bash
INPUT=$1
INPUT=${INPUT/> /}
STRING=$(echo $INPUT | cut -d ' ' -f 1)
STRING=${STRING/Non-trimmed/}
HEX=${STRING/Non-tried/}
echo $HEX
printf "%d\n" $HEX

That block number lets me use the -i parameter to set a starting point and -s to set sector size. Then I use a loop to scan through a certain amount of blocks at a time

START=514916352;for x in {0..20000}; do echo $(($START+512*$x)); ddrescue -i $(($START+512*
$x)) -a 1024 -s 512 -O -d /dev/sdx imagefile mapfile; if [[ $? -gt 0 ]]; then START=$(($START+512)); break;fi; done;START=$((
$START+512*$x+512));echo $START;

Share