How To Recover Data From an Android Device Using Linux

Learn to process Android data recovery using Linux in this guide.

When you think about Linux, you likely envision a computer operating system. Data recovery is just one of the many uses for Linux, a very adaptable operating system. Therefore, with the use of Linux, it is possible to recover lost data from an Android device. This article will discuss performing Android data recovery using Linux in internal and external memory. Furthermore, with the help of the Android data recovery software for Linux listed here, you can also recover your important files easily.

Can You Recover Deleted Files From Android Phone Using Linux?

Yes, users can recover deleted files from an Android phone using Linux. There are two kinds of recovery case scenarios:

  • Recovering from Android internal and external memory: Users can use "adb," a component of the Android SDK, or the "fastboot" tool, which is used to unlock the bootloader on Android phones to access the Android file system from a Linux computer to recover deleted files.
  • Recovering from Android phone external memory (SD card): For external memory like an SD card, any Linux-compatible data recovery software should work. Examples include TestDisk for Linux and other Linux data recovery tools.

This second scenario is easy to do by connecting the SD card to a Linux computer, and you can already run the data recovery tool. So, this article will concentrate on the first option (recovering from Android internal and external memory).

How To Recover Data From the Android Internal and External Memory on Linux?

The Android Debug Bridge (ADB) command-line tool is useful for communicating with Android devices. You may carry out many tasks on the target device via the ADB.

ADB consists of two components: the desktop client and the one that ships with Android. We may use the desktop ADB client to send the Android device various commands when it is connected, and USB debugging is enabled. The Android SDK, accessible on Windows, Linux, macOS, and other platforms, includes ADB.

Prerequisites

  • Agnostic Linux-based operating system
  • Rooted Android phone
  • Installed BusyBox on the Android device
  • To obtain “adb,” install the Android SDK. Download the (large) SDK, unpack it, and launch adb from within.
  • TestDisk, Pipe Viewer (PV), and, if necessary, extundelete (to recover files from ext3/4 filesystems). If you're using Debian, run the following:

# apt-get install testdisk pv extundelete

Step 1: Access the Android File System

  1. Enable USB Debug on your device to connect with adb. Connect the Android device to the Linux computer using a USB cable. Then, open a terminal on your Linux computer and navigate to the sdk/platform-tools in the Android SDK directory where adb is located.
  1. Use adb shell to connect to your phone:

$ ./adb shell

Note: If the command above fails, you may need to call adb start-server as root first.

We can now use the mount command to determine which partition contains the SD Card data and dump the partition or dump out the entire memory content to avoid failure.

  1. Look for a block tool called /dev/block/mmcblk0. We can see multiple partitions within mmcblk0, but we will leave the partition management to TestDisk later. Exit the shell to return to your computer's Android SDK directory sdk/platform-tool.
  2. Let us now dump the contents of /dev/block/mmcblk0. Use adb shell to elevate to superuser and run cat to dump the content, as shown below:

$ ./adb shell su -c "cat /dev/block/mmcblk0" | pv > mmcblk0.raw

We can now let TestDisk handle the rest.

Learn more tools to access Android on Linux with video tutorials:

Step 2: Android Data Recovery on Linux

After accessing the Android device on Linux, you can now use any Linux data recovery tools to recover data from it, for example, TestDisk.

  1. To begin, restore the GPT partition table. Choose mmcblk0.raw in the TestDisk interface, and press Proceed.
restore the gpt partition table
  1. Select the EFI GPT partition map.
Select the efi gpt partition map
  1. Then, for TestDisk to find the partitions, select Analyse.
analyze partitions
  1. Select Quick Search.
apply quick search
  1. The search will yield a table like this:
seach table
  1. Then press Enter to proceed.
press enter
  1. Choose the Write option to save this new (recovered) partition table. Then, tap Y to confirm the selection.
choose the write option
  1. You will then be notified that you must reboot. However, there is no such demand in this situation. Press Enter to continue. Now that the partition table has been restored, we can try recovering the files.
try recovering the files
  1. To use TestDisk's Filesystem Utilities section, select Advanced.
select advanced
  1. Choose the partition for which you want to perform the recovery. In this example, we'll use the Undelete option to recover photos from the FAT32 SD Card partition:
use the undelete option
  1. Now we can search the filesystem for recoverable files:
search the filesystem for recoverable files
  1. There are many recoverable files in the /DCIM/100ANDRO directory, where the Android device stores the photos. Choose it, then use C or c to recover them to one of the Linux computer's file systems.
recover files
  1. Optional: To recover files from an ext3/ext4 partition, TestDisk has an Image Creation option that will write an image of that partition called image.dd to a file on the Linux computer's file system.
recover files from ext3/ext4 partition

Then, in your terminal window, use extundelete to recover files from the image:

$ extundelete --restore-all image.dd

Aside from TestDisk, many free and open-source Linux data recovery tools are available in the market. Here are a few examples:

  • PhotoRec for Linux: A powerful tool that can recover lost partitions, repair damaged file systems, and recover deleted files.
  • Extundelete: A tool that can recover deleted files from ext4 file systems.
  • Ddrescue: A tool for recovering data from failing storage devices and cloning storage devices with bad sectors.
  • Foremost: A tool for recovering files based on their headers and footers.
  • Scalpel: A Linux data recovery tool based on the headers and data structures.

Each tool may have different capabilities and limitations. It is always recommended to try more than one tool to increase the chances of successful recovery.

Summing Up

In this article, we listed the 2 major steps to recover data from an Android device using Linux. First, you must access the Android file system and then recover your lost or deleted data on your Android device by a Linux device. However, we listed the best Linux data recovery software if you want a more convenient way of recovering files. Check them out now!

You May Also Like