how to make an image of android partition to your pc

Edit: Hongo's answer has fewer steps.

  1. Install TWRP.

    Choose your device on the TWRP page and follow the installation instructions there.
  2. Boot into Recovery

    You may have to find the key combination specific to your device in order to react the bootloader menu. If you flashed TWRP using fastboot (fastboot flash recovery twrp.img), then you can try fastboot reboot-bootloader, then select Recovery.
  3. Mount partitions in TWRP

    You should now be in TWRP. From there, choose Mount. Make sure your data partition in mounted. Make sure your system partition is mounted, as you'll need some executables that reside there.
  4. Connect adb

    Install adb if you haven't already. Connect your phone to your computer by USB cable. Type adb devices. If you see a device listed, then you're connected.
  5. Forward a port adb forward tcp:33333 tcp:33333

    We need to enable TCP access to your phone. This command listens on the computer's port 33333 (the first argument) and forwards all connections to port 33333 on your phone. You can pick any port. Ports lower than 1024 on the PC require root access. Make sure the port you pick isn't already being used. The two numbers don't need to match.
  6. Locate the partition you want to backup adb shell mount

    Locate the partition that you want to backup and get the device name. [EDIT: if the partition that you need to backup looks like /dev/block/dm-0, it's part of a logical volume (LVM) and this is probably not the right way to back it up]
  7. Forward the raw partition from your phone

    • adb shell
    • Try dd if=/dev/block/dm-0 bs=64k | gzip | nc -l -p 33333
      • This /dev/block/dm-0 with the the device that you found from the mount command, earlier.
      • Replace 33333 with the phone port that you picked above
      • If any commands can't be found, you can try to prepend them with /system/bin/toybox or /system/bin/busybox.
      • This command block copies from the specified device (if=) and, using a block size of 64k (bs=64k - you can specify any, or omit this argument entirely, but small values will likely slow the process down. Values larger than 64k will generally not speed the process up), dumps this to stdout, which is piped into gzip to compress it, then piped into netcat, which is listening (-l) on port 33333 (-p 33333).
  8. Dump the data on your computer

    • From a new terminal, do nc localhost 33333 | pv -i 0.5 --size 54g > dm-0.raw.gz
      • Replace 33333 with the computer port that you picked above
      • Replace dm-0.raw.gz with any file name
      • Replace 54g with the size of your partition (see below)
      • This command connects to port 33333 on the localhost (your computer) and dumps to stdout, pipes that to pv, which updates the transfer progress every half second (-i 0.5) with an estimated size of 54 gigs (--size 54g - you can omit this argument but it's necessary for the transfer progress to be accurate), then into a file named dm-0.raw.gz

Here another better answer:

Requirements: adb must be already installed

  1. Download insecure boot.img to your PC from https://www.androidfilehost.com/?fid=9390169635556426389
  2. Reboot your phone into fastboot mode by powering it off and then pressing and holding volume-down and power buttons.
  3. From your Linux PC in the folder where boot.img is located type:

    $ fastboot boot boot.img
    
  4. To copy the image of the mmcblk0 partition type:

    $ adb pull /dev/block/mmcblk0 mmcblk0.img
    

Don't install TWRP

Instead:

  1. Install android-platform-tools or android-sdk onto your computer.

  2. Download TWRP to your computer.

  3. Hold the volume down and volume up buttons and turn on your phone to start up the bootloader screen. Make sure your phone is plugged into your computer's USB port.

  4. Boot TWRP by running fastboot boot twrp-3.1.0.0.img. (No need to flash your recovery partition this way.)

  5. In TWRP, select Advanced, then Terminal, which will open a shell. Type mount and press [ENTER] to see the partitions. You're looking for the /data and possibly /sdcard mounts.

  6. Let's say your /data partition maps to /dev/mmcblk0p28. Just run adb pull /dev/block/mmcblk0p28 data.img on your computer and it will copy the partition. Expect this process to take a while since it is copying the entire partition, regardless of how many files are stored in it.