Last active
August 11, 2022 05:39
-
-
Save fopina/3b41fc00604d2b7ba0ce82fff6a7e211 to your computer and use it in GitHub Desktop.
SD Card Speed Test (from Raspberry Pi Agnostics package)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#NAME=SD Card Speed Test | |
#DESC=Determines whether an SD card can read and write data fast enough to provide adequate performance.\n\nShould be run on a new or newly-formatted SD card. | |
# Original at https://raw.githubusercontent.com/raspberrypi-ui/agnostics/1dc4a426e3a2b75276c560b612123a8551b6c0e2/data/sdtest.sh | |
# run with | |
# curl -s https://gist.githubusercontent.com/fopina/3b41fc00604d2b7ba0ce82fff6a7e211/raw/sdtest.sh | sudo bash - | |
# default test file location will be in /var/tmp, you can choose other directory as first parameter of the script | |
# curl -s https://gist.githubusercontent.com/fopina/3b41fc00604d2b7ba0ce82fff6a7e211/raw/sdtest.sh | sudo bash -s /mnt/usb | |
APT_INSTALLS="" | |
which curl > /dev/null || APT_INSTALLS="${APT_INSTALLS} curl" | |
which fio > /dev/null || APT_INSTALLS="${APT_INSTALLS} fio" | |
APT_INSTALL="apt install -y" | |
which apk > /dev/null && APT_INSTALL="apk add" | |
[ -n "${APT_INSTALLS}" ] && $APT_INSTALL ${APT_INSTALLS} | |
TMP_DIR="${1:-/var/tmp}" | |
FFIO="${TMP_DIR}/sd.test.fio" | |
curl -s https://raw.githubusercontent.com/raspberrypi-ui/agnostics/master/data/sd_bench.fio > $FFIO | |
sed -i "s~^directory=.*~directory=$TMP_DIR~" $FFIO | |
for i in 1 2 3 | |
do | |
echo "Run" $i | |
RES=$(fio --output-format=terse --max-jobs=4 $FFIO | cut -f 3,7,8,48,49 -d";" -) | |
echo "$RES" | |
swri=$(echo "$RES" | head -n 2 | tail -n 1 | cut -d ";" -f 4) | |
rwri=$(echo "$RES" | head -n 3 | tail -n 1 | cut -d ";" -f 5) | |
rrea=$(echo "$RES" | head -n 4 | tail -n 1 | cut -d ";" -f 3) | |
pass=0 | |
if [ "$swri" -lt 10000 ] ; then | |
echo "Sequential write speed $swri KB/sec (target 10000) - FAIL" | |
echo "Note that sequential write speed declines over time as a card is used - your card may require reformatting" | |
pass=1 | |
else | |
echo "Sequential write speed $swri KB/sec (target 10000) - PASS" | |
fi | |
if [ "$rwri" -lt 500 ] ; then | |
echo "Random write speed $rwri IOPS (target 500) - FAIL" | |
pass=1 | |
else | |
echo "Random write speed $rwri IOPS (target 500) - PASS" | |
fi | |
if [ "$rrea" -lt 1500 ] ; then | |
echo "Random read speed $rrea IOPS (target 1500) - FAIL" | |
pass=1 | |
else | |
echo "Random read speed $rrea IOPS (target 1500) - PASS" | |
fi | |
rm -f $TMP_DIR/sd.test.file | |
if [ "$pass" -eq 0 ] ; then | |
rm -f $TMP_DIR/sd.test.fio | |
exit $pass | |
fi | |
done | |
rm -f $FFIO | |
exit $pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment