LinuxCommandLibrary

testdisk

Recover lost partitions and repair boot sectors

SYNOPSIS

testdisk [device_file | disk_image]

PARAMETERS

device_file
    Specifies the path to a block device (e.g., /dev/sda, /dev/nvme0n1) to be analyzed for partition recovery or boot sector repair. If omitted, TestDisk will present an interactive list of detected disks to choose from.

disk_image
    Provides the path to a raw disk image file (e.g., my_disk.img, backup.dd) to perform recovery operations on. This is highly recommended as a non-destructive way to work on a copy of the problematic disk.

DESCRIPTION

TestDisk is a powerful, free, and open-source data recovery utility primarily designed to help recover lost partitions and/or make non-booting disks bootable again. It is highly effective when these issues are caused by faulty software, certain types of viruses, or human error, such as accidentally deleting a Partition Table.

It supports a wide range of file systems, including FAT, NTFS, ext2/3/4, HFS+, JFS, XFS, and more. Key functionalities include: finding lost partitions, recovering damaged boot sectors (especially for FAT/NTFS), fixing corrupted Master File Tables (MFT) for NTFS, recovering deleted files from FAT, NTFS, and ext2 filesystems, and copying files from deleted partitions.

TestDisk operates by analyzing the disk structure, identifying potential partition entries, and then allowing the user to write a new, corrected partition table. Its interactive, menu-driven interface makes it accessible, though a basic understanding of disk partitioning is beneficial.

CAVEATS

Using TestDisk incorrectly can lead to further data corruption or permanent data loss. Always back up critical data before attempting any recovery operations. It is highly recommended to run TestDisk from a live operating system (e.g., a Live CD/USB) to prevent any writes to the affected disk during the recovery process. While user-friendly, a basic understanding of disk partitioning, file systems, and the underlying data structures is beneficial for successful recovery.

INTERACTIVE OPERATION

TestDisk operates primarily through an interactive, menu-driven interface. Upon execution, it guides the user step-by-step through disk selection, analysis of partition structures, searching for lost partitions, and finally, the option to write changes to the disk or recover files. This interactive nature makes it accessible even without memorizing complex command-line arguments.

READ-ONLY ANALYSIS

By default, TestDisk performs a read-only analysis of the disk. No changes are written to the disk unless explicitly confirmed by the user, usually by selecting the [ Write ] option. This crucial safety feature helps prevent accidental data corruption during the recovery process. It is always advised to verify detected partitions and choose actions carefully.

LOG FILE GENERATION

TestDisk automatically creates a testdisk.log file in the directory from which it was executed. This log file records all actions performed and messages displayed during the session, which can be invaluable for troubleshooting, resuming interrupted operations, or for seeking expert assistance.

HISTORY

TestDisk was developed by Christophe Grenier and first released in 2002. It emerged as a powerful, free, and open-source solution for partition recovery, addressing a critical need for users across various operating systems, including Linux, Windows, and macOS. Its companion utility, PhotoRec (for file carving), was developed shortly thereafter. The project has seen continuous development and updates, maintaining its relevance and effectiveness in the data recovery landscape.

SEE ALSO

photorec(8), dd(1), gparted(8), fdisk(8), parted(8), fsck(8)

Copied to clipboard