How to Install and Use TestDisk Data Recovery Tool in Linux

TestDisk is a free and opensource, command-line data recovery tool that is used to recover data from deleted or lost partitions. Further, you can use it to revive non-bootable partitions which can be caused by factors such as accidental deletion of partition tables, and malware attacks to mention a few.

The command-line software was written in C programming languages by Christophe Granier and licensed under the GNU/GPLv2 license. TestDisk is a cross-platform tool and runs on almost any desktop operating system: Linux, Windows, macOS, FreeBSD, OpenBSD, and even NetBSD. It’s easy to use and requires no installation whatsoever.

What Can TestDisk do?

TestDisk is a powerful, and lightweight software tool that comes with a myriad of data recovery applications as outlined below:

  1. TestDisk is able to repair a corrupt or damaged partition table.
  2. It can seamlessly recover a deleted disk partition.
  3. It restores files from Windows filesystems such as NTFS, FAT, FAT32, exFAT and ext2 Linux filesystem.
  4. It can copy files from deleted or corrupt Windows filesystems such as NTFS, FAT32, and exFAT and Linux partitions (ext2, ext3, and ext4).
  5. TestDisk can recover and rebuild the NTFS, FAT32 and FAT16 boot sectors from their backups.
  6. TestDisk can also repair corrupt FAT32 tables as well as the MFT by riding with the help of the MFT mirror.

In this article, we will show you how to install TestDisk data recovery utility to recover an unbootable partition on Linux.

How to Install TestDisk on Linux

The package TestDisk is available to install from the default system repositories in most Linux distribution using the default package manager as shown.

Install TestDisk on Debian and Ubuntu

To start off, update the system packages and install TestDisk as shown.

$ sudo apt update
$ sudo apt install testdisk
Install Testdisk on Ubuntu and Debian

Install Testdisk on Ubuntu and Debian

To verify that Testdisk is installed and display more information by running the following dpkg command.

$ sudo dpkg-l testdisk
Verify TestDisk on Ubuntu

Verify TestDisk on Ubuntu

Install TestDisk on RHEL and CentOS

To install TestDisk, first enable EPEL repository and then install TestDisk as shown.

------------ On RHEL/CentOS 7 ------------
# yum install epel-release
# yum update
# yum install testdisk

------------ On RHEL/CentOS 8 ------------
# yum install
# yum update
# yum install testdisk
Install TestDisk on CentOS and RHEL

Install TestDisk on CentOS and RHEL

To verify that Testdisk is installed and display more information about the TestDisk tool run the following rpm command.

# rpm -qi testdisk
Verify TestDisk on CentOS

Verify TestDisk on CentOS

Install TestDisk on Fedora and Arch Linux

For Fedora systems run.

$ sudo dnf install testdisk

For Arch Linux run:

$ sudo pacman -S testdisk

If no suitable package is found for your Linux distribution, download TestDisk from its official site.

How to Run and Use TestDisk in Linux

Since testdisk is run from the command line, run the command below to display the partitions on your system.

# testdisk /list
TeskDisk Check Partitions

TeskDisk Check Partitions

Now, assume your Linux partition table is lost or corrupt. To restore the Linux partition using TestDisk first run.

# testdisk
Run TestDisk on Linux

Run TestDisk on Linux

Select ‘Create‘ and hit ENTER. This will display a list of partitions to choose from. In your case, your partitions will be different from what is displayed below.

TestDisk Select Partition

TestDisk Select Partition

Next, select the ‘Proceed‘ at the bottom to go on to the next options.

Proceed to Recover Partition

Proceed to Recover Partition

Your system will automatically detect the partition table type you are using. In my case it is ‘Intel‘. Hit ENTER to continue.

TestDisk Select Partition Table

TestDisk Select Partition Table

In the next section, select the ‘Analyse‘ option for the testdisk utility to probe your partition structure.

TestDisk Analyze Partition

TestDisk Analyze Partition

If No bootable partition is found on the Disk, the error below will be printed.

Partition                  Start        End    Size in sectors
No partition is bootable

*=Primary bootable  P=Primary  L=Logical  E=Extended  D=Deleted

[Proceed ]

Select ‘Proceed‘ option.

A list of available partitions will be displayed on the next screen. Hit ‘ENTER‘ to continue to the next screen.

Select the ‘write‘ option on the next screen. This option will trigger TestDisk to write on the partition table.

Next, press Y to confirm as shown below.

Write partition table, confirm ? (Y/N)

TestDsk will prompt you to reboot your system for the changes to take effect.

You will have to reboot for the change to take effect.

Select the OK option.

On the next screen select ‘Quit‘ to leave the menu and finally select ‘Quit‘ again to exit the TestDisk program.

All you have to do now is to reboot your system. If all went well, the new partition table should allow the system to boot normally.

Read Also: How to Recover Deleted Files Using TestDisk in Linux


TeskDisk is an ideal tool when you want to unerase data from corrupt partitions or revive unbootable partitions and get them to boot as expected. It supports a vast range of file systems and can work in any operating system: from Windows to Linux.

In this guide we illustrated how to recover an unbootable partition using TestDisk, however, the tool can be used for so much more!

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

James Kiarie

This is James, a certified Linux administrator and a tech enthusiast who loves keeping in touch with emerging trends in the tech world. When I'm not running commands on the terminal, I'm taking listening to some cool music. taking a casual stroll or watching a nice movie.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

1 Response

  1. Martins Almeida says:

    It seems to me it is a limited recovery tool as it needed to be installed in the faulty computer in order to recover data. Probably it would be better that this software was created to be installed in an external bootable device, such as a dvd or flash drive.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.