How to Recover Data in Linux After Formatting a Hard Disk, USB Stick or Memory Card?

Read this article to find out how to recover data lost after formatting a hard disk, USB stick or memory card in Linux.

How to Recover Data in Linux After Formatting a Hard Disk, USB Stick or Memory Card?

When any storage device is formatted, a part of the information about the location of data on the disk is erased. However, in most cases data recovery after formatting is still possible. Your chances for success depend on the file system type, type of data, and the number of files. Another factor is what information and how much of it was written to the disk after it was formatted.

WARNING!!! You shouldn’t write anything or do other things to your freshly formatted disk since it will greatly reduce your chances for recovery!

In this article, we will explore data recovery methods with the example of Mint, but everything is relevant for other versions of Linux as well (Ubuntu, CentOS, Fedora, Debian, and so on.)

Go to view
How to Recover Files After Emptying Linux Trash or Using Shift + Del

How to Recover Files After Emptying Linux Trash or Using Shift + Del

How to format a disk in Linux

Suppose we have a disk containing some data.

Linux Mint: a disk with data

Go to the Disks tool to see that the disk is healthy and has the file system – ext4, xfs, or btrfs.

In fact, it doesn’t matter, what file system is used for your disk. The sequence of actions described in this article will work for all Linux file systems, and soon you will understand why.

Linux Mint: ext4 disk with data

Let’s format the disk in any way you find convenient:

Method 1. With the Terminal.

Type the following command to display the list of all disks and partitions. You can identify the required disk by its size or name, or by its file system.

lsblk –fs

Linux Mint:  lsblk –fs

Now you need to unmount the disk if it’s active. Use this command to help you do it:

sudo umount /dev/sdb2

Linux Mint: sudo umount /dev/sdb2

Now format the data storage device in the required file system:

sudo mkfs.ext4 /dev/sdb2

where,

  • ext4 - the file system;
  • /dev/sdX – the disk to be formatted.
Linux Mint: sudo mkfs.ext4 /dev/sdb2
Command /Utility Purpose Example of usage Notes
mkfs A general command to create file systems mkfs.ext4 /dev/sdX1 used with various file system types
mkfs.ext4 Create EXT4 file system mkfs.ext4 /dev/sdX1 The most popular file system on Linux
mkfs.ntfs Format into NTFS mkfs.ntfs /dev/sdX1 You need to install the package ntfs-3g
mkfs.vfat Format into FAT32 mkfs.vfat /dev/sdX1 Compatible with Windows and most devices
mkfs.xfs Create XFS file system mkfs.xfs /dev/sdX1 Suitable for large volumes
mkfs.btrfs Format into Btrfs mkfs.btrfs /dev/sdX1 Modern file system with snapshot support
parted Disk formatting and partitioning parted /dev/sdX mklabel gpt Supports both GPT and MBR
fdisk Text-mode partitioning (MBR) fdisk /dev/sdX Used to create and delete partitions
gparted Graphical disk management utility Needs to be installed separately (apt install gparted)
disks (GNOME Disks) Graphical and convenient utility Suitable for novice users

Method 2. With specialized software tools.

For example, Gparted or KDE Partition Manager.

Gparted
KDE Partition Manager

Method 3. With the graphic interface of your system, or with the Disks tool.

If you don’t erase the disk, USB stick or memory card, then your data can be recovered with the same effectiveness regardless of which method you decided to use.

Click on the disk settings menu and choose Format.

Click on the disk settings menu and choose Format

Erase/overwrite feature in Linux

Pay attention to the erase/overwrite feature when formatting your disk.

Erase/overwrite feature in Linux

If you don’t enable this option, only the file allocation table will be overwritten. The files themselves will be intact. The operating system will just label them as deleted. After such method, recovering information from the disk won’t be difficult.

But if you enable the Erase feature, it will overwrite all disk data while formatting the storage device. In this case, there’s no guarantee that data recovery can be successful.

