The other day we managed to zap one of our Raspberry Pi's microSD cards. This was our own fault; for months the Pi had been crashing due to a segmentation fault. We never got around to finding the root cause, and suddenly the Pi would no longer boot.
In the past, I would normally just give up on the card and start over again, however in this case, we had put a lot of time into this particular image.
So, I got to work trying to figure out how to recover the SD card.
We tried many things, but here is what actually worked!
We put the SD card into a reader and inserted it into a working Raspberry Pi. Running sudo fdisk -l listed the partitions on the system. In this case, sdc was the bad SD card.
Device Boot Start End Sectors Size Id Type
/dev/sdc1 8192 93814 85623 41.8M c W95 FAT32 (LBA)
/dev/sdc2 94208 15523839 15429632 7.4G 83 Linux
We tried mounting sdc2, using sudo mount /dev/sdc2 /mnt, and this resulted in a Bad Superblock error. Without getting into details, this means that the database on the SD card of all the stuff on the SD card was damaged
Fortunately, Linux is smart enough to create backup superblocks!
To find the backup superblocks, we ran mke2fs -n /dev/sdc2.
There were were a few backups superblocks, but the one we used was 32768
To restore, we ran sudo e2fsck -b 32768 /dev/sdc2
When running, many errors came up and we just chose the default options. You might consider running e2fsck with the -a option, which ignores all errors and attempts to automatically fix them. Only do this if this is an option of last resort.
When e2fsck was done, we were able to mount the drive, proving that miracles DO happen. We have not tried to boot using this SD card, nor do we plan to. My goal was to recover some files and put them on our new system, which is running off a USB drive instead of SD card.
Comments will be approved before showing up.