FORUMS

OnePlus Addresses Reservation List Cheating

Jake Cooper figured out how to bump his place up on OnePlus’ reservation list and … more

OnePlus 2 Benchmark Scores Show Its Muscle

This video by FoneArena contains all the popular benchmarks being tested on the OnePlus 2, … more

Sony’s Emergence in The Middle: Is The Price Right?

Sony’s Electronics Division is not in its best days, and its smartphone … more

HTC Delivering Ads Straight to Sense Home

HTC’s 2015 has been a year marked by a desperate search for revenue.The HTC One M9 … more

Mounting Internal Storage as a USB Mass Storage Device and Recovering Data

6 posts
Thanks Meter: 0
 
By CleverCoder, Junior Member on 9th August 2014, 10:09 PM
Post Reply Subscribe to Thread Email Thread
CleverCoder's Guide to Mounting Android’s Internal Storage As A Mass Storage USB Device

I found inspiration from this guide: http://mohammadag.xceleo.org/mountin...ernal-storage/
His process did not work exactly, but by changing the “lun” to “lun0” and the path to the “android_usb” device, I was able to get this to work with my rooted Samsung Note 10.1. The instructions below were verified on my Note 2.

I was motivated to find this solution after I accidentally deleted my daughters world that she worked so hard to create in Survivalcraft. Ultimately, I wasn’t able to recover her world, but I learned a lot in the process. Enjoy!

Steps:
  1. Boot into recovery mode (Usually holding volume (and home) down while powering up). I find the Wiki on CyanogenMod to be helpful to find device-specific bootloader instructions.
  2. Invoke a root shell using ADB: “adb shell" (Note: This assumes you have the Android SDK installed and /platform-tools are in your PATH)
  3. Find the /data partition, determine the block device that corresponds to it:

    Code:
    mount | grep /data
    Quote:


    /dev/block/mmcblk0p16 on /data type ext4 (rw,seclabel,relatime,user_xattr,barrier=1,data=or dered)

  4. Make a note of the block device name. In my case, it's "/dev/block/mmcblk0p16". Unmount the /data partition to allow mounting as a mass storage device:
    Code:
    umount /data
  5. Locate the “mass storage” device LUN entry. (In my case, it was ..\lun0 rather than ..\lun):
    Code:
    find /sys -name lun*
    Quote:


    /sys/devices/platform/s3c-usbgadget/gadget/lun0
    /sys/devices/virtual/android_usb/android0/f_mass_storage/lun0

    In this case, we want to make a note of the entry with "f_mass_storage" in it. This is the entry that corresponds to a USB Mass Storage device.
  6. Map the block device to the mass storage logical device LUN “file”. Note, this will be a file called “file” within the LUN folder. For example:
    "/sys/devices/virtual/android_usb/android0/f_mass_storage/lun/file":
    ~# echo BLOCK_DEVICE_HERE > LUN_FILE_PATH_HERE
    For example:
    Code:
    echo /dev/block/mmcblk0p16 > /sys/devices/virtual/android_usb/android0/f_mass_storage/lun0/file
    Note: the ADB shell appears to wrap at around 80 characters, making it look like the line is split.
  7. Reconfigure the USB device in “mass storage” mode. This has to be done in one command, since it will terminate the ADB connection. Also, the path varies to the “android_usb” device. It may be:
    /sys/devices/virtual/android_usb/android0/
    /sys/class/android_usb/android0/
    You can use "find /sys -name *android0*" to help narrow the options. I believe either entry will work. YMMV

    On my Note 2 the following worked:
    Code:
    echo "echo 0 > /sys/devices/virtual/android_usb/android0/enable && echo \"mass_storage,adb\" > /sys/devices/virtual/android_usb/android0/functions && echo 1 > /sys/devices/virtual/android_usb/android0/enable" > enable_mass.sh
    sh enable_mass.sh &
    This should terminate the ADB connection and cause a new USB device to appear, representing the /data volume mounted as a mass storage device.

