natjohan's blog

Posted lun. 28 janvier 2013

Easily recover your data from corrupted usb disk/memory card

Yesterday, I just wanted to move my pictures from my memory card to my computer. Unfortunatly, my memory card doesn't mount automatically under linux (Fedora), so i tried to mount it manually

natjohan# fdisk -l
[...]
Périphérique Amorce  Début        Fin      Blocs     Id  Système
/dev/sdc1            8192    15564799     7778304    b  W95 FAT32


natjohan# mount -t vfat /dev/sdc1 /mnt/
mount: mauvais type de système de fichiers, option erronée, superbloc
        erroné sur /dev/sdc1, page de code ou aide manquante, ou autre erreur
        Dans quelques cas certaines informations sont utiles dans le journal
        système — essayez « dmesg | tail » ou quelque chose du genre

Oooops, it doesn't works, what's in dmesg ?

natjohan# dmesg | tail
[ 2571.223469] usb 2-1: new low-speed USB device number 2 using xhci_hcd
[ 2571.269795] usb 2-1: New USB device found, idVendor=046d, idProduct=c01e
[ 2571.269805] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 2571.269810] usb 2-1: Product: USB-PS/2 Optical Mouse
[ 2571.269815] usb 2-1: Manufacturer: Logitech
[ 2571.271718] usb 2-1: ep 0x81 - rounding interval to 64 microframes, ep desc says 80 microframes
[ 2571.289396] input: Logitech USB-PS/2 Optical Mouse as /devices/pci0000:00/0000:00:1c.4/0000:03:00.0/usb2/2-1/2-1:1.0/input/input11
[ 2571.290150] hid-generic 0003:046D:C01E.0001: input,hidraw0: USB HID v1.10 Mouse [Logitech USB-PS/2 Optical Mouse] on usb-0000:03:00.0-1/input0
[ 2677.921938] FAT-fs (sdc1): invalid media value (0x00)
[ 2677.921944] FAT-fs (sdc1): Can't find a valid FAT filesystem

I was really annoyed (all my pictures from christmas :( , but with a quicksearch I found a very interesting tool called photorec :

PhotoRec is file data recovery software designed to recover lost files including video, documents and archives from hard disks, CD-ROMs, and lost pictures (thus the Photo Recovery name) from digital camera memory. PhotoRec ignores the file system and goes after the underlying data, so it will still work even if your media's file system has been severely damaged or reformatted.

Moreover, Photorec is :
- free and open source (GPLV v2+)
- developped by a french developper : Christian Grenier (thank you to him)
- multi-platform (Linux, Win and OSX)
- support most of filesystems : FAT, NTFS, Ext2/3/4, ExFAT, HFS+

What a promise ! So let's test it, under Fedora, there is a packet called testdisk (testdisk is a suite which include photorec, note testdisk looks great too for recovering lost partition or boot sectors, hope I never need to use it)

natjohan# yum install testdisk

Then, you just have to call photorec and follow the instructions

natjohan# photorec

Choose your storage device, your partition, folder for recovered files, etc. And take some time to drink a cup of coffee :)

photorec in progress

That's it ! Then you can format your device (in FAT 32 for example) with :

natjohan# mkfs.vfat -cvF 32 /dev/sdc1

WARNING : Be really careful before formating a disk, you will not be able to recover your data, check that you are applying the command to the right device before you hit ENTER

Note: I supposed you have a partition created on the disk, before you format it.
Category: Linux
Tags: tool recover photorec repair testdisk

Comments