Skip to content

Instantly share code, notes, and snippets.

@roarc0
Last active December 8, 2017 10:52
Show Gist options
  • Save roarc0/d5e4252a054d28875a03f65cd72a2d12 to your computer and use it in GitHub Desktop.
Save roarc0/d5e4252a054d28875a03f65cd72a2d12 to your computer and use it in GitHub Desktop.
badblocks helper script
#!/bin/sh
# ./badb.sh /dev/sdd 0.9
# starts from 90th% block of the device using 4k blocks.
DEV=$(basename $1)
BLOCKS=$(cat /proc/partitions| grep $DEV| awk 'NR==1{ print $3 } ')
SIZE=1024
NB=4
BSIZE=$(( SIZE * NB ))
echo "total 1k blocks: $BLOCKS"
BLOCKS=$(( BLOCKS / NB - 1 ))
echo "total ${NB}k blocks: $BLOCKS"
START=0
if [ -n $2 ]; then
START=$(echo "$BLOCKS * $2"| bc)
START=$(printf "%.0f" $START )
fi
echo "start block: $START"
sudo umount ${1}1 || true
sudo badblocks -nsv -b $BSIZE -p 1 -c 32768 -o badblocks-$DEV.txt $1 $BLOCKS $START
#!/bin/sh
DEV=$(basename $1)
BLOCKS=$(cat /proc/partitions| grep $DEV| awk 'NR==1{ print $3 } ')
SIZE=1024
NB=4
BSIZE=$(( SIZE * NB ))
echo "total 1k blocks: $BLOCKS"
BLOCKS=$(( BLOCKS / NB - 1 ))
echo "total ${NB}k blocks: $BLOCKS"
START=0
if [ -n $2 ]; then
START=$(echo "$BLOCKS * $2"| bc)
START=$(printf "%.0f" $START )
fi
echo "start block: $START"
sudo umount ${1}1 || true
sudo badblocks -nsv -b $BSIZE -p 1 -c 32768 -o badblocks-$DEV.txt $1 $BLOCKS $START
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment