zefie icon

wipe dying disk

zefie | PRO | 01/15/18 05:22:45 PM UTC | 0 ⭐ | 797 👁️ | Never ⏰ | []
Bash |

710 B

|

None

|

0 👍

/

0 👎

#!/bin/bash
DISK="/dev/disk/by-id/ata-WDC_WD20NMVW-59AV3S3_WD-WXQ1EA4F4HS2"
MAX_SECTORS=$(hdparm -I ${DISK} | grep sectors | grep LBA48 | rev | cut -d' ' -f1 | rev)
JUMP=64
LAST=$(cat last)
 
while [ ${LAST} -lt ${MAX_SECTORS} ]; do
        if [ $(expr ${LAST} + ${JUMP}) -lt ${MAX_SECTORS} ]; then
                DIFF=${JUMP}
        else
                DIFF=${MAX_SECTORS} - ${LAST}
        fi
        RANGEEND=$(expr ${LAST} + ${DIFF})
 
        for i in $(seq ${LAST} ${RANGEEND}); do
                hdparm --yes-i-know-what-i-am-doing --write-sector ${i} ${DISK} 2>&1 | grep "sector" | awk '{printf "%s\r", $0}'
        done;
        LAST=$(expr ${LAST} + ${DIFF} + 1)
        echo -n ${LAST} > last
done

Comments