Executing the TestDisk Program

Working with Damaged Hard Disks

You can also use TestDisk to help analyze the sectors copied from a hard drive with physical problems onto a good drive. If there are any bad sectors on your hard disk, you should first copy its data to another hard disk before attempting to recover its data. The new disk must be at least exactly the same size (check the number of LBA sectors) or larger; when larger, it's usually not a problem because the number of heads per cylinder and sectors per head will be the same if both disks use LBA mode.

Under Linux, the Primary Master IDE disk device is /dev/hda
Primary Slave IDE device is /dev/hdb
Secondary Master IDE device is /dev/hdc and so on.
SATA HDD device filenames usually begin at /dev/hde or /dev/sda
SCSI device filenames always begin at /dev/sda

To list the partitions of a disk, log in as root and run fdisk -l device. Once you have verified the device names for your damaged disk and the new one, in a command shell (CLI) or terminal, not from within any OS on the damaged disk (see note 1 below), run:

dd if=/dev/old_disk of=/dev/new_disk conv=noerror,sync
or to create an image file:
dd if=/dev/old_disk of=image_file conv=noerror
to copy the data.

To speed up the copy process, you can append bs=8k, it will read/write the disk by 16 sectors at a time.

If you believe there are many damaged sectors on the drive, you should try using either Kurt Garloff's 'dd_rescue' (dd_rescue) or Antonio Diaz's 'ddrescue' (ddrescue) instead of dd. This Freshmeat page has some brief exchanges between the two authors and others. Though we haven't tried it out ourselves, it appears that the Diaz program by itself may save you some time over learning how to use both Garloff's program and the 'rhelp' script he links to. We're open to suggestions as to why one might be better than the other.
_ _ _ _ _ _ _ _ _ _ _
1If needed, download the Knoppix "Live CD", a bootable CD with a fully functional Linux OS that runs only in memory!

Warning: If you use TestDisk to recover lost partitions on a target hard drive by connecting the drive to a computer other than the one it was originally partitioned and formatted on, you risk the chance of having incorrect data about the drive passed along to TestDisk from the BIOS of this other computer. BIOS chips have at least two different ways of translating disk geometry, and using the wrong data may make it impossible for TestDisk to correctly recover a drive's lost partitions; or worse, you may write the wrong data to the drive's MBR, boot up the disk and then incorrectly write data to the disk leading to further corruption and loss of data. ( This may not apply to all file systems.) TestDisk tries to detect this problem.

Working with Hard Disk Image Files

TestDisk can also work with hard disk images. The disk image must be available under its image_filename in the working directory, or you can add its Path and filename to a TestDisk command line. For example:

testdisk_win.exe C:\BOCHS\DOS\c.img

will include the Path\image_file, c.img, in the list of drives on TestDisk's initial screen. Then open the image file just like any physical drive.

Image files are limited in size by the OS and filesystem:
2 GiB (FAT16), 4 GiB (FAT32), 16 GiB (EXT2/3 with 1kb block), 256 GiB (EXT2/3 with 2kb block), 2048 GiB (EXT2/EXT3 with 4kb block)

TestDisk Startup

When TestDisk is executed, you may see the phrase "Please wait..." on your screen until it has gathered enough data from the BIOS or OS to list the disk drives on the system.

screen01.gif

If the reported size doesn't match the harddisk size, i.e., a 120 GB harddisk is recognized as only a 32 GB harddisk, check your BIOS harddisk settings and the jumpers on the disk. On most large hard disks, there are jumpers to limit the size to only 32 or 8 GB.


TestDisk Menu Items

Analyse

Delete

MBR Code

Disk Geometry

Options

Advanced


If you don't understand how to use TestDisk,

Note: TestDisk appends new information to testdisk.log; it does not overwrite an existing file.

Return to TestDisk main page