[Q] Backup/Restore partitions using dd command under ClockWorkMod?

Search This thread

dnlilas

Senior Member
Dec 27, 2010
416
74
Hello,

Is is possible to use dd command available under busybox when in recovery mode
to backup partitions?

Examples:
Backup data partition:
dd if=/dev/block/mmcblk0p26 of=/sdcard/data.img

Restore data partition:
dd if=/sdcard/data.img of=/dev/block/mmcblk0p26

If yes, then what the needed mount commands to make the above work.

The reason is that I have a problem with nandroid restore:
http://xdaforums.com/showpost.php?p=14714800&postcount=319

Note: similar command apparently works for flashing recovery
image (which is partition /dev/block/mmcblk0p21).
 

dnlilas

Senior Member
Dec 27, 2010
416
74
Without appropriate answer, I have to try for myself, and finally get the answer to my own question.
The answer is YES, dd command could be used to backup/restore the entire system (so can replace
nandroid part of ClockWorkMod).

You need to know the mapping of the partitions for the Desire HD:
Code:
/dev/block/mmcblk0p21  recovery
/dev/block/mmcblk0p22  boot
/dev/block/mmcblk0p25  system
/dev/block/mmcblk0p26  data
/dev/block/mmcblk0p27  cache

The partitions backupped will result in same size each time, with same backup/restore time
since it is a "raw" backup (bit-to-bit copy, or sector-by-sector copy in hard disk terminology).
I use the .dsk for file extension to avoid confusion with .img extension used by CWM (since they
are not the same format, and cannot be used in fastboot command for example).

Backup sample log:
Code:
ls -l /sdcard/MyBackups/recovery/recovery*.dsk
-rwxrwxrwx    1 root     root       8909824 Jun 16 10:17 /sdcard/MyBackups/recovery/recovery_3.0.2.8.dsk
2011-06-17-02:26:24 Backup boot...
512+0 records in
512+0 records out
4194304 bytes (4.0MB) copied, 0.208129 seconds, 19.2MB/s
-rwxrwxrwx    1 root     root       4194304 Jun 17 02:26 /sdcard/MyBackups/LeeDroid_Froyo/boot.dsk
2011-06-17-02:26:24 Backup system...
71423+1 records in
71423+1 records out
585104896 bytes (558.0MB) copied, 188.697998 seconds, 3.0MB/s
-rwxrwxrwx    1 root     root     585104896 Jun 17 02:29 /sdcard/MyBackups/LeeDroid_Froyo/system.dsk
2011-06-17-02:29:33 Backup data...
150399+1 records in
150399+1 records out
1232076288 bytes (1.1GB) copied, 370.469513 seconds, 3.2MB/s
-rwxrwxrwx    1 root     root     1232076288 Jun 17 02:35 /sdcard/MyBackups/LeeDroid_Froyo/data.dsk
2011-06-17-02:35:43 Backup cache...
38399+1 records in
38399+1 records out
314572288 bytes (300.0MB) copied, 97.289337 seconds, 3.1MB/s
-rwxrwxrwx    1 root     root     314572288 Jun 17 02:37 /sdcard/MyBackups/LeeDroid_Froyo/cache.dsk
2011-06-17-02:37:21 Done.

Restore sample code:
Code:
ls -l /sdcard/MyBackups/recovery/recovery*.dsk
-rwxrwxrwx    1 root     root       8909824 Jun 16 10:17 /sdcard/MyBackups/recovery/recovery_3.0.2.8.dsk
2011-06-17-15:28:33 Restore boot...
-rwxrwxrwx    1 root     root       4194304 Jun 17 14:58 /sdcard/MyBackups/LeeDroid_Froyo/boot.dsk
512+0 records in
512+0 records out
4194304 bytes (4.0MB) copied, 1.006897 seconds, 4.0MB/s
2011-06-17-15:28:34 Restore system...
-rwxrwxrwx    1 root     root     585104896 Jun 17 15:02 /sdcard/MyBackups/LeeDroid_Froyo/system.dsk
71423+1 records in
71423+1 records out
585104896 bytes (558.0MB) copied, 405.526398 seconds, 1.4MB/s
2011-06-17-15:35:20 Restore data...
-rwxrwxrwx    1 root     root     1232076288 Jun 17 15:08 /sdcard/MyBackups/LeeDroid_Froyo/data.dsk
150399+1 records in
150399+1 records out
1232076288 bytes (1.1GB) copied, 434.877655 seconds, 2.7MB/s
2011-06-17-15:42:34 Restore cache...
-rwxrwxrwx    1 root     root     314572288 Jun 17 15:09 /sdcard/MyBackups/LeeDroid_Froyo/cache.dsk
38399+1 records in
38399+1 records out
314568704 bytes (300.0MB) copied, 49.197021 seconds, 6.1MB/s
2011-06-17-15:43:24 Done.

