8282
8383Main () {
8484 export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
85+
86+ # check if stdout is a terminal...
87+ if test -t 1; then
88+ # see if it supports colors...
89+ ncolors=$( tput colors)
90+ if test -n " $ncolors " && test $ncolors -ge 8; then
91+ BOLD=" $( tput bold) "
92+ NC=' \033[0m' # No Color
93+ LGREEN=' \033[1;32m'
94+ fi
95+ fi
8596
8697 [ $# -eq 0 ] && (DisplayUsage ; exit 0)
8798
@@ -108,7 +119,7 @@ Main() {
108119} # Main
109120
110121ParseOptions () {
111- while getopts ' hHbBuUrRmMdD ' c ; do
122+ while getopts ' hHbBuUrRmMdDc:C: ' c ; do
112123 case ${c} in
113124 H)
114125 # display full help test
@@ -181,29 +192,25 @@ ParseOptions() {
181192 echo -e "Please post the URL in the Armbian forum where you've been asked for."
182193 exit 0
183194 ;;
195+ c|C)
196+ # check card mode
197+ CheckCard "${OPTARG} "
198+ exit 0
199+ ;;
184200 esac
185201 done
186202} # ParseOptions
187203
188204DisplayUsage() {
189- # check if stdout is a terminal...
190- if test -t 1 ; then
191- # see if it supports colors...
192- ncolors=$(tput colors)
193- if test -n "$ncolors " && test $ncolors -ge 8 ; then
194- BOLD="$(tput bold)"
195- NC='\033 [0 m' # No Color
196- LGREEN='\033 [1 ;32 m'
197- fi
198- fi
199- echo -e "Usage: ${BOLD}${0##*/ } [- h] [- b] [- d] [- m] [- r] [- u]${NC} \n"
205+ echo -e "Usage: ${BOLD}${0##*/ } [- h] [- b] [- d \$path ] [- d] [- m] [- r] [- u]${NC} \n"
200206 echo -e "############################################################################"
201207 if [ ${FullUsage} ]; then
202208 echo -e "\nDetailed Description:"
203209 grep "^#" "$0 " | grep -v "^#\!/bin/bash" | sed 's/^#//'
204210 fi
205211 echo -e "\n Use ${BOLD} armbianmonitor${NC} for the following tasks: \n"
206212 echo -e " armbianmonitor ${BOLD} - b${NC} switches between verbose and normal boot"
213+ echo -e " armbianmonitor ${BOLD} - c / path/ to/ test${NC} performs disk health/ performance tests"
207214 echo -e " armbianmonitor ${BOLD} - d${NC} tries to upload debug disk info to improve armbianmonitor"
208215 echo -e " armbianmonitor ${BOLD} - m${NC} provides simple CLI monitoring"
209216 echo -e " armbianmonitor ${BOLD} - r${NC} tries to install RPi- Monitor"
@@ -642,4 +649,107 @@ BAKBQCAQCAQCgUAgEAgEwjPhPzou6T0AoAAA" | base64 --decode | tar xzf -
642649 esac
643650} # PatchRPiMonitor_for_sun8i
644651
652+ CheckCard() {
653+ if [ "$(id -u)" = "0" ]; then
654+ echo "Checking disks is not permitted as root or through sudo. Exiting" >&2
655+ exit 1
656+ fi
657+
658+ if [ ! -d "$1" ]; then
659+ echo "\"$1\" does not exist or is no directory. Exiting" >&2
660+ exit 1
661+ fi
662+ TargetDir="$1"
663+
664+ # check requirements
665+ which f3write >/dev/null 2>&1 || MissingTools=" f3"
666+ which iozone >/dev/null 2>&1 || MissingTools="${MissingTools} iozone3"
667+ if [ "X${MissingTools}" != "X" ]; then
668+ echo "Some tools are missing, please do an \"sudo apt-get -f -y install${MissingTools}\" before and try again" >&2
669+ exit 1
670+ fi
671+
672+ # check provided path
673+ Device="$(GetDevice "$1")"
674+ set ${Device}
675+ DeviceName=$1
676+ FileSystem=$2
677+ echo "${DeviceName}" | grep -q "mmcblk0" || echo -e "\n${BOLD}WARNING:${NC} It seems you' re not testing the SD card but instead ${DeviceName} (${FileSystem} )\n "
678+
679+ TestDir=" $( mktemp -d " ${TargetDir} /cardtest.XXXXXX" || exit 1) "
680+ date " +%s" >" ${TestDir} /.starttime" || exit 1
681+ trap " rm -rf \" ${TestDir} \" ; exit 0" 0 1 2 3 15
682+
683+ # start actual test, create a small file for some space reserve
684+ fallocate -l 32M " ${TestDir} /empty.32m"
685+ # Start writing
686+ echo -e " Now starting to write to the card, please be patient, this might take a very long time"
687+ f3write " ${TestDir} " | tee /tmp/CheckCard.log
688+ touch " ${TestDir} /.starttime" || (echo -e " \n ${BOLD} Test stopped, read-only filesystem" ; dmesg | grep 'I/O error' ; echo -e " ${NC} " ; exit 1)
689+ rm " ${TestDir} /empty.32m"
690+ # Start verify
691+ echo -e " \n Now verifying the written data:"
692+ f3read " ${TestDir} " | tee -a /tmp/CheckCard.log
693+ touch " ${TestDir} /.starttime" || (echo -e " \n ${BOLD} Test stopped, read-only filesystem" ; dmesg | grep 'I/O error' ; echo -e " ${NC} " ; exit 1)
694+ rm " ${TestDir} /" *.h2w
695+ echo -e " \n Starting iozone tests:"
696+ cd " ${TestDir} "
697+ iozone -e -I -a -s 100M -r 4k -r 512k -r 16M -i 0 -i 1 -i 2 " ${TestDir} " | tee -a /tmp/CheckCard.log
698+ touch " ${TestDir} /.starttime" || (echo -e " \n ${BOLD} Test stopped, read-only filesystem" ; dmesg | grep 'I/O error' ; echo -e " ${NC} " ; exit 1)
699+ echo -e " \n ${BOLD} The results from testing ${DeviceName} (${FileSystem} ):${NC} "
700+ egrep " Average| Data" /tmp/CheckCard.log | sort -r
701+ echo " random random"
702+ echo -e " reclen write rewrite read reread read write\c "
703+ awk -F" 102400 " '/102400/ {print $2 }' </tmp/CheckCard.log
704+
705+ # check health
706+ echo -e " \n ${BOLD} Health summary: \c "
707+ grep -q " Data LOST: 0.00 Byte" /tmp/CheckCard.log && echo " OK" || \
708+ (echo -e " ${DeviceName} is faulty. Replace it as soon as possible! " ; \
709+ grep -A3 " ^Data LOST" /tmp/CheckCard.log)
710+
711+ # check performance
712+ RandomSpeed=$( awk -F" " ' /102400 4/ {print $7"\t"$8}' < /tmp/CheckCard.log)
713+ set ${RandomSpeed}
714+ RandomReadSpead=$1
715+ RandomWriteSpead=$2
716+ ReadSpeed=$( awk -F" " ' /Average reading speed/ {print $4"\t"$5}' < /tmp/CheckCard.log)
717+ set ${ReadSpeed}
718+ if [ " X$2 " = " XMB/s" ]; then
719+ RawReadSpead=$( echo " $1 * 1000" | bc -s | cut -f1 -d.)
720+ else
721+ RawReadSpead$( echo " $1 " | cut -f1 -d.)
722+ fi
723+ echo -e " \n Performance summary:${NC} \n Sequential reading speed: $1 $2 \c "
724+ [ ${RawReadSpead} -le 5000 ] && echo -e " ${BOLD} (too low)${NC} \c "
725+ echo -e " \n 4K random reading speed:$( printf " %6s" ${RandomReadSpead} ) KB/s \c "
726+ [ ${RandomReadSpead} -le 1500 ] && echo -e " ${BOLD} (too low)${NC} \c "
727+ WriteSpeed=$( awk -F" " ' /Average writing speed/ {print $4"\t"$5}' < /tmp/CheckCard.log)
728+ set ${WriteSpeed}
729+ if [ " X$2 " = " XMB/s" ]; then
730+ RawWriteSpeed=$( echo " $1 * 1000" | bc -s | cut -f1 -d.)
731+ else
732+ RawWriteSpeed=$( echo " $1 " | cut -f1 -d.)
733+ fi
734+ echo -e " \n Sequential writing speed: $1 $2 \c "
735+ [ ${RawWriteSpeed} -le 5000 ] && echo -e " ${BOLD} (too low)${NC} \c "
736+ echo -e " \n 4K random writing speed:$( printf " %6s" ${RandomWriteSpead} ) KB/s \c "
737+ [ ${RandomWriteSpead} -le 750 ] && echo -e " ${BOLD} (too low)${NC} \c "
738+ echo -e " \n\n To interpret the results above correctly or search for alternatives
739+ please refer to http://oss.digirati.com.br/f3/ and also
740+ http://www.jeffgeerling.com/blogs/jeff-geerling/raspberry-pi-microsd-card
741+ http://thewirecutter.com/reviews/best-microsd-card/"
742+ } # CheckCard
743+
744+ GetDevice() {
745+ TestPath=$( findmnt " $1 " | awk -F" " ' /\/dev\// {print $2"\t"$3}' )
746+ if [[ -z ${TestPath} && -n " ${1%/* } " ]]; then
747+ GetDevice " ${1%/* } "
748+ elif [[ -z ${TestPath} && -z " ${1%/* } " ]]; then
749+ findmnt / | awk -F" " '/\/dev\// {print $2 " \t " $3 }'
750+ else
751+ echo " ${TestPath} "
752+ fi
753+ } # GetDevice
754+
645755Main " $@ "
0 commit comments