Verifying sdcards

TL;DR: Verify sdcards on the fly

DEV=/dev/sdX && \
dd if=/dev/urandom bs=4096 count=$(( $(sudo blockdev --getsz $DEV) / 8)) \
| pv | sudo tee $DEV | md5sum ; \
sudo dd if=$DEV bs=4096 count=$(( $(sudo blockdev --getsz $DEV) / 8 )) \
| pv | md5sum

I have a few sdcards which are probably counterfeit or plain broken. So I’ve developed a one liner to check the sdcard. The good part is that no temporary files are created. All data on the device is deleted.

This line reads out the fast pseudo random number generator. This data is written to the sdcard and also piped via ‘tee’ to md5sum.

In the second step, the data is re-read from the sdcard and piped into md5sum. ‘pv’ is used as progress indicator. You can leave it out. Here is an example output for a 32GB card:

7745280+0 records in6MiB/s] [ ]
7745280+0 records out
31724666880 bytes (32 GB, 30 GiB) copied, 3269.12 s, 9.7 MB/s
29.5GiB 0:54:29 [9.25MiB/s] [ ]
455fd3232c655fd8c2224116af3b2bc1 -
7745280+0 records in9MiB/s] [ ]
7745280+0 records out
31724666880 bytes (32 GB, 30 GiB) copied, 1731.66 s, 18.3 MB/s
29.5GiB 0:28:52 [17.5MiB/s] [ ]
455fd3232c655fd8c2224116af3b2bc1 -

The md5sums 455fd3232c655fd8c2224116af3b2bc1 match. ‘dd’ even shows the read and write data transfer rate.

If you want to reset the sdcard and discard all sectors you can

sudo blkdiscard $DEV


  1. Pingback: Teardown: SportDV Camera – whatumake

Leave Comment