Repair: Corrupted SD Card on Raspberry Pi

RECOMMENDED: Click here to fix Windows errors and optimize system performance

Have you ever experienced that your Raspberry Pi no longer wears boots? The red and yellow lights flash several times and then stop? These are the classic symptoms of a damaged SD card.

The first thing you can do is to regularly back up your SD card BEFORE it is damaged. If you spend hours configuring an SD card, save it. Do you modify your software? Go back to it. This will save you a lot of time if you damage or destroy the SD card.

Similarly, incorrect shutdown of the Raspberry Pi often results in damage to the operating system. To stop safely, you must open a command line and type the following command:

sudo shutdown -h now

You can also use the stop option on the desktop graphical interface.

To repair damaged SD cards on Raspberry Pi

The only thing that makes the situation worse is the lack of backups for the affected SD card. If you do not have backups, you are unlikely to recover the contents of the damaged SD card.

There are several reasons why an SD card on your Raspberry Pi is damaged, but the most common is to turn it off without the “stop” command. If you have interfered with the CPU clocks, power problems can also damage the SD cards.

April 2021 Update:

We now recommend using this tool for your error. Additionally, this tool fixes common computer errors, protects you against file loss, malware, hardware failures and optimizes your PC for maximum performance. You can fix your PC problems quickly and prevent others from happening with this software:

  • Step 1 : Download PC Repair & Optimizer Tool (Windows 10, 8, 7, XP, Vista – Microsoft Gold Certified).
  • Step 2 : Click “Start Scan” to find Windows registry issues that could be causing PC problems.
  • Step 3 : Click “Repair All” to fix all issues.


So what can you do if this happens? You can format the SD card and restore it to your SD card using Raspbian backups. However, if you made a mistake working without timely backups, you can only try two things. There is a “fsck” command that will probably not repair your damaged SD card.


The file system consistency utility is usually able to find and recover damaged file systems. My systems perform a file system check every time they start, and they receive a regular restart. The SD card has an ext4 file system and is 16 GB in size.

As you can usually repair defective file systems with a fsck, I connected the card to my computer and started the fsck:

# fsck /dev/mmcblk0p2

Scratch Files

You must create the folder /var/cache/e2fsck if it does not exist before running fsck :

mkdir -p /var/cache/e2fsck

The scratch_files stanza has more options, two of which can be important, dirinfo set and icount set.

You configure dirinfo as false if your file system has a large number of individual files and not as many directories. You set the icount setting to false if the reverse setting is true. Otherwise, set both to true.

If you use a Raspberry Pi, you must make sure that everything is properly connected, just like a typical desktop computer. Before you even start for the first time, make sure you have the necessary cables, devices and storage media at hand.

Knowing how to properly turn off the Raspberry Pi is absolutely crucial and can save you a lot of time if you rebuild your SD card in case of data corruption.

RECOMMENDED: Click here to troubleshoot Windows errors and optimize system performance