Skip to content

Instantly share code, notes, and snippets.

@agrajag9
Last active July 3, 2020 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agrajag9/7c2ce460c0bc9e18a5b85ce686fffe8c to your computer and use it in GitHub Desktop.
Save agrajag9/7c2ce460c0bc9e18a5b85ce686fffe8c to your computer and use it in GitHub Desktop.
FreeBSD hdd burn-in script
#!/bin/sh
BLOCKS_SIZE=${BLOCKS_SIZE:-32768}
STRIDE_SIZE=${STRIDE_SIZE:-512}
ROOTDIR=`pwd`
DEV=$1
GEOM=${DEV##*/}
# Did we get an arg?
if [ "x$DEV" == "x" ]
then
echo "Please enter a valid character device"
exit 1
fi
# Valid GEOM disk?
geom disk status $GEOM >/dev/null 2>&1
if [ $? -ne 0 ]
then
echo "Invalid GEOM disk"
exit 2
fi
# Valid character device?
if [ ! -c $DEV ]
then
echo "Invalid character device"
exit 3
fi
# Make sure we have all the tools
TOOLS="smartctl badblocks"
set +e
for i in $TOOLS
do
TOOL_PATH=`which $i`
if [ "x$TOOL_PATH" == "x" ]
then
echo "Tool $i is not installed"
exit 4
fi
done
set -e
# SMART short test
/usr/local/sbin/smartctl --test=short $DEV
REMAINING=$( smartctl -c $DEV | grep -F "% of test remaining" | awk '{print $1}' )
while [ x$REMAINING != "x" ]
do
echo "$DEV: $REMAINING remaining in short test, sleeping for 10s..."
sleep 10
REMAINING=$( smartctl -c $DEV | grep -F "% of test remaining." | awk '{print $1}' )
done
echo "$DEV: Short test complete. Conveyance test is next."
# SMART conveyance test
# disable exit on fail since some drives may not support SMART conveyance test (WD Gold, I'm looking at you...)
set +e
smartctl --test=conveyance $DEV
REMAINING=$( smartctl -c $DEV | grep -F "% of test remaining" | awk '{print $1}' )
while [ x$REMAINING != "x" ]
do
echo "$DEV: $REMAINING remaining in conveyance test, sleeping for 10s..."
sleep 10
REMAINING=$( smartctl -c $DEV | grep -F "% of test remaining." | awk '{print $1}' )
done
echo "$DEV: Conveyance test complete. Long test is next."
set -e
# SMART long test
smartctl --test=long $DEV
REMAINING=$( smartctl -c $DEV | grep -F "% of test remaining" | awk '{print $1}' )
while [ x$REMAINING != "x" ]; do
echo "$DEV: $REMAINING remaining in long test, sleeping for 15min..."
sleep 900
REMAINING=$( smartctl -c $DEV | grep -F "% of test remaining." | awk '{print $1}' )
done
echo "$DEV: Long test complete. badblocks is next."
# backblocks - this one takes a few days...
echo "Running badblocks with BLOCKS_SIZE=${BLOCKS_SIZE} and STRIDE_SIZE=${STRIDE_SIZE}"
echo "This one can take a few days, so we'll create a PID in case you need to kill it"
echo "Outputs to ${ROOTDIR}/badblocks_${GEOM}.out"
badblocks -b $BLOCKS_SIZE -c $STRIDE_SIZE -wsv $DEV >${ROOTDIR}/badblocks_${GEOM}.out 2>&1 &
echo $! >/var/run/badblocks_${GEOM}.pid
# wait for badblocks to finish...
wait
echo "badblocks is complete!"
# Make sure it all worked I guess
smartctl --all $DEV >${ROOTDIR}/smart_${GEOM}.out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment