Is there a way to estimate the lifetime of a SD card? If not, is there a utility I can use that monitors its integrity and reliability so I know when to use a new SD card?
There are several tools that will check integrity of a filesystem, and recurring errors will point to a SD card reaching the end of its lifetime.
fsck is a commonly used Linux application and you can use it to check a partition like this:
x is the partition number.
As for estimating the lifetime, the Sandisk Product Manual states:
SanDisk SD cards have an endurance specification for each sector of 100,000 writes typical (reading a logical sector is unlimited).
However, I do not know how many read/writes the typical OS uses on average.
SD cards do the monitoring themselves, so you don't have to. Modern commercial-grade SD cards will use sophisticated wear leveling algorithms which detect and isolate bad blocks as they appear, so at any given moment no bad blocks are exposed to the file system. That's why HDD tools like
badblocks (and by extension
fsck) are useless for failure prediction: they will show you the card is fine even if it is already aging.
Things keep going until the SD card runs out of reserved spare blocks, at which point most cards permanently lock themselves to read-only mode. This is intended to give the user a chance to read out the data and move it to another medium. This is how you know you need to get a new one.
Since the card typically runs out of spare blocks while you're writing on it, having journaling enabled greatly helps to recover your data.
If you really want to anticipate a failure, get an SSD and keep your data there. Then you'll be able to use
smartctl to check how many blocks have already been relocated internally, and how many more remain, often represented as a percentage of the estimated lifetime of your SSD.
You can scan all blocks of your partitions with
time badblocks -sv /dev/mmcblk0p2 -o mmcblk0p2.log
mmcblk0p2 refers to the partition and has to be replaced by the partition to scan. You can list your partitions with
Bad blocks will be recorded to the log file.
Unmounting of the file system is not necessary.
You can also do non-destructive write tests (
-n option), if you find it necessary.
If you don't need to preserve the data you can also do faster (destructive) write test (
For ATP branded Industrial SD Cards, they provide "SD Lifetime Monitoring Tool" software for Linux/Windows. But if you use this tool you must run this tool from a Host Operating System. That means you can not use this software inside SD Card to check itself. Because if you run this software, SD card can not be accessable.
For Reference - Google: ATP Industrial Grade SD Card Specification (Revision 3.8)
I just came across a tool to check Panasonic SD Cards for remaining endurance:
It only has Mac and Windows versions though.