Created
April 18, 2024 01:21
-
-
Save ChatchaiJ/73373e131d77b28300f60091290ec854 to your computer and use it in GitHub Desktop.
check that sdcard that how much actually it could contain data
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/sh | |
SDCARD="$1" | |
RANDFILE="/tmp/rand10m" | |
TMPBIN="/tmp/tmp.bin" | |
MAGICWORD="--i-know-what-i-am-doing" | |
BS="10240" | |
COUNT="1024" | |
[ -z "$2" ] && \ | |
{ echo "Usage: $0 /dev/sde ${MAGICWORD}"; exit; } | |
[ "$2" != "${MAGICWORD}" ] && \ | |
{ echo "Well, please use magicword"; exit; } | |
[ -f "${TMPBIN}" ] && sudo rm -f ${TMPBIN} | |
if [ ! -f "${RANDFILE}" ]; then | |
dd if=/dev/random of=${RANDFILE} bs=${BS} count=${COUNT} | |
fi | |
RANDSUM=$(md5sum ${RANDFILE} | cut -f1 -d' ') | |
FILESZ=$(expr ${BS} \* ${COUNT}) | |
C=0 | |
while true; do | |
ISEEK=$(expr ${C} \* ${COUNT}) | |
OSEEK=${ISEEK} | |
C=$(expr ${C} + 1) | |
echo "===== [$C] =====" | |
echo "=== Write [$C] ===" | |
sleep 1 | |
sudo dd if=${RANDFILE} of=${SDCARD} bs=${BS} \ | |
count=${COUNT} oseek=${OSEEK} status=progress conv=sync | |
echo "" | |
echo "=== Read [$C] ===" | |
sleep 1 | |
sudo dd if=${SDCARD} of=${TMPBIN} bs=${BS} \ | |
count=${COUNT} iseek=${ISEEK} status=progress conv=sync | |
echo "" | |
echo "=== MD5CHECK [$C] ===" | |
sleep 1 | |
SUM=$(md5sum ${TMPBIN} | cut -f1 -d' ') | |
if [ "${SUM}" != "${RANDSUM}" ]; then | |
echo "FAILED : SUM = ${SUM}" | |
break | |
else | |
echo "OK" | |
fi | |
echo "" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment