I recently bought some USB sticks and SD cards. The price was way too good, and I suspect they are counterfeit products. I am not able to find a program to that runs on Ubuntu that can be used to check these cards/sticks. I do not have the skills necessary to compile, so I would like a program that will install easily. Thanks.
3 Answers
There's a Linux program called F3 which can test for fake flash drives. The info and download are at http://oss.digirati.com.br/f3/. It's not a big deal to compile, as it only requires the use of the make
command in terminal. The program is actually two separate programs, f3write and f3read.
Use them in terminal, like this:
cd directory_where_f3_source_is_located
ie: cd ~/Desktop/f3
make
used to compile the program, only required once
./f3write /path_to_flash_drive
ie: ./f3write /media/my_username/my_flash
./f3read /path_to_flash_drive
ie: ./f3read /media/my_username/my_flash
A video can be viewed at https://www.youtube.com/watch?v=qnezKfCTO7E
-
Oh, nice. I heard about that before but thought it was Windows-only. I recommend editing this answer to expand it with specific details about how to install and use this. Oct 30, 2016 at 17:16
What you need to test basically is that the drive can hold the advertised amount of data and "remember" it for later use.
A very simple approach would be to generate a file with random content and the same size as the drive as your test data, write to the drive to test and finally compare the written data with the original file. This requires quite a bit of intermediate storage space and we can do better by just storing an initialization vector for a random number generator. This is what I'll describe below.
I'll assume that the drive to test is located at /dev/sdx
and advertises a total size of 32 GiB = 32768 MiB throughout this question.
Install the
openssl
package if you don't have it yet:sudo apt install openssl
Generate a random initialization vector (IV) for the generation of the test data stream:
openssl rand 32 > ~/template-iv.bin
Write a (pseudo-)random data stream onto the drive until it's full:
dd if=/dev/zero bs=1M count=32768 2>/dev/null | sudo openssl enc -rc4 -nosalt -out /dev/sdx -pass pass:~/template-iv.bin
(Replace the 32768 in
count=32768
with the size of you drive in Mibibytes.)If you specified the correct size for the drive and there are any messages about I/O errors the drive is faulty.
Compare the data on the drive with the same (pseudo-)random data stream:
sudo dd if=/dev/sdx bs=1M iflag=direct | cmp - <(dd if=/dev/zero bs=1M count=32768 2>/dev/null | openssl enc -rc4 -nosalt -pass pass:~/template-iv.bin)
(Replace
count=32768
like before.)There should be 3 lines of status output from the first
dd
command. If there are any messages about I/O errors or comparison mismatches the drive is faulty.
-
-
You specified /dev/loop0 instead of /dev/sdx, but otherwise a very good solution to detect wraparound.– psusiOct 30, 2016 at 17:25
-
@psusi: Thanks for the hint. I tested it with a loop device since I didn't have an unused drive handy. Oct 30, 2016 at 23:37
sudo dd if=/dev/zero of=/dev/sdb
This will fill the entire drive, assuming it shows up as /dev/sdb, with zeros. It will report if there are any errors, and the transfer rate when it finishes, as well as how much data it actually wrote. If there are no errors and the size matches what you expect, it is probably not counterfit.
For a more thorough test using non zero data, you might look at badblocks
.
-
That's not enough unfortunately. Some counterfeit storage media "wrap around" when you try to write beyond their actual size limit. Neither the above
dd
command norbadblocks
can detect that. Oct 30, 2016 at 10:07 -
@DavidFoerster, interesting... I had only heard about cases where they fail to write beyond their real size.– psusiOct 30, 2016 at 17:26