How to Recover Specific Files from a Bad SD Card on Raspberry Pi 4

Abstract: Recover specific files from a failing Raspberry Pi 4 SD card by creating a safe sector-by-sector image with ddrescue to prevent further data loss.

Created: 2026-09-23 by
Recovering specific files from a failing SD card on a Raspberry Pi 4 requires immediate, careful imaging of the drive before attempting any repairs. By creating a sector-by-sector copy using Linux tools like dd or ddrescue, you can work on a safe replica while the original card is preserved for professional recovery if necessary. This approach prevents further degradation and allows you to extract data without risking total loss.

Assessing the Damage and Initial Safety Steps

The first step in recovering data is to stop writing to the SD card immediately. Every time the Raspberry Pi attempts to read or write to a failing flash memory cell, it increases the risk of permanent failure. If the card is still recognized by your PC, do not attempt to format it or run standard disk repair utilities like chkdsk on Windows, as these can overwrite critical file system structures. Instead, mount the card in read-only mode if possible, but the most reliable method is to create an image file. This ensures that even if the card dies completely during the process, you have a bit-for-bit copy of the current state. You should also check the physical connections; sometimes a loose card reader connection mimics SD card corruption. Ensure the card is seated correctly and try a different USB port or card reader to rule out hardware interface issues.

Creating a Disk Image with ddrescue

While the basic dd command can create an image, it often fails when encountering bad sectors because it stops at the first error. A more robust tool is ddrescue, which is designed specifically for data recovery. It skips unreadable areas and returns to them later, maximizing the amount of recoverable data. First, install the tool on your Linux machine using sudo apt install gddrescue. Identify the device name of your SD card using lsblk; it will typically appear as something like /dev/sdb. Be extremely careful to select the correct device, as selecting your main hard drive could result in catastrophic data loss. Once identified, run the following command:
sudo ddrescue -f /dev/sdb sdcard_image.img sdcard_logfile.log
This command creates sdcard_image.img and logs progress in sdcard_logfile.log. The -f flag forces overwriting of the output file if it exists. After the initial pass, you can run the command again to retry bad sectors:
sudo ddrescue -d -r3 /dev/sdb sdcard_image.img sdcard_logfile.log
The -d flag uses direct access for faster reading, and -r3 retries up to three times. For more aggressive recovery, consider looking into guides on handling physically damaged sectors, such as those discussed in Can Corrupt or Physically Damaged Sectors on a Hard Drive be Written Over?. However, note that hard drive techniques may not apply directly to NAND flash memory used in SD cards.

Making the Image Readable

Once you have a complete image file, you need to make its contents accessible. The image contains raw partitions, so you must map them to loop devices. Use the fdisk command to inspect the partition table within the image:
fdisk -l sdcard_image.img
Note the starting sector of the partition you wish to recover (usually the first one). Then, calculate the offset by multiplying the start sector by 512 (the default sector size). Mount the image using the offset option:
sudo mkdir /mnt/recovery
sudo mount -o ro,loop,offset=OFFSET_VALUE sdcard_image.img /mnt/recovery
Replace OFFSET_VALUE with your calculated number. The ro flag ensures the image is mounted read-only, preserving its integrity. If the file system is corrupted and does not mount automatically, you may need to use tools like testdisk to repair the partition table within the image. For messy file systems, refer to Effortlessly Recover Your Messy SD Card for strategies on cleaning up directory structures after extraction.

Extracting Specific Files

With the image mounted, navigate to /mnt/recovery and locate your files. Copy them to your host computer’s storage. If the file system is severely damaged, you can use photorec or foremost to scan the image for file signatures, bypassing the file system entirely. These tools search for headers and footers of known file types like JPEGs, PDFs, or text files. While this method recovers content, it often loses original filenames and directory structures, so prioritize mounting the image first if possible.

Preventing Future Data Loss

SD cards are prone to failure due to limited write cycles and sudden power loss, which is common in Raspberry Pi projects. To mitigate this, always shut down the Pi properly using sudo shutdown -h now before removing power. Consider using a UPS (Uninterruptible Power Supply) module for critical projects. Additionally, implement regular backups using tools like rsync or cloud synchronization. Monitoring the health of your SD card through SMART-like tools (if supported by your reader) or logging write operations can provide early warnings of impending failure. If you frequently encounter unrecognized cards, check our guide on Fix Unrecognized Samsung 8GB SD Card - Complete Guide for troubleshooting connectivity issues that might mimic total failure.

Frequently Asked Questions

Can I use Windows tools to recover files from a Raspberry Pi SD card?

Windows native tools are generally ineffective for ext4 file systems used by Raspberry Pi OS. You should use Linux-based tools like ddrescue or specialized software like PhotoRec that runs on Windows but accesses the raw image created on Linux. Trying to force Windows to read ext4 can lead to data corruption.

What if ddrescue cannot read any part of the SD card?

If the card is not detected at all, the issue may be hardware-related, such as a broken controller chip. In this case, software solutions will not work. You may need to consult a professional data recovery service that specializes in NAND flash memory, although this can be expensive. Check if the card works in other devices to isolate the problem.

Is it safe to run fsck on the original SD card?

No, running filesystem check utilities like fsck on the original failing card is dangerous. These tools attempt to fix errors by modifying the disk structure, which can destroy remaining data. Always perform repairs on a copied image file, never on the source medium.

How long does the ddrescue process take?

The duration depends on the size of the card and the number of bad sectors. A small card with few errors may take minutes, while a large card with many bad sectors can take hours. The log file allows you to resume interrupted processes, so do not cancel the operation unless you are certain the hardware has failed completely.

Will recovering files delete anything from the SD card?

Reading the card does not erase data. However, if you unmount the card improperly or write to it during the process, you risk overwriting deleted files. Always ensure the card is unmounted from your operating system before creating the image, and keep it disconnected until the image is fully secured.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More