Menu Analyse

TestDisk queries the BIOS or the OS in order to find the hard disks and their characteristics (LBA size and CHS geometry). TestDisk does a quick check of your disk's structure and compares it with your partition table for entry errors. If the partition table has entry errors, TestDisk can repair them. If you have missing partitions or a completely empty partition table, TestDisk can search for partitions and create a new table or even a new MBR if necessary.

However, it's up to the user to look over the list of possible partitions found by TestDisk and to select the one(s) which were being used just before the drive failed to boot or the partition(s) were lost. In some cases, especially after initiating a detailed search for lost partitions, TestDisk may show partition data which is from the remnants of a partition that had been deleted and overwritten long ago.

Partition checks

The Intel partition structure is composed of the MBR table and extended partitions. The MBR is limited to four entries. One of the entries can be an extended partition allowing several logical partitions. Each logical partition is contained by an extended partition/container. The MBR and each extended partition must end with the two bytes 0x55 and 0xAA, in that order; which make up the hex word 0xAA55 (since x86 CPU systems are little-endian).
A partition entry is composed of:
- the start of the partition in CHS
- the end of the partition in CHS
- the filesystem type
- the logical start
- the size in sectors
- the boot flag
Only one primary partition can have the boot flag set.
CHS information storage is limited to a maximum of 1024 cylinders
(0-1023), that's why we have the famous 8 GB limitation (1024*255*63 = 16450560 sectors = 8422686720 bytes).

Modern operating systems and BIOS chips use LBA mode to access the data, but FAT12/16/32 boot sectors still make reference to CHS geometry. TestDisk checks that each value is in the authorized range: i.e., no sector value less than 1 nor higher than the number of sectors per head. The partition entries are read using the logical start and size in sectors, then TestDisk checks to see if the logical values match the CHS values. TestDisk also checks that no partition data shows a partition as ending after the end of the disk, and that none of them are overlapping each other.

Sun label can have up to 8 partition entries. Entry number 2 is reserved for the whole disk.

Filesystem checks

Following the filesystem type, TestDisk runs some basic checks on the boot sector/superblock of each filesystem. As ext2/ext3/reiserfs/jfs share the same filesystem type: 0x83, TestDisk has to check for each filesystem. The checks are the same as those used when TestDisk is searching for partitions:
- presence of magic value or signature (i.e., 0xAA55 at offset 0x1FE of either FAT or NTFS boot sectors).
- coherent values (i.e., free_blocks_count lower than blocks_count for ext2)
This phase is very quick as the checks are minimal.

Partition recovery

In a second step, TestDisk searches for 'lost partitions' without making use of any results from the previous step. This is the heart of TestDisk's powerful capabilities!
TestDisk assumes the existence of partitions and scans all relevant locations for them. With a PC/Intel partition table, a primary partition usually starts at the beginning of a cylinder (head=0, sector=1), while a logical partition starts a little further along (head=1, sector=1). For each possible partition starting location, TestDisk can search for the presence of a file system header (FAT or NTFS boot sector, ext2/ext3 superblock, BSD disklabel...), which confirms the presence of a known partition type. Thus, the size of a partition is determined directly from its structure on the disk. Each partition that TestDisk discovers is added to a list of found partitions.

To detect a FAT32 partition, TestDisk searches for a 0xAA55 end mark and the signature FAT32 - it also runs the corresponding FAT file system checks:
- jump signature must be of the form 0xeb 0xXX 0x90 or0xe9 0xXX 0xXX
where 0xXX could be any byte, and...

0xeb: A Short Jump, displacement relative to next instruction (only 8 bit).
0x90: NOP (do nothing).
0xe9: A Near Jump, displacement relative to next instruction (32 or 16 bit).

- sector size is 512
- cluster size must be 1, 2, 4, 8, 16, 32, 64 or 128
- there must be 2 FAT copies
- the media must be 0xF8 (no other value is seen - it's an obsolete feature)
- If you follow MS guidelines, the signature FAT32 is meaningless but your file system should have it.

Following the number of clusters, TestDisk determine the kind of FAT (number of clusters is more or equal to 65525 for FAT32).

Some specific checks for FAT32 are done:
- the root cluster number must be between 2 and the maximum cluster number,
- some obsolete values (number of directory entries, 16-bit partition size) must be set to 0,
- FAT32 version (unused) must be 0.0

To detect an NTFS partition, TestDisk searches for an 0xAA55 end mark and the signature NTFS - it also checks that some FAT specific values are all set to zero (0): the number of reserved sectors, number of FATs, number of directory entries, 16-bit size of file system, 32-bit size of file system, sectors per FAT.
The number of Sectors per Cluster must be greater than zero.

For FAT and NTFS file system, the size of the partition will be read in the boot sector itself.

You can change the status of the selected partition using the left/right arrow key. The available statuses are Primary, * bootable, Logical, Deleted.

As you make edits, watch the status of the partition table's structure. It will be either Ok or Bad.

Structure: Ok should appear if everything is ok, i.e., no primary partition between two extended partitions, one or no bootable partitions, no partitions using the same disk space.

When you are satisfied with the edited partition table, press Enter. If you've made any edits, TestDisk gives you a choice of writing that data to the drive's partition table, or of running a more detailed analysis.

Quit

Quits (exits) from the TestDisk program without making any changes (unless you pressed the ENTER key while Write was highlighted).

Search!

The quick first scan may have miss some partitions. Search! will also search for FAT32 backup boot sector, NTFS backup boot superblock, ext2/ext3 backup superblock to detect more partitions, it will scan each cylinder.

Write

Writes the changes that have been made in TestDisk's memory buffer to the hard drive. If you are unsure of the changes (often to the MBR's partition table), then don't use this function!

Extd Part

If there is logical partition, this flag lets you decide if the extended partition will used all available disk space or only the required (minimal) space.