Now with "dd" backup, I can now have the liberty to try other ROMs without my dreaded problem with CWM :).

Edit: let have a dream. How about using dd binary like nandroid currently invoked by CWM from it's menu?
CWM currently for backup or restore invoke the standalone nandroid binary with appropriate parameters, then it captures
(pipes) the output of e.g. tar utility to extract (restore) or compress (backup) the .img file.
With dd it would be simple to add to CWM menu to provide invocation of dd for a backup/restore using partition imaging method.
By doing this, no more need to plug an USB cable and use adb command.

Edit: Finally there is a simpler solution. Create an installation ZIP script (like the one used to flash ROM). Then in updater_script invoke a command (shell script, extension.sh) with the run_program(). You can provide parameters to this. You can have a zip to backup, a zip to restore etc...
 
Last edited:

DualJoe

Senior Member
Oct 12, 2011
2,194
1,095
de
Good idea. I've tried this on my U8510 (Android 2.3.3) but it doesn't work. This is my partition layout:
cat /proc/mtd
dev: size erasesize name
mtd0: 00500000 00020000 "boot"
mtd1: 00500000 00020000 "recovery"
mtd2: 00140000 00020000 "misc"
mtd3: 00060000 00020000 "splash"
mtd4: 0ba00000 00020000 "system"
mtd5: 03f00000 00020000 "cache"
mtd6: 0a0a0000 00020000 "userdata"
mtd7: 01400000 00020000 "userdata2"
mtd8: 01400000 00020000 "cust"
And this is "ls -l /dev/block":
brw------- 1 root root 7, 0 Oct 12 21:54 loop0
brw------- 1 root root 7, 1 Oct 12 21:54 loop1
brw------- 1 root root 7, 2 Oct 12 21:54 loop2
brw------- 1 root root 7, 3 Oct 12 21:54 loop3
brw------- 1 root root 7, 4 Oct 12 21:54 loop4
brw------- 1 root root 7, 5 Oct 12 21:54 loop5
brw------- 1 root root 7, 6 Oct 12 21:54 loop6
brw------- 1 root root 7, 7 Oct 12 21:54 loop7
brw------- 1 root root 179, 0 Oct 12 21:54 mmcblk0
brw------- 1 root root 179, 1 Oct 12 21:54 mmcblk0p1
brw------- 1 root root 31, 0 Oct 12 21:54 mtdblock0
brw------- 1 root root 31, 1 Oct 12 21:54 mtdblock1
brw------- 1 root root 31, 2 Oct 12 21:54 mtdblock2
brw------- 1 root root 31, 3 Oct 12 21:54 mtdblock3
brw------- 1 root root 31, 4 Oct 12 21:54 mtdblock4
brw------- 1 root root 31, 5 Oct 12 21:54 mtdblock5
brw------- 1 root root 31, 6 Oct 12 21:54 mtdblock6
brw------- 1 root root 31, 7 Oct 12 21:54 mtdblock7
brw------- 1 root root 31, 8 Oct 12 21:54 mtdblock8
drwxr-xr-x 3 root root 60 Oct 12 21:54 platform
brw------- 1 root root 1, 0 Oct 12 21:54 ram0
brw------- 1 root root 1, 1 Oct 12 21:54 ram1
brw------- 1 root root 1, 2 Oct 12 21:54 ram2
brw------- 1 root root 1, 3 Oct 12 21:54 ram3
brw------- 1 root root 1, 4 Oct 12 21:54 ram4
brw------- 1 root root 1, 5 Oct 12 21:54 ram5
brw------- 1 root root 1, 6 Oct 12 21:54 ram6
brw------- 1 root root 1, 7 Oct 12 21:54 ram7
'mmcblk0' is the sdcard.

