[Desire General] genseng:
So I have an old SD card that for some reason or another I keep using because I haven't gotten around to replacing the replacement I did get that doesn't work (sad tale of a Sandisk Class10 32GB card that I've seen from a handful of other people).

Anyway, I've had to do this a number of times now and it's worked pretty well. First of all, if your disk is crashing this way, there's probably something wrong with it, and there's a chance that your data will not be recoverable, or it will be recoverable and it is corrupted and it might take time to figure out how it's corrupted.

Basically, I get a warning from Android that there's something wrong with the SD disk and apps rely on the SD card will slowly stop functioning until it crashes. After this it pretty much just locks up and is unusable. This is the procedure I use when there's no partition information on the drive and the disk just appears to be empty. I run Linux on my systems so I just use run testdisk natively but there appear to be some Live CD's that have testdisk installed for everyone.

Mount your SD Card following your usual methods with a USB reader of built-in laptop card reader. Hopefully you have one.

Figure out which /dev represents your SD care. Normally I just open gparted (probably some variation of just finding it in your system tools or gksudo gparted or gparted from the command line). If that's not an option some combination of the following may give you some info to help you figure out which disk is causing the problem.

ls -l /dev/disk/by-id
ls -l /dev/mm*
ls -l /dev/sd*

The nice thing about gparted is that it will show you which partitions are formatted, and if your results are like mine you will see your ext4/ext3 SD-ext partition has survived with your apps intact, but no dice for the storage portion of your card. You could mount your SD-ext partition and copy the data if you wanted, or use dd to copy it but you have other backups, right? Oh, your Titanium Backup files are on your SD data drive. You don't rsync to a server..? OK, we'll get to that...If you want a chance of recovering your files remember your /dev path (why you opened gparted) and close gparted before you do something stupid.

Start testdisk in your favourite terminal emulator with... wait for it...

testdisk

And this is the part where I tell you exactly what to do but can't actually remember and always just bumble around until I find what I'm looking for - so I Googled it for you.

But to summarize after starting the program, you'll need to select the correct disk (/dev) and tell testdisk what type of partition your disk uses (pick intel!)

You can try using analyze to write a new partition table. This doesn't seem to help the problem I have with my disk but it hasn't hurt my recovery efforts either. Make the copy first and then try to recover partitions after, just to be safe.

To get your files back you want the advanced menu and the undelete option. Say what? Undelete?

Basically this feature is meant to let you copy deleted files off a camera card, USB hard drive etc. so once it's done it's voodoo to read the files on your broken partition it will show you all the files on your partition, not just the deleted ones (in red). Several filesystems will just leave junk on the drive until it gets overwritten later so many of these deleted files may be partially overwritten already.

Just highlight everything, if you can manage to not highlight the red things you're ahead of me.

Now press "c" to copy the selected files just like the program tells you. Follow the prompts to choose a destination folder. You probably want to copy it all into an empty file so it's easy to copy back.

If you copied all the deleted files on your disk you probably deleted a bunch of junk you no longer need and will needlessly fill up your SD card with files when you copy everything back. You might want to clean that up now.

Put the SD card in your phone and start fresh with a full format of the SD card in 4ext recovery.

With you newly minted partitions ready to receive data, you can use the toggle USB storage button to put your data back on the phone. I believe this is the recommended way to write data on the card. This will put all your backups/ROMs on the SD card so you can reflash everything and start recovering your data from your backups. You do have backups, right?

Hopefully this helps someone!