A corrupted Raspberry Pi SD card is usually recoverable if you stop writing to it. Shut the Pi down, put the card in a USB reader on another Linux computer (a second Pi works), and copy the whole card to an image file before you try any repair. Then check the two partitions without mounting them: fsck.fat for the small FAT boot partition and e2fsck for the ext4 root partition. If the repair fails, mount the copy read-only, pull your files off, and write a fresh image.
The short version: image first, repair second, reflash third. The two usual causes are power lost during a write and a card that has worn out, and Raspberry Pi’s own white paper on the subject says a failing card typically shows up as random file corruption. If the same card corrupts again on a good power supply, replace it. If it keeps happening to good cards, the fix is fewer writes, a clean shutdown every time, and for unattended projects the built-in Overlay File System option.

Why Raspberry Pi SD cards get corrupted
Raspberry Pi Ltd explains the mechanism in its white paper Making a more resilient file system (updated August 2026). Three points from it matter here.
- Linux does not write immediately. Data waits in a RAM cache and is flushed in batches. Pull the plug before a flush and that data is gone. Pull it during the brief moment the card is physically storing data and the data being written can be damaged.
- Flash wears out. SD cards have a limited number of write cycles. Wear levelling spreads the load, but the paper says cards still fail after anything from months to years depending on how much is written, and that lifetime varies a lot between cards.
- The Pi writes even when your project doesn’t. Linux logs in the background constantly, so an “idle” Pi is still writing.
Two design details explain the symptoms you see. The root partition is ext4, which keeps a journal. The journal protects the structure of the file system after an interrupted write, but not the contents of the file that was being written, so one file can still end up truncated. And, as the white paper describes, ext4 uses errors=remount-ro by default: when the kernel detects an inconsistency it switches the file system to read-only to stop the damage spreading. The boot partition is FAT, which has no journal at all. A write to it that gets interrupted, such as a firmware or kernel update, can leave a Pi that will not boot.
Symptoms and what they point to
| What you see | Likely cause | First move |
|---|---|---|
| “Read-only file system” errors; nothing can be saved or installed | ext4 found an inconsistency and remounted read-only | Shut down, image the card, run e2fsck from another machine |
| Green ACT LED flashes 4 times, pauses, repeats | Firmware cannot find its start*.elf file on the boot partition | Check the FAT partition with fsck.fat; reflash if files are missing |
| ACT LED flashes 7 times | Kernel image not found | Same as above |
| 2 long flashes then 1 short, or 2 long then 2 short | Partition is not FAT, or the firmware failed to read from it | Try the card in a reader; if the computer cannot read it either, the card is suspect |
| Boots, but random programs crash or files are garbled | Worn card, or an earlier unclean shutdown | Back up now, then check; plan to replace the card |
| A freshly written card corrupts again within days | Bad power, or a failing card | Check the supply first, then retire the card |
The flash counts come from the LED warning code table in the Raspberry Pi configuration documentation. Long flashes come first, then short ones, and the pattern repeats after a two-second pause. A blank screen with a steady boot is a different fault; see our guide to a Raspberry Pi 3 B+ with no HDMI signal.
What you need
- A USB microSD card reader.
- A computer running Linux, or a second Raspberry Pi booted from a known-good card. Windows and macOS can open the FAT boot partition but do not read the ext4 root partition without extra software.
- Free disk space at least equal to the card’s full capacity, for the image file.
- A spare microSD card for the rebuild.
Step-by-step recovery
Before you start: every command below takes a device name. Run lsblk -f before and after plugging in the reader and use the device that appears. This guide writes it as /dev/sdX; yours will be a real letter. Getting it wrong can damage the wrong disk.
- Stop using the card. If the Pi still responds, shut it down properly and remove power. Every extra boot on a damaged file system risks more damage.
- Connect the card and make sure it is not mounted. Desktop Linux often mounts cards automatically. If lsblk shows a mount point next to either partition, unmount it with sudo umount followed by that mount point. The e2fsck manual is blunt that it is not safe to run it on a mounted file system.
- Copy the whole card to an image. Install GNU ddrescue (the Debian and Raspberry Pi OS package is gddrescue) and run sudo ddrescue -n /dev/sdX pi-card.img pi-card.map. The order is input, output, map file. Unlike a plain copy, ddrescue rescues the readable areas first when it hits read errors. The -n option skips the slow scraping phase on this first pass.
- Retry the bad areas, if any. Run it again with the same map file: sudo ddrescue -d -r3 /dev/sdX pi-card.img pi-card.map. Here -d uses direct disc access and -r3 allows three retry passes. The map file is what lets ddrescue resume rather than start over, so always give it one, and never reuse a map from a different card.
- Check without changing anything. Run sudo fsck.fat -n /dev/sdX1 and sudo e2fsck -f -n /dev/sdX2. With -n both tools only report. On e2fsck, -f forces a full check even if the file system is flagged clean.
- Repair the safe problems. Run sudo fsck.fat -a /dev/sdX1 and sudo e2fsck -f -p /dev/sdX2. The -p (“preen”) mode fixes what can be fixed safely and stops with exit code 4 if something needs a decision. Only then consider sudo e2fsck -f -y /dev/sdX2, which answers yes to every question. You already have the image, so a bad outcome is not final.
- Test. Put the card back in the Pi and boot. If it runs, copy your data off before you trust it with anything else.
- If the repair fails, recover from the image. Attach it with sudo losetup -fP –show -r pi-card.img. The command prints the loop device it used, -P makes the kernel scan the partition table, and -r keeps it read-only. Run lsblk to see the partitions under that loop device, and mount the larger one with sudo mount -o ro,noload, the loop partition, and an empty folder. The mount manual explains why plain read-only is not enough: ext4 replays its journal, which is a write, when the file system is dirty, and noload skips that. Copy out your home directory and configuration files, then unmount and detach with sudo losetup -d and the loop device name.
- Rebuild on a fresh image. Write Raspberry Pi OS to a card with Raspberry Pi Imager and restore your files. The getting started documentation recommends at least 32 GB for the desktop versions and at least 8 GB for Raspberry Pi OS Lite. For an older board, see our OS guide for the Pi 3 B+.
Reading e2fsck exit codes
e2fsck reports its result as a number, and the values add together. The list is from the e2fsck manual page.
| Exit code | Meaning | What to do |
|---|---|---|
| 0 | No errors | The file system is not your problem; look at power or the card itself |
| 1 or 2 | Errors corrected (2 adds “system should be rebooted”) | Boot and test |
| 4 | Errors left uncorrected | Rerun with -y, or recover files from the image |
| 8 | Operational error | The check could not run properly; work from the image |
If the Pi still boots: check at the next start
The stock Raspberry Pi OS image already carries fsck.repair=yes on its kernel command line (it is in the image builder’s cmdline.txt), so a check that runs at boot answers yes to repairs. By default, though, the check only runs when the checker thinks it is needed. To force one, add fsck.mode=force to the single line in cmdline.txt on the boot partition, boot once, then remove it. The systemd-fsck manual documents both options. Because the boot partition is FAT, you can make that edit from any computer. Take the image first if the data matters: this is the same as running e2fsck -y with no copy to fall back on.
How to stop it happening again
In rough order of effort. The white paper’s summary is that Pi storage is very reliable when shut down correctly; the extra measures are for unreliable power and unattended use.
- Shut down before you unplug. From the desktop, use the Raspberry Pi menu and choose Shutdown. From a terminal, sudo poweroff. On a Pi 5, a double press of the power button shuts it down.
- Fix the power. Raspberry Pi recommends its official supply and warns about voltage lost in the cable. Our undervoltage guide shows how to check with vcgencmd get_throttled.
- Use a card from a well-known brand, and treat cards as consumables. For a Pi that matters, the white paper suggests replacing cards on a schedule instead of waiting for failure. Raspberry Pi says its own A2 cards were tested through more than 100,000 surprise power cycles under heavy I/O.
- Write less. The white paper’s example root entry in /etc/fstab uses defaults,noatime,commit=30. A 30-second commit interval batches writes; the cost is that up to that much recent data can be lost in a power cut. It also shows /tmp moved to RAM with the line tmpfs /tmp tmpfs defaults,noatime 0 0, with the caveat that swap can push tmpfs contents back onto the card.
- Turn on the Overlay File System for appliance-style projects. In a terminal: sudo raspi-config, then 4 Performance Options, P2 Overlay File System. On the desktop: Preferences, Control Centre, Performance tab, Configure next to Overlay File System, with switches for Use Overlay and Write-protect Boot Partition. Reboot to apply. The root partition becomes read-only and all changes go to RAM, so nothing you save survives a reboot. Disable it before updating or changing settings, and keep data that must persist on a separate drive or partition.
- Move off the SD card, or add a UPS. A USB SSD or network boot removes the card from the picture; the documentation lists USB boot on the Pi 3 B+ out of the box and on the Pi 4 and later through the boot order setting. Where power cuts are routine, a UPS gives the Pi time to shut down cleanly.
Where the official sources differ
- Menu name. The white paper (August 2026) says the overlay option is in the desktop “Raspberry Pi Configuration” application. The current documentation calls the tool Control Centre. Look for the Performance tab in whichever your OS release has.
- What overlay is for. The documentation files it under performance for write-heavy workloads. The white paper presents the same switch as protection against corruption. Both are true; the protection is the reason to use it here.
- Not the strongest option. The white paper notes that the raspi-config overlay sits on an ordinary ext4 partition marked read-only, and that purpose-built read-only images (SquashFS or EROFS) are more robust for products.
Common mistakes
| Mistake | Why it hurts | Do this instead |
|---|---|---|
| Running fsck on the only copy | A repair on a failing card can destroy what was still readable | Image with ddrescue first |
| Checking a mounted partition | e2fsck’s manual calls it unsafe, and results are not valid | Unmount, or check from another machine |
| Setting barrier=0 to “speed up” the card | The white paper warns against it: it removes the ordering the journal depends on | Raise commit= instead |
Frequently asked questions
Can I fix a corrupted Raspberry Pi SD card without another computer?
Sometimes. If the Pi still boots, add fsck.mode=force to cmdline.txt for one boot as described above. If it does not boot, you need another Linux system or a second Pi with a card reader, because the root partition cannot be repaired while it is the one in use.
Why does my Raspberry Pi SD card keep getting corrupted?
Three usual sources: power cut without a shutdown, a weak supply or cable, or a card near the end of its life. A dying card also throws read errors during the ddrescue copy. Check power, change the card, and if the Pi runs unattended, enable the overlay.
Will fsck get my files back?
It repairs the file system’s structure. It does not restore the contents of a file that was half written when power failed. That file may come back truncated or land in lost+found. Anything irreplaceable should come from a backup, which is the real fix.
Quick checklist
- Power down and stop booting the damaged card.
- Unmount, then image the whole card with ddrescue and a map file.
- Check with fsck.fat -n and e2fsck -f -n; repair with -a and -p; use -y last.
- Repair failed: mount the image read-only, copy files, write a fresh image to a new card.
- Afterward: clean shutdowns, a good supply, a reputable card, fewer writes.
- Unattended Pi: Overlay File System on, boot partition write-protected, data stored elsewhere.