I accidentally formatted my Android phone's storage partition while updating to Android Oreo today. When I tried to restore the backup I realized that the backup of the data partition had failed and basically is an empty file with 0 Bytes.

I would like to run PhotoRec over it but I'm somehow unable to get my phone into mass storage mode. It seams like Google has ditched it for MTP. I tried some apps from XDA but none of them really worked with my device. I was able to get the external SD mounted but not the internal storage. The custom recoveries that are available for my device only support MTP as well.

Does anyone have an idea how it could be possible to recover my files? I'm rooted and bootloader is unlocked.


You can't do that. Google has made MTP the default since version 3.0 and remove mass storage mode completely years ago in Android 4.0

If you want to do things directly on the data partition you have 2 ways

  • Run command in adb shell
  • Start in recovery mode (if you're using a custom ROM)

Since you're running a restore from backup, I assume you're on a custom ROM and still have the backup file with you, why don't just do the restoration again?

| improve this answer | |
  • The backup failed. file size of the data partition backup is 0 bytes and i only realized when it was too late so i cant just restore – J. Doe Jul 23 '18 at 11:57

This method works only if kernel is built with CONFIG_USB_F_MASS_STORAGE and Android Composite Gadget driver (CONFIG_USB_G_ANDROID). For newer devices built with CONFIG_USB_CONFIGFS_MASS_STORAGE /config/usb_gadget interfaces are to be used in place of /sys. See Linux USB gadget configured through configfs.

USB Mass Storage (UMS) is disabled on newer Android versions by default. So you need custom recovery to enable UMS:

# mountpoint /data && umount /data

# echo '0' >/sys/class/android_usb/android0/enable
# echo '/dev/block/bootdevice/by-name/userdata' >/sys/class/android_usb/android0/f_mass_storage/lun/file
# echo 'mass_storage' >/sys/class/android_usb/android0/functions
# echo '1' >/sys/class/android_usb/android0/enable

* Paths may vary depending on device
* If your /data partition is FDE encrypted and you unencrypted it in recovery, path will be dev/block/dm-0

Now /data will appear as a partition on Linux PC. Other options to access internal storage at block level are answered in below mentioned question.

To make sure your data is recoverable, see this answer.


| improve this answer | |