Rescue files from a corrupted SD card using Ubuntu and ddrescue

Recently the micro SD card in my mobile got corrupted, here are the steps I took to rescue most of the files:

1. Remove the card from the mobile immediately and do not use it

2. Install ddrescue

$ sudo apt install gddrescue

3. Insert the card and find the mount point of the sd card

$ lsblk
NAME           MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda              8:0    0 465.8G  0 disk  
|-sda1           8:1    0    15G  0 part  
|-sda2           8:2    0   100M  0 part  
|-sda3           8:3    0 109.7G  0 part  
|-sda4           8:4    0     1K  0 part  
|-sda5           8:5    0 333.1G  0 part  /
|-sda6           8:6    0   7.9G  0 part  
  |-cryptswap1 252:0    0   7.9G  0 crypt [SWAP]
sr0             11:0    1  1024M  0 rom   
mmcblk0        179:0    0  59.5G  0 disk  
|-mmcblk0p1    179:1    0  59.5G  0 part

In my case, mmcblk0p1 is the one we want. So, the mount point for the card is /dev/mmcblk0p1

4. Run ddrescue

$ sudo ddrescue -dr3 /dev/mmcblk0p1 /home/<username>/sdcard.image ddrescue.log
GNU ddrescue 1.19
Press Ctrl-C to interrupt
Initial status (read from logfile)
rescued:    63847 MB,  errsize:   99328 B,  errors:      71

Current status
rescued:    63847 MB,  errsize:   83456 B,  current rate:        0 B/s
   ipos:     8209 MB,   errors:      59,    average rate:       72 B/s
   opos:     8209 MB, run time:    3.66 m,  successful read:      24 s ago
Finished

The first run will take some time depending on the size of your drive, subsequent runs will take considerably less time and will only focus on recovering corrupted files. Please note that ddrescue and dd_rescue are different programs and do different things, in this case we used ddrescue.

5. Check the drive for errors

$ sudo fsck.exfat sdcard.image 
exfatfsck 1.2.3
WARN: volume was not unmounted cleanly.
Checking file system on sdcard.image.
File system version           1.0
Sector size                 512 bytes
Cluster size                128 KB
Volume size                  59 GB
Used space                10200 MB
Available space              50 GB
Totally 99 directories and 1113 files.
File system checking finished. No errors found.

6. Finally, mount the rescued image to verify what files have been recovered

$ mkdir /media/recovered
$ sudo mount sdcard.image /media/recovered

Then you can browse this directory at your heart’s content and back up any rescued files.

If the card is using the exFAT file system and this is not recognised by Ubuntu, install the required packages:

$ sudo apt install exfat-fuse exfat-utils

For worst situations, this data recovery guide may come in handy.

Leave a Reply

Your email address will not be published.