Reference articles on history, science, culture and more
Encyclopedia

TestDisk

Data recovery utility

Image credit is listed at the end of this article.

TestDisk is a free and open-source data recovery utility that helps users recover lost partitions or repair corrupted filesystems. TestDisk can collect detailed information about a corrupted drive, which can then be sent to a technician for further analysis. TestDisk supports MS-DOS, Windows, Linux, FreeBSD, NetBSD, OpenBSD, SunOS, and MacOS. TestDisk handles non-partitioned and partitioned media. In particular, it recognizes the GUID Partition Table (GPT), Apple partition map, PC/Intel BIOS partition tables, Sun Solaris slice and Xbox fixed partitioning scheme. TestDisk uses a command line user interface. In one test TestDisk recovered deleted files with 97% accuracy.

01Features

TestDisk can recover deleted partitions, rebuild partition tables or rewrite the master boot record (MBR). EFI GPT is also supported.

Partition recovery

TestDisk retrieves the LBA size and CHS geometry of attached data storage devices (i.e. hard disks, memory cards, USB flash drives, and virtual disk images) from the BIOS or the operating system. The geometry information is required for a successful recovery. TestDisk reads sectors on the storage device to determine if the partition table or filesystem on it requires repair (see next section).

TestDisk is able to recognize the following partition table formats:

  • Apple partition map
  • GUID Partition Table
  • Humax
  • PC/Intel Partition Table (master boot record)
  • Sun Solaris slice
  • Xbox fixed partitioning scheme
  • Non-partitioned media

TestDisk can perform deeper checks to locate partitions that have been deleted from the partition table. However, it is up to the user to look over the list of possible partitions found by TestDisk and to select those that they wish to recover.

After partitions are located, TestDisk can rebuild the partition table and rewrite the MBR.

Filesystem repair

TestDisk can deal with some specific logical filesystem corruption.

File recovery

When a file is deleted, the list of disk clusters occupied by the file is erased, marking those sectors available for use by other files created or modified thereafter. TestDisk can recover deleted files especially if the file was not fragmented and the clusters have not been reused.

There are two file recovery mechanisms in the TestDisk package:

  • TestDisk proper uses knowledge of the filesystem structure to perform "undelete".
  • PhotoRec is a "file carver". It does not need any knowledge of the file system, but instead looks for patterns of known file formats in the partition or disk image. It works best on unfragmented files and cannot recover the file name.

02Digital forensics

TestDisk can be used in digital forensics to retrieve partitions that were deleted long ago. It can mount various types of disk images including the Expert Witness File Format used by EnCase. Binary disk images, such as those created with ddrescue, can be read by TestDisk as though they were storage devices.

In TestDisk versions prior to version 7, a malformed disk or its image can be used to inject malicious code into a running TestDisk application on Cygwin.

03File system support

File system support for TestDisk is shown in the table:

Name Partition Recovery Filesystem Recovery File Recovery
Find filesystem Boot sector/
superblock Restore
File table repair Undelete
FAT12/16/32 YesYesYesYes
exFAT YesYesUse fsckYes
NTFS YesYesYesYes
ext2, ext3, and ext4 YesYesUse fsckYes
HFS, HFS+, HFSX YesYesUse fsckNo
ReFS NoNoNoNo
APFS NoNoNoNo
BeOS YesNoNo
BSD disklabel (FreeBSD/OpenBSD/NetBSD) YesNo
Cramfs YesNo
IBM JFS2 YesNo
Linux RAID (mdadm) YesNo
Linux Swap 1 and 2 YesNo
LVM and LVM2 YesNo
Novell Storage Services (NSS) YesNo
ReiserFS 3.5, 3.6 and 4 YesNo
Sun Solaris i386 disklabel YesNo
UFS and UFS2 (Sun/BSD/…) YesNo
XFS from SGI YesNo

Some features, such as partition table editing and PhotoRec "carving", do not depend on the file system at all.

Watch videos about TestDiskExplainers and documentaries on YouTube (opens in a new tab)

Sources and credits

This article is adapted from the Wikipedia article TestDisk, written by its contributors and licensed under CC BY-SA 4.0. Fathomly has changed the layout, removed citation markers, navigation and maintenance notices, and adjusted punctuation. This adapted version is shared under the same license. For references, see the original article.

Images, from Wikimedia Commons:

Fathomly is not affiliated with or endorsed by the Wikimedia Foundation. Spotted a problem? Tell us.