Hetman Partition Recovery: HEX-Editor

Recovering Linux data after formatting

Choose the format type and file system.

Linux Mint: Choose the format type and file system

As you can see, the disk has been formatted, while its files and folders are removed. What shall we do now?

Linux Mint: a formatted disk

Run Hetman Partition Recovery:

The tool recovers data from any devices, regardless of the cause of data loss.
  • The app will ask you for the root user password. Enter it.

    Hetman Partition Recovery: root user password
  • Choose your disk.

    You can identify the required disk by its size or name, or by its file system.

    Hetman Partition Recovery: ext4 disk
  • Select Full analysis and specify the file system.

    Fast scan is not suitable to recover data after formatting a hard disk, USB stick, or memory card.

    Hetman Partition Recovery: Full analysis
  • As you can see, the recovery tool can deal with almost any file system. That is why we mentioned before that the file system of the formatted disk does not matter. Data in different file systems is actually recovered in the same way.

  • You can see the file system of your disk in the tool itself, or in the Disks utility. However, the recovery tool tends to properly identify the file system of the disks it works with.

  • When the scan is over, click Finish.

    Hetman Partition Recovery: Full analysis is complete

Now you can see the recovery tool has created two folders.

Hetman Partition Recovery: folder Lost and Found

In one of them, you can find the same number of folders that have been lost as a result of formatting.

Hetman Partition Recovery: deleted files and folders

Inside the folders, there are your files.

Hetman Partition Recovery: file preview

In the other folder (Content-Aware Analysis), there are files that have been found by analyzing the contents of files. They are sorted by type.

Hetman Partition Recovery: Content-Aware Analysis folder

In both folders, you can preview the files.

If you’re looking for a specific file of a specific format, then it’s more convenient to find it in Content-Aware Analysis folder. If you need to recover contents of a certain folder, then go to the folder named Lost and Found.

If a partition is formatted in a different file system, or even deleted, the recovery tool will also display the partition with the previously existing file system. In this case, select a particular disk with the file system from which data should be recovered.

Hetman Partition Recovery: deleted disk partitions

To recover necessary files or folders:

  • To have the files back, select them and hit the Recovery button.

    Hetman Partition Recovery: recovering deleted folders
  • Otherwise, drag them to the Recovery List. If you can’t see one, go to View - Toolbars - Recovery List to open it;

    Hetman Partition Recovery: View - Toolbars - Recovery List
  • Choose the method to save them;

    Hetman Partition Recovery: Save to hard disk
  • Choose a folder and click Recovery.

    Hetman Partition Recovery: give the path to recover files
  • As you can see, the files are recovered now.

    Linux Mint: recovered files

Conclusions

I have shown this example with a hard disk on my computer. However, using this method you can recover data after formatting a USB stick or memory card, an external hard disk or another storage device regardless of the interface used to connect them to a computer, Be it a card reader, USB port, or Type-C port.

Talking of data recovery from SSDs, this process has its own peculiarities, but it’s a topic for another article.

Vladimir Artiukh

Author: , Technical Writer

Vladimir Artiukh is a technical writer for Hetman Software, as well as the voice and face of their English-speaking YouTube channel, Hetman Software: Data Recovery for Windows. He handles tutorials, how-tos, and detailed reviews on how the company’s tools work with all kinds of data storage devices.

Oleg Afonin

Editor: , Technical Writer

Oleg Afonin is an expert in mobile forensics, data recovery and computer systems. He often attends large data security conferences, and writes several blogs for such resources as xaker.ru, Elcomsoft and Habr. In addition to his online activities, Oleg’s articles are also published in professional magazines. Also, Oleg Afonin is the co-author of a well-known book, Mobile Forensics - Advanced Investigative Strategies.

Recommended For You

Hello! This is AI-based Hetman Software virtual assistant, and it will answer any of your questions right away.
Start Chat