Recovering data from internal memory on Android for dummies
- From the sandbox
- Tutorial
Now more and more smartphones go without an sd-card slot, and information has to be stored on internal memory with access to it via MTP. This connection mode does not allow standard means to restore phone data after wipe'a or accidental deletion.
Today, using the example of a bunch of Xiaomi Mi2s and Windows 8.1, I’ll try to tell you how you can recover lost data, who are interested, welcome to cat.
It should be noted that if you mistakenly formatted the internal memory of a smartphone / tablet / smartpad, then you should not be upset, and most importantly, in no case do you need to write anything to the device’s memory, so you can recover more data.
The MTP protocol does not allow the computer to recognize the connected device as a USB drive and recovery programs cannot scan such a device and save the data, so we need to copy the entire internal memory partition as a system image.
You will need root and enabled USB debugging.
In order to copy the system partition, we need:
First, install the USB drivers for your device and ADB. After that, I advise you to restart the PC.
We create a folder with the address C: \ cygwin64 \ 000 (the name does not matter, you should not just use letters other than the Latin alphabet), here our image will lie. Copy to the VHDtool.exe folder.
During the installation, we agree to all standard installations.
After installation, FileZilla will start automatically, but you must exit the program and run it on behalf of the Administrator .
When starting FileZilla will ask for the server name, leave everything as it is.

Next, go to Edit - Settings and make the following settings:
listen on those ports 40
timeout settings - the default is 120, 60, 60, and we put 0 everywhere and click OK.
Go to edit - users. In the users window, create a new user. In my case, this is the qwer user.
Click Add - write the name - password pass - click OK.
Next, in the same Users menu, on the left, select the Shared folders tab. We go there and add the folder into which our block will be poured. Click Add and add the folder C: \ cygwin64 \ 000. The path to this folder will appear in the window. If there is no letter H to the left of the inscription C: \ cygwin64 \ 000, then click Set as home dir. Then, highlighting the line C: \ cygwin64 \ 000, you need to mark Read and Write rights with checkmarks. Then click OK.


We will need the following files:
You can download them here .
Or pull from the Android SDK distribution.
Copy them to the folder C: \ cygwin64 \ bin
Launch the console from the folder C: \ cygwin64 \ bin, just enter cmd in the address bar of the explorer.

Enter the command:
The list of connected devices should not be empty, if after the line List of devices attached is empty, you did not install USB drivers or enable USB debugging.
When everything goes well, the console looks like this:

20352f2c is my Xiaomi Mi2s
We will need to connect the device via USB to your PC and turn on the modem mode via USB. I use CyanogenMod 11 and I have this mode located along the path: Settings> Wireless Networks> More ...> Modem Mode> USB Tethering
Now we need to find out which IPv4 address your computer received.
We use the ipconfig command on the command line
or
go along the path: Control Panel \ Network and Internet \ Network and Sharing Center

Click on the words 'Local Area Connection' next Information and copy the IPv4 address.

In my case it is 192.168.42.79
Important! Each time you reconnect the USB cable and turn on / off the modem mode, IPv4 will change.
All the memory in your device is divided into logical blocks, we do not need to download everything, just understand which section contains the erased information.
Now we need to look at the list of memory blocks, for this we enter the following commands line by line:
Hint: if you are too lazy to manually rewrite commands or you are afraid to make a mistake, you can use copying, but you won’t be able to paste a line into the console in the usual way, so you need to right-click on the console window, then select change> paste.

After that, the list_of_partitions.txt file will appear in the internal memory, which we need to copy to the PC and study.
You can copy it to our folder 000 using a simple command (it should be performed in a separate command window):
The internal memory in my device is 32 GB. Therefore, I am looking for the largest section, in my case it is mmcblk0p27 of size 25.6 GB, it will most likely have a different name for you, or it will not have p ** at all. Of course, no one guarantees that the largest section will turn out to be the one on which more recently your photos, videos, documents, etc. lay, but in 90% of cases this turns out to be the exact section of memory that we need. Otherwise, you will have to copy all the images in order and check each of them.
If you have already closed the cmd window, then run it again.
We enter the commands line by line:
Do not forget to make appropriate adjustments to the code!
We decrypt what was written:
qwer - the name of the account in FileZilla (you have your own if changed)
pass - password from the account in FileZilla (yours if you changed)
40 - the port of the FileZilla server
192.168.42.79 - the address of the FileZilla server (you have your own)
mmcblk0p27 .raw - the copied memory block (you have your own)

