56

I have a smartphone without the possibility to insert an SD-card. I would like to make a dump of the biggest partition (cause I lost files and I'd like to use a dump to recover them).

The partition is 10GB.

I was looking for an ADB command to pull using dd but nothing...

I tried to use Carliv touch recovery with a 32GB USB key by OTG but the USB key didn't mount ... Then I couldn't use dd directly on the phone using Aroma file manager and a terminal emulation.

Thank you!

I don't understand why they closed a question that has already an accepted answer by linking a completely different question. Copying a file and copying a partition are 2 different things.

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
Alexis
  • 2,136
  • 2
  • 19
  • 47
  • 9
    no need for `dd`. make sure that `adbd` is running as root and then just `adb pull` the block device file for your partition. – Alex P. Apr 04 '15 at 16:30
  • 6
    Wow, Thank you very much ! For those who look for : `adb pull /dev/block/mmcblk0 mmcblk0.img` – Alexis Apr 05 '15 at 13:25
  • 1
    `/dev/block/mmcblk0` is a device file for the whole storage device. You probably wanted to pull just a single partition. Run `mount` command to find the device file for the partition you're looking to dump which would look something like `/dev/block/bootdevice/by-name/userdata` and `adb pull` that – Alex P. Apr 06 '15 at 18:41
  • please post the answer and mark it accordingly. It is possible to make a DD image, however not as easy. I missed the answer in this comment section because it's not marked. – user2305193 Dec 30 '16 at 15:53
  • 4
    I wrote the solution in comments. Thank you for your reply, don't know who down vote through... – Alexis Jan 02 '17 at 07:13

3 Answers3

54

As said in comment, adb pull /dev/block/mmcblk0 mmcblk0.img worked for me. A "DD image" is only a binary image file of the device.

Alexis
  • 2,136
  • 2
  • 19
  • 47
  • 1
    Nice and simple. Although it gave me a "Permission denied" error, even with root and adbd Insecure, running the command in recovery mode (using TWRP) allowed the partition to be transferred without a hitch. – idmadj Feb 13 '17 at 03:49
  • 2
    yes of course, the partition has to be `unmounted` then only in `recovery mode`. – Alexis Feb 16 '17 at 00:51
  • @Alexis_FR_JP, I created a "dd image" as you mentioned, but when I had to use this to restore everything, my phone didn't want to boot up... Something went wrong with the "system" partition because when I re-flashed it, everything worked again... I started my phone in recovery mode (TWRP). In other hands, the transfer size when I backed up the data and when I restored was same and equaled than the physical size. So I have no idea why was not worked the restore... – andras.tim Sep 16 '18 at 12:33
  • I guess this way doesn't work anymore to restore a phone. I don't know exactly the reason. I guess due to more complicated boot path and some other security features and/or encrypted partition. Usually there is a proper way for each smartphone. – Alexis Sep 16 '18 at 22:10
  • 2
    ADB throws: 'remote object '/dev/block/mmcblk0' does not exist' – Nikita G. Aug 15 '20 at 09:49
  • 1
    Well, the name of the device may change. You need to check which block device corresponds to the memory. – Alexis Aug 15 '20 at 11:33
  • This method worked for me. I "pushed" the image on another device. The system booted fine, but all the data was gone. I guess this is because it was encrypted, and the encryption keys are device specific somehow. I didn't try a push on the same device. – ocroquette Jan 24 '21 at 14:37
22

You want to copy a disk from your android device to your computer (preferably on your fastest drive) for faster and lossless analysis/recovery.

This is short step-by-step guide in windows (linux: scroll down) to achieve it using the linux tool dd intended for precise, bit-wise copies of data. Credits go to scandium on xda for the code, see his post for more details.

Prerequisites

Windows:

  1. install cygwin. During install, add netcat (under Net) and pv (under util-linux) packages; the standard install is located in C:\ so make sure you have enough disk space beforehand;

  2. install adb e.g. through Android Studio. Make sure to add adb.exe executable file to the path variable to access it properly (guide).

  3. Open two cygwin consoles/terminals (one sending data, one receiving data) and enter in one of the terminals to enter the device:

    # terminal 1
    adb forward tcp:5555 tcp:5555   # forward data over tcp connection
    adb shell                       # open a connection
    su                              # gain root access
    BUSYBOX=/system/xbin/busybox    # default location for most bb installers
    
    # note: adapt the variable `BUSYBOX` to point to your install directory
    #       the TWRP default is `BUSYBOX=/sbin/busybox` (in case of bricked device)
  1. Decide what partition to copy, the /dev/block/mmcblk0 partition is usually the one containing the data you typically would want.

  2. In the following code, adapt the partition name according to 4. and quickly one after another type in terminal 1 and terminal 2:

    # terminal 1
    $BUSYBOX nc -l -p 5555 -e $BUSYBOX dd if=/dev/block/mmcblk0
    # terminal 2
    nc 127.0.0.1 5555 | pv -i 0.5 > $HOME/mmcblk0.raw    

This saves the partition in the cygwin home directory (in a nutshell: it sends/receives output of dd over a tcp connection)

Look at the files / analysis

  • To mount the partition in Windows you can use (OSFmount).

  • To analyze the files I recommend Active@ Undelete but there are tons of alternatives. With that program you can also directly load all partitions from the file (without mounting it, so step 5 is redundant in this case).

Guide for GNU/Linux users: install netcat and pv (step 1), use the Disks utility to analyze

EM0
  • 5,369
  • 7
  • 51
  • 85
user2305193
  • 2,079
  • 18
  • 39
  • 1
    Depending on ADB toolkit version *adb shell* command may not work. Especially when copying to Windows OS (adding extra CR to LF, etc.) The right command in such cases would be: *adb exec-out 'dd if=/dev/block...* In contrast to shell, exec-out deals binary data much better. – hypers Mar 15 '20 at 20:46
  • thanks! please feel free to edit and improve the answer =) I've never used exec-out – user2305193 Mar 16 '20 at 16:29
  • Thanks for the tip about the Disks utility. I was able to mount the `system` partition image with it, but `userdata` gives an error: **cannot mount /dev/loop0 read-only (udisks-error-quark, 0)** From a web search, "udisks-error-quark, 0" seems to be a generic error shown for all sorts of different problems. – EM0 Jan 14 '23 at 21:05
