Hi all, as many of you know, I've long held that people spend too long agonising over the use of SD-Cards in Pi's. A decent card (so that it supports wear levelling) with plenty of free space should last years.
Well I now have another data point on that subject. And I bring you a possible recovery solution.
Last week the SD-Card on my Pi3 failed. It is a Samsung EVO Plus 32GB. It lasted some 1,182 days, that is 3 years, 2 months and 25 days. A similar card in my older Pi2 has lasted 2,133 days so far (5 years, 10 months and 3 days) and is still going strong. I did nothing on either Pi to reduce the number of writes to the cards.
If you want to work out the age of your filing system, use the
sudo lsblk
command to find the name of the partition. Then use the commandsudo dumpe2fs /dev/mmcblk0p2 | grep 'Filesystem created:'
to get the date the filing system was created.
Whilst I do have all the data I needed backed up, I thought that it would be a useful exercise to see if I could actually recover the data from the card. In my case it was pretty easy - of course, your mileage is very likely to vary.
Always have a backup!
In this case, the card wouldn't mount or be read either by Windows nor by Linux.
To have the best chance at getting a successful image of the broken card:
sudo apt install gddrescue
# Obviously change the block device id to the one you discovered using lsblk
sudo ddrescue -d -r3 /dev/mmcblk0 sd-card-copy-rescue.img sd-card-copy-rescue.logfile
This will take some time to run. you can adjust the settings if you like. -d
uses direct disk access (not the kernel cache), -r3
means retry bad sector reads 3 times. Retry's can make matters worse of course on a failing disk but isn't likely to have a negative impact on a corrupted SD-Card.
Once you have a successful image (assuming it works), mount the image file:
sudo losetup --partscan --find --show ./sd-card-copy-rescue.img /dev/loop0
# You might want to check that /mnt is actually empty first or mount to a sub-folder
# In my case p2 is the root partition and p1 the boot partition. That should be common for Pi cards.
sudo mount /dev/loop0p2 /mnt
ls /mnt
For me, that worked just fine and seems to have recovered all files that I would be interested in. Again, it might not work for you and you should always have a backup of course.
An interesting exercise and didn't take very long even with the Google research to piece everything together. In a hurry, you could do it all in 1/2 hr. Anyway, documented here in case of future need.