[Gllug] [OT] Testing SDHC cards

general_email at technicalbloke.com general_email at technicalbloke.com
Tue Jan 4 02:47:23 UTC 2011

On 31/12/10 19:16, James Courtier-Dutton wrote:
> Hi,
> Are there any good Linux tools for testing SDHC cards.
> What I want is a tool that does a good test of the SDHC card before I
> use it in order to try and find out if it is a good or bad card.
> I currently have a number of Transcend SDHC cards and although I have
> not had problems with them yet, would like to find some way to be
> sure.
> For example, if a SDHC is marked Class 10, how can I test to see if it
> is really a Class 10 device.
> I would also like to be able to test if every sector on the card is
> good for both read and write.
> Any ideas?
> James

You could just use dd and hashing.

Find out how many blocks your card has (assuming your card is /dev/sdg):
cat /sys/class/block/sdg/size

Create a file of random noise the exact same size. 'count' is the number
from the above command, block size ('bs') is normally 512...
sudo dd if=/dev/urandom of=/var/noise.dd bs=512 count=8274944

TBH you don't even really need it to be that random, just fairly high
entropy, and /dev/urandom is SLOW so you could speed things up by
copying that number of blocks from a movie file or something similarly
compressed/encrypted. Do be careful with dd though, make sure you never
mix up your 'if' and 'of' !

Calculate that file's md5 hash:
md5sum /var/noise.dd

DD the file to your card. Here you could either time how long it takes
to write the whole thing and do the maths to figure out the write rate
or use Gnu's DD rescue to do the copying - that displays the bitrate of
the transfer as it happens. "Class 10" devices are only 10MB/s which is
rather slow compared to modern hard disks, gigabit Ethernets and USB2
ports so you're unlikely to have any bottlenecks elsewhere that might
affect the result. Note gnu's ddrescue ('gddrescue' in debian repos)
syntax is subtly different, it doesn't use 'if' and 'of', instead
relying on parameter order source first, destination second:
sudo ddrescue /var/noise.dd /dev/sdg

Next dd the file back from the card, calculate it's hash and compare it
to the one we made earlier to verify it's integrity. Again dd rescue may
be better than straight dd as it will show you the read rate in real
time as it copies.

Naturally this process will completely (and thoroughly!) wipe the cards
and you will have to reformat them before using them in your camera again!

Also, and especially with larger cards, this will be like watching paint
dry so you may want to script it and have your script beep when it's done!



Gllug mailing list  -  Gllug at gllug.org.uk

More information about the GLLUG mailing list