Open the second command prompt window and enter the commands:
Do not forget to fix mmcblk0p27 to your block number!
We look into the FileZilla window and see that downloading mmcblk0p27.raw to the C: \ cygwin64 \ 000 folder has begun, now you can close the cygwin windows and take a tea break.

Are you back? Did the file download? Excellent. Turn off the phone, connect the Internet. Run Cygwin.bat and enter the following commands.
Do not forget to fix mmcblk0p27 to your block number!
It took me a couple of seconds to convert. At the output, we get the same file mmcblk0p27.raw in the folder C: \ cygwin64 \ 000, but a little different. This converted file can be mounted as a virtual disk, or, for example, through R-studio, perform data recovery directly from our image. I did just that.

Hint: Important points marked in yellow.
My goal was to explain in a popular language how to copy a system partition from an android device to a PC, some may reproach me with the difficulties associated with a USB modem and ftp and say that it was probably easier to pull out the image. The answer is: I tried in other ways, described on w3bsit3-dns.com and xda-developers, it didn’t work out for me, but with ftp it turned out on the second try, and when I wrote the article everything went smoothly.
I managed to recover all the lost photos without loss in quality and even that I did not think to restore. During the restoration, photos were found that I took in August last year, when I just bought a phone and tested the camera.
In conclusion, I would also like to mention another small utility that restores data - DiskDigger undelete. It is free, good functionality, but unfortunately, after 40%, it fell out of my mind with an error.
PS Now I will do backup more often ...
PPS Many thanks to the user bakatrouble for the visual experiment in the comments and help in optimizing the process
Today, using the example of a bunch of Xiaomi Mi2s and Windows 8.1, I’ll try to tell you how you can recover lost data, who are interested, welcome to cat.
It should be noted that if you mistakenly formatted the internal memory of a smartphone / tablet / smartpad, then you should not be upset, and most importantly, in no case do you need to write anything to the device’s memory, so you can recover more data.
The MTP protocol does not allow the computer to recognize the connected device as a USB drive and recovery programs cannot scan such a device and save the data, so we need to copy the entire internal memory partition as a system image.
Preparing an Android device
You will need root and enabled USB debugging.
PC preparation
In order to copy the system partition, we need:
- VHDtool ;
- Drivers for your device (in case of problems habrahabr.ru/post/205572 );
- ADB ( adbdriver.com or developer.android.com );
- FileZilla Server .
First, install the USB drivers for your device and ADB. After that, I advise you to restart the PC.
Vhdtool
We create a folder with the address C: \ cygwin64 \ 000 (the name does not matter, you should not just use letters other than the Latin alphabet), here our image will lie. Copy to the VHDtool.exe folder.
Filezilla
During the installation, we agree to all standard installations.
After installation, FileZilla will start automatically, but you must exit the program and run it on behalf of the Administrator .
When starting FileZilla will ask for the server name, leave everything as it is.
Next, go to Edit - Settings and make the following settings:
listen on those ports 40
timeout settings - the default is 120, 60, 60, and we put 0 everywhere and click OK.
Go to edit - users. In the users window, create a new user. In my case, this is the qwer user.
Click Add - write the name - password pass - click OK.
Next, in the same Users menu, on the left, select the Shared folders tab. We go there and add the folder into which our block will be poured. Click Add and add the folder C: \ cygwin64 \ 000. The path to this folder will appear in the window. If there is no letter H to the left of the inscription C: \ cygwin64 \ 000, then click Set as home dir. Then, highlighting the line C: \ cygwin64 \ 000, you need to mark Read and Write rights with checkmarks. Then click OK.
Adb
We will need the following files:
- adb.exe
- AdbWinApi.dll
- adb-windows.exe
- AdbWinUsbApi.dll
- fastboot.exe
You can download them here .
Or pull from the Android SDK distribution.
Copy them to the folder C: \ cygwin64 \ bin
Testing ADB
Launch the console from the folder C: \ cygwin64 \ bin, just enter cmd in the address bar of the explorer.
Enter the command:
adb devices
The list of connected devices should not be empty, if after the line List of devices attached is empty, you did not install USB drivers or enable USB debugging.
When everything goes well, the console looks like this:

20352f2c is my Xiaomi Mi2s
USB modem mode
We will need to connect the device via USB to your PC and turn on the modem mode via USB. I use CyanogenMod 11 and I have this mode located along the path: Settings> Wireless Networks> More ...> Modem Mode> USB Tethering
Screenshot