12

Run as root:

adb root

Use dd to output content into stdout and write file on your computer:

adb shell 'dd if=/dev/block/platform/msm_sdcc.1/by-name/XXXXXX 2>/dev/null' > XXXXXX.img

Or all (see cat /proc/partitions)

adb shell 'dd if=/dev/block/mmcblk0 2>/dev/null' > mmcblk0.img
Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
Nikola
  • 137
  • 1
  • 4
  • 11
    Please explain these command lines – LaurentY Oct 28 '16 at 12:29
  • This perfectly answered my question that requires the use of `dd`. But I haven't tried. – Alexis Jun 02 '19 at 02:21
  • Depending on ADB toolkit version *adb shell* command may not work. Especially when copying to Windows OS (adding extra CR to LF, etc.) The right command in such cases would be: *adb exec-out 'dd if=/dev/block...* In contrast to shell, exec-out deals binary data much better. – hypers Mar 15 '20 at 20:45
  • Use double quotation instead (single quotation gives "The system cannot find the path specified."), I've tested on win10. – SAMPro Apr 26 '20 at 11:29
  • I was getting `adbd cannot run as root in production builds` when trying to run `adb root`. Instead, I was able to switch to root as part of the shell command: `adb shell "su -c 'dd if=/dev/block/mmcblk0'"` (per this answer: https://forum.xda-developers.com/t/resolve-adbd-cannot-run-as-root-in-production-builds.4560483/#post-88274507) – ropeladder May 27 '23 at 14:42