When i enter 'dd if=/dev/block/mtdblock0 of=/sdcard/mtdblock0-boot.img' i get:
dd: /dev/block/mtdblock0: I/O error

CWM Recovery Backup gives me this files. I'm not sure if this are all files so i want to dump partitions manually.
.android_secure.img
boot.img
cache.img
data.img
nandroid.md5
recovery.img
system.img

Why is it not working?

Edit: When i enter 'dd if=/dev/block/mmcblk0 of=/sdcard/mmcblk0.img' dd does work but it copies the sdcard to itself. :)
Why are the other "blocks" not working and how can i get the working ones like your 'mmcblk0p21'?

Edit2: Got it. For the U8510 its 'dd if=/dev/mtd/mtd0 of=/sdcard/mtd0-boot.img bs=4096'.
 
Last edited:
Jan 26, 2014
9
0
busybox dd

Hello,

Is dd if=/dev/block/mmcblk0p26 of=/sdcard/data.imgis possible to use dd command available under busybox when in recovery mode
to backup partitions?

Examples:
Backup data partition:
dd if=/dev/block/mmcblk0p26 of=/sdcard/data.img

Restore data partition:
dd if=/sdcard/data.img of=/dev/block/mmcblk0p26

If yes, then what the needed mount commands to make the above work.

The reason is that I have a problem with nandroid restore:
http://xdaforums.com/showpost.php?p=14714800&postcount=319

Note: similar command apparently works for flashing recovery
image (which is partition /dev/block/mmcblk0p21).


Hi, I'm interested in using dd command to do a full backup but I don't know how to do.
Where I have to write the command "dd if=/dev/block/mmcblk0 of=/sdcard/data.img"?
In busybox?

Thanks in advance!
 

dnlilas

