Recovering your precious photos from a SD card can be challenging enough after accidental file deletion or formatting. Recovering data from an unstable SD Card may prove to even more difficult.
Recovering data from an unstable SD Card
Many file, photo and data recovery tools available focus on file recovery. Their efforts focus on discovery of file system meta data and/or ‘magic byte sequences’. If enough file system meta data can be discovered you’ll be able to recover your files, complete with names and directory structures. But even if this meta data is largely lost, as long as the actual data exists it can often be recovered by scanning the memory card for magic bytes. The latter is known as RAW recovery or file carving.
Read errors can result in lock ups
However most tools do not fare too well if the card doesn’t play nice and reports read and disk access errors. Some tools may be able to skip bad sectors but if the card locks up or stops responding, sometimes even disconnects, then they’ll probably just give up. If they’re even able to do so, instead of locking up themselves.
File or data recovery software reads raw sectors from a drive. However, once a read command is issued they’re at the mercy of the card. If all works as designed the card returns the data. If the SD Card controller can’t read the data it will return an error instead. The file recovery tool then needs to decide what to do next. Try reading the sector again? Or accept the error and try reading the next sector?
But even before it comes to this, this exchange of data and return codes passes through several layers. The operating system, the USB bus, the card reader etc.. It is not uncommon that something in this chain locks up. The USB bus may even decide to drop the SD Card or reader entirely, often causing the requesting file recovery tool to freeze. Many of us have experienced at some point the Windows file explorer to freeze when trying to read a file with a bad sector.
Handling SD Cards and USB disconnects
Best solution for these unstable SD Cards is imaging them sector-by-sector rather than try reading them file-by-file. This limits the amount of disk access as each sector only has to be tried once. A file recovery tool typically needs to access multiple areas and goes back and forth between file system meta data and actual file data. This may increase wear, increase ‘opportunities’ for the hardware to lock up and slows the process down.
Ideally such unstable SD Cards are sent to a data recovery lab. Such labs have the hardware to stabilize USB connected storage devices. These tools also allow for a more direct communication with the SD Card or USB Flash drive. If needed they can even power cycle a drive. These devices and the accompanying software often cost several thousands of Dollars plus additional annual license fees.
If it comes to that, a data recovery engineer can even decide to bypass the USB flash drive or SD Card controller all together and read the memory chips directly. For that even more expensive hardware and software is required. As without the controller as middle man the raw dump will contain meaningless, and scrambled data, the conversion to a logical image is a time consuming process.
Linux and ddrescue
A possible alternative for end users may be a Linux rescue environment and using ddrescue. Linux often is more stable when dealing with unstable hardware compared to Windows. The tool ddrescue is designed to expect bad sectors.
Possible solution for Windows
To some degree and with some effort, imaging can often be done from Windows too. The trick is using a tool that expects read errors and lock ups. When writing the disk imager module of JpegDigger I used my own experience with unstable USB flash drives and memory cards. These are:
- Re-reads of bad sectors hardly ever pay off. If reading a certain sector results in the drive dropping the connection, re-reads will simply cause more dropped connections.
- One read error can result in the rest being read bad too, even when next sectors are in fact good
- The USB drives or cards frequently drop the connection which is a royal pain in the .. you know ..
- Once connection dropped, picking up the process at the point where it was left isn’t simple enough in most tools
- Be prepared to baby sit the process: Once a connection gets dropped, you will need to manually re-insert the card or USB flash drive
The built-in disk imaging module in the soon to be released version of JpegDigger tries to detect if the memory card or USB flash drive dropped off-line. It allows you to re-insert the drive and then continue the imaging process. You can also configure it to stop imaging after a certain amount of errors, allowing you to remove and re-insert the drive and then continue.
Ideally you’d use an external reader with a power switch, but I haven’t been able to find one yet.
One major advantage that JpegDigger offers is the entropy map. A successful read does not mean by definition valid data was returned. The card might as well be returning sectors filled with zeros. Using the entropy map such a situation would be easy spotted, the map would be black and stay black. Black means no data or a repeating byte pattern (0xFF, FF, FF etc.). A bright green entropy map is what you would expect when imaging a SD Card containing photo and video data.
EDIT 06/02/2020: I have ordered a device that allows for powering up and down a device connected through USB and will be looking to integrate this with the JpegDigger drive imager.
Dealing with unstable SD Cards in Windows
So, although the JpegDigger isn’t ideal and certainly not the best, it does often allow you to image an unstable SD Card in Windows.
For completeness sake, I must warn you that any DIY attempts to recover data from any ill behaving drive may make the situation worse. If your data is of value the best advise is to take it to a data recovery lab.