TestDisk

Homepage | Download (1.3 MB)
Version: 6.10
License: GPL2
Rating:


Those of you who read this site regularly, or pay attention to the dates at the end of each post, may have noticed that it’s been a while since I last posted anything here. This is, of course, due to many factors (I’ve been alternately very busy and very lazy, these past couple months); but one major one is the problems I’ve had with my computer. A while ago I upgraded my distribution to the latest version, only to receive a GRUB Error 21 upon rebooting. After hours of reading documentation, searching online, asking for help on IRC (Thanks, cathbard, MichMash, and EchoLynx!), and a couple reinstallations, I finally realized that all my problems were caused by a simple mistake in my GRUB menu.lst file, which was easily fixed.

But not before I had, somehow, corrupted my NTFS partition.

Now I suppose this could have been an opportunity to leave Microsoft once and for all, and overwrite the bad partition with an XFS one or something; but I had a lot of rather important files on board, and didn’t want to lose them. If I hadn’t lost them for good, already. I figured there had to be a way to recover a broken partition, so I searched online on a tech support forum, and found a program called TestDisk recommended. I looked up the program’s homepage, and found that not only is there a version of it for Linux, but it’s also open source!

TestDisk is a program for the express purpose of recovering deleted, unbootable, or damaged hard drive partitions. It’s a text-based program, so as to keep it small and cross-platform, but it’s got a very easy-to-use interface which’ll set GUI junkies at ease.

Linux binary downloads are available as an RPM, as well as in tarball form for those of us who don’t use a Red Hat-derivative distro. Upon downloading the tar.bz2 of TestDisk, I was pleasantly suprised to find that there was nothing further I had to do, besides executing it. Because it’s a binary, you don’t have to run a Makefile or anything, and because it’s compiled statically, it doesn’t depend on any external libraries. Just navigate to testdisk-6.10/linux from where you extracted TestDisk, and run sudo ./testdisk_static in a shell. (By the way, you may have noticed a binary entitled photorec_static in the same directory that the TestDisk binary was in. This is TestDisk’s companion program, PhotoRec, that ships with it. PhotoRec is for recovering lost or deleted files from your hard drive, and is also a very useful application — but we haven’t space enough to talk about it much, here, so you’ll have to go to its homepage to learn more.)

Depending on whether you use a terminal window for text-based stuff (as opposed to using one of Linux’s built-in virtual consoles) and what its default size is, you may or may not receive the message: TestDisk need 25 lines to work. Please enlarge the terminal. If you do, follow the instructions; and you’ll come to the introduction screen. Here you’ll see a brief explanation of what TestDisk is and does, and be asked whether you want to create a log file. Whether you do or not is up to you (though doing so is recommended) — to tell TestDisk of your decision, use the up and down arrows to choose your option of choice, and press Enter.

Now you’ll come to a list of all the hard drives on your computer. Choose the one that contains your deleted/unbootable/damaged partition, again by using the arrow keys, and press Enter again while the word Proceed is highlighted (if you feel like quitting at this point, you can use the rightwardly-pointing arrow key to select Quit). Then you’ll have to inform TestDisk as to what type of partition table your drive has. Chances are you have a PC, in which case you can go with Intel; though if it’s not, select the appropriate menu entry. TestDisk will try to detect what type of table you’ve got, so unless you know that what’s automatically selected is wrong, you can usually just go with the default.

And then you’ll happen upon the main menu itself. There’s a lot of different choices that can be made, but commonly you’ll just be able to press Analyze, and continue. You’ll be shown a list of the partitions on the drive in question. Look at these carefully. If there’s anything odd about the list (error messages, the same partition being shown twice, etc.), you’ll be able to tell which partition is causing problems, if you didn’t know already. Then, select Quick Search, say whether or not it ought to look for partitions created under Windows Vista, and TestDisk’s real capabilities will spring into action. The listed partitions will be repaired and then relisted, with healthy partitions highlighted in green. If everything is as it should be, you’ll see the message Structure: OK in the lower left of the screen. Next to each partition is a letter designating what type of partition it is — primary bootable, primary, logical, extended, or deleted. If you have reason to believe that one of the partitions ought to be of a different type, you can use the arrow keys to change it: up and down to choose between partitions, and left and right to swap types. Depending on the type of partition (some sorts, such as XFS, are not yet fully supported), you can also press ‘P’ to view a list of the files and folders contained within it; to make sure the partition is operational, or even to copy files to somewhere else (done by pressing ‘C’).

Then you can press Enter to continue, where you’ll be shown your partition list again. If there’s still something missing, you can do a Deeper Search. This can take a long time, but is much more thorough than the quick way of doing it. But, if all your partitions are available, you can select Write to write a new partition table to your drive and fix it for good!

If you happen to be so lucky, you can exit TestDisk, restart your computer, and access your partition that once was lost, but now is found (which may very well warrant a rousing rendition of Amazing Grace). But maybe your problems weren’t solved so easily. In that case, you can rely on TestDisk’s excellent documentation, available on their website. Every function of the program is explained in detail, and there’s lots of example case studies, which may also help. But as good as the documentation is, don’t expect it to be perfect. I wasn’t able to find out, at first, what to do about the message Warning: Incorrect number of heads / cylinder. But — the docs are also available in French and German, and by use of Google Translate, I was able to find the answer and ultimately solve my problem.

So, if you’re in a similar predicament, I highly recommend TestDisk. It fixed my partition, and brought the episode to a happy conclusion —

Until my graphics driver tried to kill me.


. . . But that’s another story!


This entry was posted on Friday, September 12th, 2008 at 6:58 pm and is filed under Utilities. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

 

Leave a Reply