Now we need to find out which IPv4 address your computer received.
We use the ipconfig command on the command line
or
go along the path: Control Panel \ Network and Internet \ Network and Sharing Center
Click on the words 'Local Area Connection' next Information and copy the IPv4 address.
In my case it is 192.168.42.79
Important! Each time you reconnect the USB cable and turn on / off the modem mode, IPv4 will change.
What memory block do we need?
All the memory in your device is divided into logical blocks, we do not need to download everything, just understand which section contains the erased information.
Now we need to look at the list of memory blocks, for this we enter the following commands line by line:
adb shell
su
find /dev/block/platform/ -name 'mmc*' -exec fdisk -l {} \; > /sdcard/list_of_partitions.txt
Hint: if you are too lazy to manually rewrite commands or you are afraid to make a mistake, you can use copying, but you won’t be able to paste a line into the console in the usual way, so you need to right-click on the console window, then select change> paste.

After that, the list_of_partitions.txt file will appear in the internal memory, which we need to copy to the PC and study.
You can copy it to our folder 000 using a simple command (it should be performed in a separate command window):
adb pull /sdcard/list_of_partitions.txt C:/cygwin64/000
My file has the form
Disk /dev/block/platform/msm_sdcc.1/mmcblk0p27: 25.6 GB, 25698483712 bytes
4 heads, 16 sectors/track, 784255 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Disk /dev/block/platform/msm_sdcc.1/mmcblk0p27 doesn't contain a valid partition table
Disk /dev/block/platform/msm_sdcc.1/mmcblk0p26: 3758 MB, 3758096384 bytes
4 heads, 16 sectors/track, 114688 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Disk /dev/block/platform/msm_sdcc.1/mmcblk0p26 doesn't contain a valid partition table
Disk /dev/block/platform/msm_sdcc.1/mmcblk0p25: 402 MB, 402653184 bytes
4 heads, 16 sectors/track, 12288 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Disk /dev/block/platform/msm_sdcc.1/mmcblk0p25 doesn't contain a valid partition table
итд…
The internal memory in my device is 32 GB. Therefore, I am looking for the largest section, in my case it is mmcblk0p27 of size 25.6 GB, it will most likely have a different name for you, or it will not have p ** at all. Of course, no one guarantees that the largest section will turn out to be the one on which more recently your photos, videos, documents, etc. lay, but in 90% of cases this turns out to be the exact section of memory that we need. Otherwise, you will have to copy all the images in order and check each of them.
Copy the memory section to the PC.
If you have already closed the cmd window, then run it again.
We enter the commands line by line:
adb shell
su
mkfifo /cache/myfifo
ftpput -v -u qwer -p pass -P 40 192.168.42.79 mmcblk0p27.raw /cache/myfifo
Do not forget to make appropriate adjustments to the code!
We decrypt what was written:
qwer - the name of the account in FileZilla (you have your own if changed)
pass - password from the account in FileZilla (yours if you changed)
40 - the port of the FileZilla server
192.168.42.79 - the address of the FileZilla server (you have your own)
mmcblk0p27 .raw - the copied memory block (you have your own)
Open the second command prompt window and enter the commands:
adb shell
su
dd if=/dev/block/mmcblk0p27 of=/cache/myfifo
Do not forget to fix mmcblk0p27 to your block number!
We look into the FileZilla window and see that downloading mmcblk0p27.raw to the C: \ cygwin64 \ 000 folder has begun, now you can close the cygwin windows and take a tea break.
Convert and restore
Are you back? Did the file download? Excellent. Turn off the phone, connect the Internet. Run Cygwin.bat and enter the following commands.
cd C:/cygwin64/000/
VhdTool.exe /convert mmcblk0p27.raw
Do not forget to fix mmcblk0p27 to your block number!
It took me a couple of seconds to convert. At the output, we get the same file mmcblk0p27.raw in the folder C: \ cygwin64 \ 000, but a little different. This converted file can be mounted as a virtual disk, or, for example, through R-studio, perform data recovery directly from our image. I did just that.
Hint: Important points marked in yellow.
Summary
My goal was to explain in a popular language how to copy a system partition from an android device to a PC, some may reproach me with the difficulties associated with a USB modem and ftp and say that it was probably easier to pull out the image. The answer is: I tried in other ways, described on w3bsit3-dns.com and xda-developers, it didn’t work out for me, but with ftp it turned out on the second try, and when I wrote the article everything went smoothly.
I managed to recover all the lost photos without loss in quality and even that I did not think to restore. During the restoration, photos were found that I took in August last year, when I just bought a phone and tested the camera.
In conclusion, I would also like to mention another small utility that restores data - DiskDigger undelete. It is free, good functionality, but unfortunately, after 40%, it fell out of my mind with an error.
PS Now I will do backup more often ...
PPS Many thanks to the user bakatrouble for the visual experiment in the comments and help in optimizing the process