At this time, the block device associated with the /data partition should show up as a USB mass storage device on your computer. I verified this with OSX. OSX did not support the ext3/4 filesystem, however, Unix utilities that support it will work.

Recovering Files

Once the device is mounted on your host machine, you can use PhotoRec (http://www.cgsecurity.org/wiki/PhotoRec) to recover files. It performs a file signature based recovery, is very powerful, and works with any file you can think of. It’s also easy to add support for your own file types.

I hope this helps others.
Cheers!
- Sean
Last edited by CleverCoder; 9th August 2014 at 10:16 PM. Reason: Small typos
 
 
9th October 2014, 11:49 PM |#2  
Junior Member
Thanks Meter: 0
 
More
Have anyone tried it?
19th January 2015, 08:45 PM |#3  
Junior Member
Flag Salzgitter
Thanks Meter: 1
 
Donate to Me
More
Failed while do the step with the lun0/file.
Permission denied
8th March 2015, 01:13 PM |#4  
Member
Thanks Meter: 6
 
More
Quite interesting and works as expected with lun/file
Last edited by yogi77; 8th March 2015 at 01:17 PM.
10th March 2015, 05:10 AM |#5  
intika's Avatar
Senior Member
Thanks Meter: 198
 
Donate to Me
More
Thanks for this amazing post
great

command done for E300K over Wifi adb
while system running normally
working great thanks
Code:
echo /dev/block/mmcblk0p20 > /sys/devices/virtual/android_usb/android0/f_mass_storage/lun0/file
echo 0 > /sys/devices/virtual/android_usb/android0/enable 
echo "mass_storage,adb" > /sys/devices/virtual/android_usb/android0/functions 
echo 1 > /sys/devices/virtual/android_usb/android0/enable


---------- Post added at 05:10 AM ---------- Previous post was at 05:08 AM ----------

wondering how we could mount many partition at the same time
will see

Edit : seems to be related to the module that provide mass storage gadget, it's set to 1 emulation for the moment... i think i have to recompile that stuff and/or the kernel to have this feature... any way not for now ^^

Note : an alternative to check deleted files is R-Studio work well
Last edited by intika; 15th March 2015 at 05:20 AM.
17th April 2015, 05:56 AM |#6  
at41man's Avatar
Member
Flag Jakarta
Thanks Meter: 17
 
More
Question Some Hint Please?
Quote:
Originally Posted by CleverCoder

CleverCoder's Guide to Mounting Android’s Internal Storage As A Mass Storage USB Device

I found inspiration from this guide: http://mohammadag.xceleo.org/mountin...ernal-storage/
His process did not work exactly, but by changing the “lun” to “lun0” and the path to the “android_usb” device, I was able to get this to work with my rooted Samsung Note 10.1. The instructions below were verified on my Note 2.

I was motivated to find this solution after I accidentally deleted my daughters world that she worked so hard to create in Survivalcraft. Ultimately, I wasn’t able to recover her world, but I learned a lot in the process. Enjoy!

Steps:

  1. Boot into recovery mode (Usually holding volume (and home) down while powering up). I find the Wiki on CyanogenMod to be helpful to find device-specific bootloader instructions.
  2. Invoke a root shell using ADB: “adb shell" (Note: This assumes you have the Android SDK installed and /platform-tools are in your PATH)
  3. Find the /data partition, determine the block device that corresponds to it:

    Code:
    mount | grep /data
  4. Make a note of the block device name. In my case, it's "/dev/block/mmcblk0p16". Unmount the /data partition to allow mounting as a mass storage device:
    Code:
    umount /data
  5. Locate the “mass storage” device LUN entry. (In my case, it was ..\lun0 rather than ..\lun):
    Code:
    find /sys -name lun*
    In this case, we want to make a note of the entry with "f_mass_storage" in it. This is the entry that corresponds to a USB Mass Storage device.
  6. Map the block device to the mass storage logical device LUN “file”. Note, this will be a file called “file” within the LUN folder. For example:
    "/sys/devices/virtual/android_usb/android0/f_mass_storage/lun/file":
    ~# echo BLOCK_DEVICE_HERE > LUN_FILE_PATH_HERE
    For example:
    Code:
    echo /dev/block/mmcblk0p16 > /sys/devices/virtual/android_usb/android0/f_mass_storage/lun0/file
    Note: the ADB shell appears to wrap at around 80 characters, making it look like the line is split.
  7. Reconfigure the USB device in “mass storage” mode. This has to be done in one command, since it will terminate the ADB connection. Also, the path varies to the “android_usb” device. It may be:
    /sys/devices/virtual/android_usb/android0/
    /sys/class/android_usb/android0/
    You can use "find /sys -name *android0*" to help narrow the options. I believe either entry will work. YMMV

    On my Note 2 the following worked:
    Code:
    echo "echo 0 > /sys/devices/virtual/android_usb/android0/enable && echo \"mass_storage,adb\" > /sys/devices/virtual/android_usb/android0/functions && echo 1 > /sys/devices/virtual/android_usb/android0/enable" > enable_mass.sh
    sh enable_mass.sh &
    This should terminate the ADB connection and cause a new USB device to appear, representing the /data volume mounted as a mass storage device.

At this time, the block device associated with the /data partition should show up as a USB mass storage device on your computer. I verified this with OSX. OSX did not support the ext3/4 filesystem, however, Unix utilities that support it will work.

Recovering Files

Once the device is mounted on your host machine, you can use PhotoRec (http://www.cgsecurity.org/wiki/PhotoRec) to recover files. It performs a file signature based recovery, is very powerful, and works with any file you can think of. It’s also easy to add support for your own file types.

I hope this helps others.
Cheers!
- Sean

Hello sir, I want to ask you.

What recovery version do you use? Philz Touch? TWRP or another? can you please help me.? I am using Galaxy Note II device (GT-N7100)
When I am using TWRP recovery I can do all steps you provide but no luck. Then I am try using Philz Touch, adb shell is error, Device Not Found.

What can I do? Can you please help me?
I need to recover some photos that I accidentally deleted.
10th May 2015, 01:49 PM |#7  
Junior Member
Thanks Meter: 1
 
More
Question
Hi Sean,

This is a great idea!!! I've been struggling for the past two weeks to recover data from my HTC One M7 ever since I accidentally hit the factory reset button!

I got a few questions...
Does this method work on my M7 which has only the internal memory and no SD card?
IIf I'm trying this directly on a terminal window on he phone, how would the last command change?
Also, once done, how do we mount /data back?

Sorry for the noob questions!

Thanks a lot!
Last edited by billqu; 10th May 2015 at 02:13 PM. Reason: Adding info
12th May 2015, 03:00 PM |#8  
Junior Member
Thanks Meter: 1
 
More
Question No response from HTC One M7
Hello Experts,

I tried the above mentioned method on my HTC One M7. It was lun0 in my case. I have unmounted /data. However, I still found that mmcblkp037 that was mounted on /data was still linked to /sdcard for some reason. I proceeded to unmount /sdcard too. (There is no SD card in my device btw).

After unmounting both /data and /sdcard, I proceeded to edit the lun0/file and then the long command all in one go. Unfortunately nothing happens, the adb shell remains active and I do not see a USB device appearing on My Computer. I've added the snapshots from the terminal window.

Can someone please help?

Thanks!!!
Attached Thumbnails
Click image for larger version

Name:	Capture1.JPG
Views:	54
Size:	74.0 KB
ID:	3309172   Click image for larger version

Name:	Capture2.JPG
Views:	48
Size:	65.9 KB
ID:	3309173  
Last edited by billqu; 12th May 2015 at 03:21 PM. Reason: Add pics...
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes