20 Nov 2018

Rescue files from a failing Raspberry Pi SD card

Source code

I recently had a problem with a particular Raspberry Pi and was able to rescue some files. I thought I’d document this here in case it’s useful.

Raspberry Pi SD card mcc0 errors

When powered on, I got an endless output of “mmc0: fsm 1, hsts 1” scrolling on the screen. Not good!

My limited understanding of this error is that “mmc” means “multi-media card”, so the Raspberry Pi isn’t happy with the SD card. I’m not sure what caused this, but I suspect it’s corruption from age (this Raspberry Pi has been running 24/7 for a couple years), or something may have been corrupted due to power failure (despite using ext4).

I can easily flash a new SD card, but I wanted to try and retrieve the MySQL database from the broken SD card if possible. To copy to and from SD cards with my Linux PC, I usually use the dd command. However, this didn’t work in this situation because dd will exit as soon as it encounters an error, so you generally won’t get anywhere near a full image if there is a problem.

Instead I used ddrescue, like this:

$ sudo apt-get install ddrescue
$ sudo ddrescue -dr3 /dev/sdc rescue.img ddrescue.log

This will take a very long time! To rescue an 8GB SD card took me about 15+ hours, so I left it running overnight.

The next day, it had finished with this result:

$ sudo ddrescue -dr3 /dev/sdc rescue.img ddrescue.log
GNU ddrescue 1.22
ipos: 7334 MB, non-trimmed: 0 B, current rate: 0 B/s
opos: 7334 MB, non-scraped: 0 B, average rate: 144 kB/s
non-tried: 0 B, bad-sector: 328192 B, error rate: 21 B/s
rescued: 7947 MB, bad areas: 127, run time: 15h 17m 18s
pct rescued: 99.99%, read errors: 2717, remaining time: 5h 21m
time since last successful read: 1m 36s

99.99% rescued is a promising result. 🙂

The raspberry pi boot partition was still not recognised, so it wouldn’t boot (just a blank screen). But I was able to read the root partition on another Linux PC and had access to all my files again for restoration.

From here I was able to retrieve some mysql data files and restore them on a fresh Raspberry Pi SD card installation.

These instructions may or may not work for you. I’ve had plenty of other corrupt SD cards that I was unable to rescue. Good luck!

About the Author:

Hardware and software engineer with experience in product development and building automation. Director at Cabot Technologies and Product Manager at NEX Data Management Systems.

Leave a Reply


This site uses Akismet to reduce spam. Learn how your comment data is processed.