Senior Member
Dec 27, 2010
416
74
Hello,
You need to connect the phone to your PC with USB cable then reboot the phone in recovery. In your PC, start the adb.exe command, you should get a command prompt with root right (# instead of $). Then you can use commands in this prompt.
 
  • Like
Reactions: vittoriomazzoli
Jan 26, 2014
9
0
busybox dd without a pc

Hello,
You need to connect the phone to your PC with USB cable then reboot the phone in recovery. In your PC, start the adb.exe command, you should get a command prompt with root right (# instead of $). Then you can use commands in this prompt.

Thanks but I've read (http://xdaforums.com/showthread.php?t=1124939) that is possible to use the command "dd" within the smartphone obtaining a full backup in the sdcard.
I've to use a terminal emulator in android, after installing busybox, to launch the command "dd if=/dev/block/mmcblk0 of=/sdcard/data.img"?

Thanks in advance!
 

dnlilas

Senior Member
Dec 27, 2010
416
74
OK, so you will need a rooted phone, then in terminal emulator, change to root with su command to get the root # prompt.
But the difference is that you may take a backup of a live (running) system : this may work (as some live online nandroid backup), but of course the safest/surest is to take a backup when the system is shutdown, as in recovery.

Also, to restore, of course you are required to use the recovery, you cannot restore from inside Android with dd.
 
  • Like
Reactions: vittoriomazzoli
Jan 26, 2014
9
0
busybox dd from inside Android

OK, so you will need a rooted phone, then in terminal emulator, change to root with su command to get the root # prompt.
But the difference is that you may take a backup of a live (running) system : this may work (as some live online nandroid backup), but of course the safest/surest is to take a backup when the system is shutdown, as in recovery.

Also, to restore, of course you are required to use the recovery, you cannot restore from inside Android with dd.

Thanks very much, now I've understand! :victory: ;)
This guide (http://xdaforums.com/showthread.php?t=1818321) says how to do a full backup via pc with the command dd but I don't understand if the phone is in recovery mode!?

Can you tell me if the guide is ok for you? because it says something different from what you have said in your first replay .
 
Last edited:
Jan 26, 2014
9
0
Great app for full backup

To to backup the phone must be powered-on.
But I would suggest you to use this application that will do all the backup for you from inside your running/live Android :
https://play.google.com/store/apps/details?id=com.h3r3t1c.onnandbup

Thanks, great app for a complete backup of the phone!
Just to learn something new: to do a backup with pc and dd command, the phone must be in recovery mode and then connected to the pc?
It is ok for you the guide that I linked in the previous reply?

You said, in your first replay, to use adb.exe: can you explain the procedure (like a small guide) or link a guide (if you know one web page that speaks about it)?

Thanks again! ;)
 
Last edited:

dnlilas

Senior Member
Dec 27, 2010
416
74
From what I know :
adb.exe is part of the Android developer toolkit (ADK) that you can download. In fact for plain user (not Android developer), we only need the following 3 files that are usually available in many tools for customed ROM :
adb.exe
AdbWinApi.dll
AdbWinUsbApi.dll

You would better download the ADK so you will get the latest version. When you connect the phone either in recovery mode with an USB cable to the PC, the PC has (at least under Win7/Win8) automatically Android adb device driver installed, so it recognizes the phone correctly. By launching adb.exe, you will get to an adb command prompt where you can issue several commands like reboot, restart to recovery, flash the partition etc.... (communication is established between adb.exe in PC and the phone ) You can also issue the su command as far as I remember, then you the the "Linux"-like shell prompt. And dd, ls, du, cat commands of busybox etc... are then all available. You exit the shell by 'exit'.

Searching for adb, fastboot etc.. would help you.

Hope this helps,
 

gruimed

Member
Jan 4, 2017
8
0
has anybody actually tried to write the live system partition this way? has his phone survived?
 

masoomyf

Member
May 24, 2014
6
0
Is it correct to flash the data.img(user data image) by fastboot with this command:
fastboot flash userdata data.img
??
 

Top Liked Posts

  • There are no posts matching your filters.
  • 3
    Without appropriate answer, I have to try for myself, and finally get the answer to my own question.
    The answer is YES, dd command could be used to backup/restore the entire system (so can replace
    nandroid part of ClockWorkMod).

    You need to know the mapping of the partitions for the Desire HD:
    Code:
    /dev/block/mmcblk0p21  recovery
    /dev/block/mmcblk0p22  boot
    /dev/block/mmcblk0p25  system
    /dev/block/mmcblk0p26  data
    /dev/block/mmcblk0p27  cache

    The partitions backupped will result in same size each time, with same backup/restore time
    since it is a "raw" backup (bit-to-bit copy, or sector-by-sector copy in hard disk terminology).
    I use the .dsk for file extension to avoid confusion with .img extension used by CWM (since they
    are not the same format, and cannot be used in fastboot command for example).

    Backup sample log:
    Code:
    ls -l /sdcard/MyBackups/recovery/recovery*.dsk
    -rwxrwxrwx    1 root     root       8909824 Jun 16 10:17 /sdcard/MyBackups/recovery/recovery_3.0.2.8.dsk
    2011-06-17-02:26:24 Backup boot...
    512+0 records in
    512+0 records out
    4194304 bytes (4.0MB) copied, 0.208129 seconds, 19.2MB/s
    -rwxrwxrwx    1 root     root       4194304 Jun 17 02:26 /sdcard/MyBackups/LeeDroid_Froyo/boot.dsk
    2011-06-17-02:26:24 Backup system...
    71423+1 records in
    71423+1 records out
    585104896 bytes (558.0MB) copied, 188.697998 seconds, 3.0MB/s
    -rwxrwxrwx    1 root     root     585104896 Jun 17 02:29 /sdcard/MyBackups/LeeDroid_Froyo/system.dsk
    2011-06-17-02:29:33 Backup data...
    150399+1 records in
    150399+1 records out
    1232076288 bytes (1.1GB) copied, 370.469513 seconds, 3.2MB/s
    -rwxrwxrwx    1 root     root     1232076288 Jun 17 02:35 /sdcard/MyBackups/LeeDroid_Froyo/data.dsk
    2011-06-17-02:35:43 Backup cache...
    38399+1 records in
    38399+1 records out
    314572288 bytes (300.0MB) copied, 97.289337 seconds, 3.1MB/s
    -rwxrwxrwx    1 root     root     314572288 Jun 17 02:37 /sdcard/MyBackups/LeeDroid_Froyo/cache.dsk
    2011-06-17-02:37:21 Done.

    Restore sample code:
    Code:
    ls -l /sdcard/MyBackups/recovery/recovery*.dsk
    -rwxrwxrwx    1 root     root       8909824 Jun 16 10:17 /sdcard/MyBackups/recovery/recovery_3.0.2.8.dsk
    2011-06-17-15:28:33 Restore boot...
    -rwxrwxrwx    1 root     root       4194304 Jun 17 14:58 /sdcard/MyBackups/LeeDroid_Froyo/boot.dsk
    512+0 records in
    512+0 records out
    4194304 bytes (4.0MB) copied, 1.006897 seconds, 4.0MB/s
    2011-06-17-15:28:34 Restore system...
    -rwxrwxrwx    1 root     root     585104896 Jun 17 15:02 /sdcard/MyBackups/LeeDroid_Froyo/system.dsk
    71423+1 records in
    71423+1 records out
    585104896 bytes (558.0MB) copied, 405.526398 seconds, 1.4MB/s
    2011-06-17-15:35:20 Restore data...
    -rwxrwxrwx    1 root     root     1232076288 Jun 17 15:08 /sdcard/MyBackups/LeeDroid_Froyo/data.dsk
    150399+1 records in
    150399+1 records out
    1232076288 bytes (1.1GB) copied, 434.877655 seconds, 2.7MB/s
    2011-06-17-15:42:34 Restore cache...
    -rwxrwxrwx    1 root     root     314572288 Jun 17 15:09 /sdcard/MyBackups/LeeDroid_Froyo/cache.dsk
    38399+1 records in
    38399+1 records out
    314568704 bytes (300.0MB) copied, 49.197021 seconds, 6.1MB/s
    2011-06-17-15:43:24 Done.

    Now with "dd" backup, I can now have the liberty to try other ROMs without my dreaded problem with CWM :).

    Edit: let have a dream. How about using dd binary like nandroid currently invoked by CWM from it's menu?
    CWM currently for backup or restore invoke the standalone nandroid binary with appropriate parameters, then it captures
    (pipes) the output of e.g. tar utility to extract (restore) or compress (backup) the .img file.
    With dd it would be simple to add to CWM menu to provide invocation of dd for a backup/restore using partition imaging method.
    By doing this, no more need to plug an USB cable and use adb command.

    Edit: Finally there is a simpler solution. Create an installation ZIP script (like the one used to flash ROM). Then in updater_script invoke a command (shell script, extension.sh) with the run_program(). You can provide parameters to this. You can have a zip to backup, a zip to restore etc...
    2
    Hello,

    Is is possible to use dd command available under busybox when in recovery mode
    to backup partitions?

    Examples:
    Backup data partition:
    dd if=/dev/block/mmcblk0p26 of=/sdcard/data.img

    Restore data partition:
    dd if=/sdcard/data.img of=/dev/block/mmcblk0p26

    If yes, then what the needed mount commands to make the above work.

    The reason is that I have a problem with nandroid restore:
    http://xdaforums.com/showpost.php?p=14714800&postcount=319

    Note: similar command apparently works for flashing recovery
    image (which is partition /dev/block/mmcblk0p21).
    1
    Hello,
    You need to connect the phone to your PC with USB cable then reboot the phone in recovery. In your PC, start the adb.exe command, you should get a command prompt with root right (# instead of $). Then you can use commands in this prompt.
    1
    OK, so you will need a rooted phone, then in terminal emulator, change to root with su command to get the root # prompt.
    But the difference is that you may take a backup of a live (running) system : this may work (as some live online nandroid backup), but of course the safest/surest is to take a backup when the system is shutdown, as in recovery.

    Also, to restore, of course you are required to use the recovery, you cannot restore from inside Android with dd.
    1
    To to backup the phone must be powered-on.
    But I would suggest you to use this application that will do all the backup for you from inside your running/live Android :
    https://play.google.com/store/apps/details?id=com.h3r3t1c.onnandbup