If your Raspberry Pi won’t boot or throws errors, the SD card is often the culprit, and recovery is possible in many cases by using a card reader and recovery software on another computer. This guide explains the common causes of SD card corruption, the steps to recover your data or repair the card, and how to prevent it from happening again.
Why Raspberry Pi SD Cards Fail
SD cards are the most common storage medium for Raspberry Pi, but they are also the most failure-prone component. Unlike a hard drive or SSD, SD cards use flash memory that wears out with repeated write cycles. The Raspberry Pi’s operating system constantly writes log files, temporary data, and swap files, which accelerates this wear. Power loss is another major cause: if the Pi loses power during a write operation, the file system can become corrupted. Other causes include:
- Using a cheap or counterfeit SD card with poor quality flash chips.
- Removing the card while the Pi is still running (though the Pi doesn’t support hot-swapping).
- Overheating, which can damage the card’s controller.
- Static electricity or physical damage to the card.
Can You Recover Data from a Corrupt SD Card?
Yes, but the success rate depends on the type of corruption. If the card’s file system is damaged (e.g., the partition table is lost or the files are marked as deleted), data recovery software can often restore files. However, if the card’s flash memory has physically worn out, recovery is much harder and may require professional services that are expensive. For most hobbyists, the goal is to get the Pi booting again, not necessarily to recover every file. If you have a backup (which you should), the easiest fix is to re-flash the card with a fresh operating system image.
Step-by-Step: How to Recover a Raspberry Pi SD Card
Before you start, you’ll need a card reader that can connect the SD card to a Windows, macOS, or Linux computer. Do not use the Pi itself for recovery, as the Pi may not be able to read the card reliably.
- Stop using the card immediately. If the Pi is still running, shut it down gracefully. If it’s not booting, remove the card.
- Insert the SD card into your computer’s card reader. If the computer asks to format the card, decline – formatting will erase everything.
- Make a raw image backup of the card. Use a tool like Win32DiskImager (Windows) or
dd(Linux/macOS) to create an image file. This preserves the current state, so you can try recovery without risking further damage. - Try to repair the file system. On Windows, run
chkdskon the drive letter (e.g.,chkdsk E: /f). On Linux, usefsck. This may fix simple corruption. - If that fails, use data recovery software. Tools like TestDisk (free, open-source) can rebuild the partition table, while PhotoRec (from the same suite) can recover individual files by scanning the raw data. Other commercial tools exist, but the free ones are often sufficient.
- If the card is still unreadable, try re-flashing it. Use the Raspberry Pi Imager or
ddto write a fresh operating system image to the card. This will erase all data but may make the card usable again.
Using TestDisk and PhotoRec for Recovery
TestDisk is a powerful tool that can recover lost partitions and make non-booting disks bootable again. It works on Windows, macOS, and Linux. To use it:
- Download and run TestDisk on your computer.
- Select the SD card from the list of drives.
- Choose the partition table type (usually Intel for a Raspberry Pi).
- Select “Analyse� and then “Quick Search�. TestDisk will scan for lost partitions.
- If it finds the original partition, you can write the partition table back to the card.
PhotoRec is a companion tool that recovers files by their signatures (e.g., JPEG, PNG, text files) rather than the file system. It’s useful when the partition is completely gone. It can recover files to another drive, but the filenames will be lost. This is a last resort for data recovery, as it’s time-consuming and the results are often messy.
How to Prevent SD Card Corruption
Prevention is far easier than recovery. Here are the most effective steps:
- Always shut down the Pi properly. Use the shutdown command (
sudo shutdown now) and wait for the LED to stop blinking before unplugging. - Use a high-quality SD card. Look for cards from reputable brands with an “A1� or “A2� rating, which indicates good random read/write performance. Avoid counterfeit cards – buy from trusted sellers.
- Reduce writes to the card. Move frequently-written files (like logs) to a RAM disk or an external USB drive. You can also disable swap or move it to a USB drive.
- Enable the “read-only� mode. If you don’t need to write to the SD card (e.g., for a dedicated media player), you can mount the file system as read-only. This dramatically reduces wear.
- Use a UPS or a good power supply. A sudden power cut is a common cause of corruption. A small uninterruptible power supply (UPS) for the Pi can prevent this.
- Keep backups. Regularly clone your SD card to an image file using
ddor Win32DiskImager. If the card fails, you can restore the image to a new card in minutes.
When to Give Up and Replace the Card
If the card is physically damaged (e.g., cracked, bent, or the contacts are corroded), no software can fix it. Also, if the card fails to appear in your computer’s card reader even after trying multiple readers, the controller chip may be dead. In those cases, the only option is to buy a new card. SD cards are relatively inexpensive, so if the card is more than a few years old, replacement is often more cost-effective than spending hours on recovery.
Frequently Asked Questions
Can I recover files from a Raspberry Pi SD card using the Pi itself?
Technically yes, if the Pi can boot from a different SD card or a USB drive, you can insert the corrupted card into a USB card reader and mount it on the Pi. Then you can use the same recovery tools (fsck, TestDisk) on the Pi. However, it’s usually easier to do it on a desktop computer because you have a full keyboard and monitor.
Will re-flashing the SD card fix corruption?
Re-flashing writes a new operating system image to the card, which overwrites the entire card with a fresh file system. This will fix any logical corruption, and the card should boot normally again. However, if the card has physical damage or worn-out flash cells, it may fail again soon. It’s worth trying, but monitor the card for errors.
How do I know if my SD card is fake?
Fake cards often have a lower actual capacity than advertised. You can test this by writing a large file to the card and reading it back. Tools like H2testw (Windows) or F3 (Linux) can verify the real capacity and speed. If the card is fake, it will fail the test, and you should stop using it immediately.
Can I use a microSD card in a full-size SD adapter for recovery?
Yes, most microSD cards come with an SD adapter. The adapter is just a physical shell; it doesn’t affect the data. Just make sure the adapter is not damaged and the card is inserted correctly.
Is it safe to use dd to clone the SD card?
Yes, but you must be careful to specify the correct input and output devices. If you mix them up, you could overwrite your computer’s hard drive. Double-check the device names (e.g., /dev/sdb for the SD card) before running the command. On Windows, use Win32DiskImager instead, which has a graphical interface and is safer.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Steam Tags & Screenshots: Reaching the Right Players
- Leather vs Faux Leather: Which Is Better for a Matching Set?133.33 USD/year
- Pascal Programming on Raspberry Pi: Setup & Code
- Voice Memos to Searchable Family Cookbook Safely
- Glass vs Plastic Food Storage: Which Is Better?2.00 USD/year
- Ridgid Nuke vs Brushless: When Is Extra Power Worth It?