Ahmed Essam

How to recover a corrupted flash memory using F3 tools under Linux

Note: This tutorial requires Linux. If you want to test your flash under windows check out: test-and-detect-fake-flash-with-h2testw

So you have a corrupted flash memory, you copy files into it and when you try to open it later, they don’t work. There are number of reasons for this problem, one of them is aging, flash memories have a lifetime too and there is a limited number of writes. If this was the cause of the problem, then it is time to retire it. Another reason could be that you have a counterfeit or defected flash, I will show you how to get something out of it in this case, but don’t expect much.

Recently someone brought to me a 200GB flash memory having this problem, from the looks of it you can tell for sure that it is a counterfiet. After using F3 tools on it, I found that its actual size is 100MB. F3 was able to recover this 100MB and it was working fine as a flash memory with a partition size equal to 0.005% of it is declared size!

In this tutorial, I will show you how to test your flash memory for problems using F3 command line tools, and if possible, recover its working part.

So what is F3?

F3 is an open source command line utility created by Michel Machado. You can find the package in the official Debian repositories and probably in your distrubtion repositories. The package description says:

F3 (Fight Flash Fraud or Fight Fake Flash) tests the full capacity of a flash card (flash drive, flash disk, pen drive).

F3 writes to the card and then checks if can read it. It will assure you have not been bought a card with a smaller capacity than stated. Note that the main goal of F3 is not to fix your removable media. However, there are resources to mark the invalid areas.

This package provides these executables: f3write, f3read, f3brew, f3fix and f3probe.

Fair enough, lets get started. Install the package or build from source:

Test the flash

First, we will test the flash thoroughly. We will fill it with data, then check this data for errors. Format the flash, mount it, then pass the mount folder to f3write to start filling it:

Then do the check:

The time this check takes depends on the declared size of your flash. If the flash passed this test without a problem, then your flash is working fine. If you get data losses, then, unfortunately, it’s corrupted. Keep reading to find out its actual size and see if you can get something out of it.

Fix attempt

I had an old 1GB flash which had a defected part from the time I got it. Here is the result I had from testing it using f3write and f3read:

The results show clearly that half of my old flash is corrupted. f3probe probes flash for counterfeits and identifies its real size. However, this tool is experimental according to the author. It is data destructive, takes a device as an argument. Use it on unmounted flashes.

Take extreme care not to pass the wrong device. Double check by running lsblk, here is the first lines of my output of lsblk:

My device is /dev/sdc. I made f3probe /dev/sdc and after a few seconds I got the following:

f3probe output says my device is a counterfeit and its real size is 496 MB which is similar to the working part size from the read and write test. Further more, it gave me the command to fix it, your fix command will be different from mine. It fixes the flash by creating a partition from the working part only and discard the fake part. I disconnected the device and inserted it again before running the given command:

That’s it, this last command took no time at all. I formatted my flash as usual and it was working fine. To understand what f3fix did, here is a screenshot of my flash device in Gparted partition editor.

Gparted screenshot of the fixed flash

The green rectangle is the newly created partition that f3fix created. The rest is the fake part which is now left without partitioning. It is clear that this is not a permanent fix, you can recreate partitions anytime, that’s what I did for the purpose of this tutorial. But if you left the partition table as f3fix did, you should be able to format this partition and use it without a problem.

At last, you need to test the flash partition. Sometimes the first test fails after fixing. From the f3 docs:

If you get some sectors corrupted, repeat the f3write/f3read test. Some drives recover from these failures on a second full write cycle. However, if the corrupted sectors persist, the drive is junk because not only is it a fake drive, but its real memory is already failing

I tested mine and this was the result:

That will be all. Hope you found this tutorial useful.

Web developer, Arabic Native, open-source enthusiastic, trying to do things the right way.