I am trying to make a backup (a direct dd image of the partitions of my built-in memory card of my phone to my PC. I am using Linux and my phone is a Nexus 4.
-
If you want to post a solution to a problem, which isn't easy to find, you are very welcome, but, please post it in answer and not in question body and then accept the answer to indicate right solution to others. Its not easy to understand if the question itself contains the answer body. Thank you... – DroidDev Nov 17 '14 at 07:54
-
`partitions of my sdcard of my phone`. `my phone is a Nexus 4`. Since when does a Nexus 4 have a sd card? – greenapps Nov 17 '14 at 09:09
-
That is how the system call it to the built-in memory card.I would like to know other answers too because I am not convinced that my answer is the best. – hongo Nov 17 '14 at 16:48
4 Answers
Don't install TWRP
Instead:
Install
android-platform-tools
orandroid-sdk
onto your computer.Download TWRP to your computer.
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.
Boot TWRP by running
fastboot boot twrp-3.1.0.0.img
. (No need to flash your recovery partition this way.)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.Let's say your
/data
partition maps to/dev/mmcblk0p28
. Just runadb 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.

- 1,559
- 13
- 22
-
At step 5 I get: Downloading 'boot.img' OK [0.332s] booting FAILED (remote: oem unlock is false) – jcomeau_ictx Oct 13 '20 at 00:51
-
1
-
No, I didn't want to wipe the data. So I guess I'm out of luck with that method. – jcomeau_ictx Oct 23 '20 at 18:08
-
-
Here another better answer:
Requirements: adb must be already installed
- Download insecure boot.img to your PC from https://www.androidfilehost.com/?fid=9390169635556426389
- Reboot your phone into fastboot mode by powering it off and then pressing and holding volume-down and power buttons.
From your Linux PC in the folder where boot.img is located type:
$ fastboot boot boot.img
To copy the image of the mmcblk0 partition type:
$ adb pull /dev/block/mmcblk0 mmcblk0.img

- 687
- 1
- 6
- 10
-
you can use TWRP recovery instead of boot.img. boot to TWRP recovery, figure the device name for /data, unmount it in TWRP interface and use adb pull – Alec Istomin Aug 21 '18 at 06:20
-
Edit: Hongo's answer has fewer steps.
Install TWRP.
Choose your device on the TWRP page and follow the installation instructions there.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 tryfastboot reboot-bootloader
, then selectRecovery
.Mount partitions in TWRP
You should now be in TWRP. From there, choose Mount. Make sure yourdata
partition in mounted. Make sure yoursystem
partition is mounted, as you'll need some executables that reside there.Connect
Installadb
adb
if you haven't already. Connect your phone to your computer by USB cable. Typeadb devices
. If you see a device listed, then you're connected.Forward a port
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.adb forward tcp:33333 tcp:33333
Locate the partition you want to backup
Locate the partition that you want to backup and get the device name. [EDIT: if the partition that you need to backup looks likeadb shell mount
/dev/block/dm-0
, it's part of a logical volume (LVM) and this is probably not the right way to back it up]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 tostdout
, which is piped into gzip to compress it, then piped into netcat, which is listening (-l
) on port 33333 (-p 33333
).
- This
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 tostdout
, pipes that topv
, 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 nameddm-0.raw.gz
- Replace
- From a new terminal, do

- 10,764
- 2
- 38
- 66
-
What to do if you want to export *everything*, not just one partition? – user2305193 Dec 30 '16 at 02:26
-
@user2305193 Well, you could do that, but then you'll need to find a way to restore it. You can essentially reverse these instructions to restore a partition. – Codebling Dec 30 '16 at 02:35
-
@user2305193 You can essentially replace `dd` in `dd if=/dev/block/dm-0 bs=64k | gzip | nc -l -p 33333` from the instructions above with an [`rsync`](https://linux.die.net/man/1/rsync) command. That would probably do the trick. And if the partitions are still mounted the same way when you try to restore it, then `rsync`ing the other way should work. – Codebling Dec 30 '16 at 02:37
-
The idea was to get all of the partitions sequentially, as in seperate files, with one command so you don't have to cycle through the commands manually if you're unsure of the partition (or you've overwritten the one you're interested in) – user2305193 Dec 30 '16 at 02:51
-
moved [to chat](http://chat.stackoverflow.com/rooms/131856/android-commandline-partition-backup). @user2305193 – Codebling Dec 30 '16 at 04:21
-
TWRP from 2018 might support adb for your phone, then its as easy as running adb pull - see another answer below – Alec Istomin Aug 21 '18 at 06:21
-
@AlecIstomin TWRP must support adb for the procedure listed in my answer, as well. The question is about making a raw (i.e. dd from the block device) backup of the phone. `adb pull` cannot do this. – Codebling Sep 07 '18 at 00:52
-
1@CodeBling adb pull from TWRP can do this, i assure you. unmount /data in twrp interface and pull device as a regular file – Alec Istomin Sep 07 '18 at 06:04
-
@AlecIstomin I upvoted your comment at the time but never explicitly said "cool, that's awesome", thanks for showing me that! – Codebling Mar 26 '20 at 03:21
Requirements: adb must be already installed
- Download insecure boot.img to your PC from https://www.androidfilehost.com/?fid=9390169635556426389
- Reboot your phone into fastboot mode by powering it off and then pressing and holding volume-down and power buttons.
From your Linux PC in the folder where boot.img is located type:
$ fastboot boot boot.img
To make an image of the mmcblk0p23 partition type:
$ adb shell 'stty raw && dd if=/dev/block/mmcblk0p23' > ~/userdata.img
Useful Links:
How to you identify the partition of interest: http://forum.xda-developers.com/showthread.php?t=2450045
If stty raw is not used all LF will be translated to CRLF: android.stackexchange.com/questions/69434/is-it-possible-to-cat-a-file-to-an-android-phone-and-dd-to-dev-xxx-on-the-fly-w
How to root phone and use insecure boot.img: www.addictivetips.com/android/root-google-nexus-4-install-clockworkmod-recovery/
Transferring binary data over ADB shell (how to use stty raw): stackoverflow.com/questions/11689511/transferring-binary-data-over-adb-shell-ie-fast-file-transfer-using-tar

- 687
- 1
- 6
- 10
-
The image will be encrypted if the data is not decrypted first. The only way I got decrypted data was via TWRP. – martinszy Jul 11 '22 at 15:34