The Raspberry Pi is a tremendously useful little computer that can perform a wide range of wonderful tasks. Like many electronic devices these days, it stores data on an SD card. Unfortunately, SD cards are not 100% percent reliable, and they certainly don't protect users against their own file management mistakes, so it doesn't take much to lose valuable data. But don't worry; there are several ways to recover a Raspberry Pi SD card, and we cover them in this guide.
Can You Recover Data from a Raspberry Pi SD Card?
RPi SD card data loss causes
😧 Accidental deletion
The default file system of Raspberry Pi OS and most other operating systems for the RPi uses the ext4 file system, which, when a file is deleted, only removes the information pointing to its location on the storage device. The actual file remains intact until overwritten with new data.
The most commonly used formatting method (called Quick format in Windows) merely recreates the file system structure without overwriting stored data, so it’s possible to recover data from a Raspberry Pi SD card that has been formatted. On the other hand, more secure formatting methods, such as Full format in Windows, make recovery impossible.
⚡ Power failure or improper shutdown
If the power failure occurs while the SD card is being written, there is a chance of data corruption. The good news is that it’s rare for power failures and improper shutdowns to corrupt a large number of files at the same time. What’s more, the corrupted files can usually be recovered (sometimes with defects) using data recovery software.
📛 SD card failure or corruption
SD cards are divided into sectors, which are grouped into blocks. These blocks are used by the SD card’s firmware for wear-leveling. When too many blocks fail or become corrupted, the SD card may become unusable. The data stored on it, however, should still be repairable and recoverable using the techniques described in this article.
⛔ RPi hardware failure
If the Raspberry Pi hardware has failed, then it may be possible to recover data from the SD card by connecting it to another Raspberry Pi or computer with a card reader (built-in or one that works like a USB flash drive). Just know that some hardware failures, especially those that cause large voltage spikes, can damage the delicate components inside of the connected SD card.
💣 Physical SD card damage
A physically damaged SD card that’s in such a bad shape that it can’t be recognized by any device may be impossible to recover data from—at least while relying only on the below-described methods to recover files from a Raspberry Pi SD card. Best SD card recovery services are sometimes able to extract data from physically damaged SD cards, but there’s no guarantee.
As the table above explains, it’s often possible to recover data from a Raspberry Pi SD card, and the following three factors have the biggest influence on data recovery outcomes:
- 🧹 Deletion/formatting method: Standard deletion and formatting methods affect only file system entries—not the actual data that’s being deleted. As such, they leave the possibility for data recovery using Raspberry Pi recovery techniques. However, there are deletion and formatting methods that can securely erase data from an SD card by overwriting it with zeroes or random data patterns. Such methods make Raspberry Pi recovery impossible.
- 🕑 Time since deletion: The length of time between the data loss and the recovery attempt can have a significant impact on the chances of successful data recovery. That’s because as time passes, the risk of lost data being overwritten increases. That’s why you should attempt to recover your data as soon as you can.
- 🔥 Type of damage: In general, Raspberry Pi SD cards can suffer from logical and physical damage. Logical damage refers to damage that affects the file system or data structure on the SD card, while physical damage refers to damage to the physical components of the card. Both types can result from a variety of causes, but only data lost to logical damage can be recovered using the methods below.
Understanding these factors is critical when attempting to recover lost data from your Raspberry Pi SD card. Now that’s out of the way, we can dive into some of the most effective methods for recovering files from a Raspberry Pi SD card.
Note: The same factors also impact your chances of successfully recovering deleted files from SD cards in general.
How to Recover Files from a Raspberry Pi SD Card
In this section, we will explore some of the most effective methods for recovering files from a Raspberry Pi SD card on all major operating systems, starting with Linux. If you’re not using Linux, then you can jump to the Windows/macOS section.
The choice of the solutions below was made based primarily on their ability to recover data from the ext4 file system, the default file system of Raspberry Pi OS, Raspbian, Ubuntu for Raspberry Pi, and other RPi-compatible operating systems.
If your RPi microSD card, microSDXC card, or SD card is formatted with a different file system, such as ext3, ext2, or even FAT32, then these solutions (except for the first one) will still work, but your results may vary.
Recover Files from a Raspberry Pi SD Card on Linux
Since Raspberry Pi users are used to the Linux operating system, let’s start with methods for recovering files from a Raspberry Pi SD card on Linux.
While you could recover your memory card directly on your Raspberry Pi, we recommend you remove the SD card from your Raspberry Pi and connect it to a Linux computer using an SD card reader. Why? Because you want to minimize the risk of further data loss as much as possible, and that means not performing any write operations on the SD card.
Option 1: extundelete
One of the most effective tools to recover deleted data from a Raspberry Pi SD card is extundelete. This open-source utility uses information stored in the partition journal of your SD card to recover deleted files from ext3- and ext4- formatted partitions.
With a bit of luck, extundelete should be able to restore Raspberry Pi SD card files with their original file names intact. Most major Linux distributions, including Ubuntu and Fedora, have extundelete in their repositories, so you should be able to install it just like any other software application.
Once you have the utility installed, you can use the following command to attempt to recover data from your Raspberry Pi SD card (replace /dev/sdxX with the actual device name of your SD card data partition):
extundelete /dev/sdxX --restore-all
If you’re not sure what the name of your SD card data partition is, then you can use the following command to list all partitions:
sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT
You can then find your recovered files in a subdirectory (named “RECOVERED_FILES”) of the current directory.
Option 2: TestDisk
Have you lost an entire partition or need to recover files from a corrupted SD card? If so, then TestDisk is the right choice. As our review of this data recovery and repair tool explains in detail, TestDisk can fix broken partition tables and copy files from deleted FAT, exFAT, NTFS, and ext2/ext3/ext4 partitions.
The application has an intimidating text-based user interface, but the actual recovery/repair process consists of simple steps. Here’s how you can use it to undelete files from an ext4 partition:
- Install TestDisk on your Linux distribution.
- Launch the application and create a new log file.
- Select your Raspberry Pi SD card.
- Select the correct partition table type.
- Go to Advanced.
- Select the ext4 partition with your lost files.
- Choose the List option and navigate to the folder where your files were located.
- Select all files you want to recover and then press “c” to copy them.
- Tell TestDisk where you want to copy the selected files.
- Exit TestDisk.
Just like extundelete, TestDisk recovers files by relying on file system information, which indicates where files are physically located. If this information isn’t available, then it’s time to use the following solution.
Tip: Read the official step-by-step guide to learn how to recover a lost Raspberry Pi partition using TestDisk.
Option 3: PhotoRec
PhotoRec is one of the best SD card recovery software applications (it also supports other storage devices) and not just because it’s free and open source. The tool ignores the file system and, instead, scans your storage device sector by sector, looking for recoverable files (it can recognize more than 480 file extensions). Because of how PhotoRec works, it can’t recover files with their original names, but it can save the day when extundelete and TestDisk fail.
Since PhotoRec is usually distributed with TestDisk, you may already have it installed on your Linux system if you followed the instructions for TestDisk. Here’s how to restore a Raspberry Pi SD card with it:
- Launch PhotoRec and select your Raspberry Pi SD card.
- Select the partition with your lost data.
- Tell PhotoRec which file system the partition uses.
- Choose to recover the whole partition.
- Select a destination to save the recovered files to.
- Give PhotoRec some time to recover your data.
- Exit the application.
PhotoRec always recovers all lost files, so you may end up with a whole lot of recovered files. We recommend you filter them by file type using your favorite file browser.
Tip: For more information about PhotoRec, read its full review. The review covers everything from data recovery performance to usability.
Recover Files from a Raspberry Pi SD Card on Windows/macOS
If you have access to a Windows PC or Mac, then you can easily recover deleted files from your Raspberry Pi SD card using Disk Drill, a versatile data recovery application with an intuitive graphical user interface (you can read our full review here).
Disk Drill supports not just ext4, ext3, and ext2, but also FAT16/FAT32/exFAT, NTFS, NTFS5, HFS, HFS+, and APFS. It can even scan raw microSD, microSDXC, SDXC cards, USB flash drives, hard drives, and other storage devices.
Included with Disk Drill is a useful byte-to-byte backup tool that you can use to create a complete backup of your Raspberry Pi SD card before recovery, but you shouldn’t need to do so because the application uses non-destructive data recovery algorithms that look both for file system information and file signatures.
Here’s how to recover files from a Raspberry Pi SD card using Disk Drill:
- Download Disk Drill from its official website and install it on your Windows PC or Mac.
- Launch the application and select your Raspberry Pi SD card.
- Click Search for lost data to initiate the recovery process.
- Analyze the found files and select the ones you want to recover. You can preview files to verify their recoverability and activate various filters to make the list of recoverable files more manageable.
- Click the Recover button and tell Disk Drill where you want it to recover files from your Raspberry Pi SD card.
Note: Disk Drill, just like all other similar applications, can’t recover data from a dead SD card that’s not recognized at all by Windows or macOS.
Losing data from a Raspberry Pi SD card is an unpleasant experience, but it’s not the end of the world because effective solutions do exist. By following the steps in this guide, you can put them to good use and recover your important files with ease. To avoid having to use them again in the future, remember to make regular backups of your Raspberry Pi SD card.
David Morelo is a professional content writer in the technology niche who joined the Handy Recovery team in 2019 and has since made an invaluable contribution to the quantity and quality of our materials. David's main principle is not to start working on a new article until he has studied the subject backwards and forwards.
Andrey Vasilyev is an Editorial Advisor for Handy Recovery. Andrey is a software engineer expert with extensive expertise in data recovery, computer forensics, and data litigation. Andrey brings over 12 years of experience in software development, database administration, and hardware repair to the team.