3

I have a rooted phone and i need to do some change to buid.prop. And if i got my phone bricked i need to recover it back. The thing is There's no CWM or TWRP roms available to my tablet(ZTE E7P(3G) running Kitkat 4.4.2).

Is there any way i can take a snapshot(Nandroid backup) of my currently running OS and restore it back if anything happen using default recovery mode(May be with ADB).

Simply what i want is to perform a Nandroid backup of my rooted tab and restore it without using custom recoveries like CWM or TWRP.

HarshaXsoad
  • 139
  • 1
  • 3

3 Answers3

3

Provided your device is rooted, you can do that with simple dd commands. Trouble is just to find out what partitions you might need to backup: some devices have more than 20 partitions, and you will most likely not need more than 5 backed up.

This is where e.g. my little tool Adebar comes in which, amongst others, creates you a script for exactly this purpose: dd the relevant partitions and get them to your computer, giving the files recognizable names. The result for my LG P880 e.g. looks like:

adb shell "su -c 'stty raw; cat /dev/block/mmcblk0p3'" > "images/system.img"
adb shell "su -c 'stty raw; cat /dev/block/mmcblk0p4'" > "images/cache.img"
adb shell "su -c 'stty raw; cat /dev/block/mmcblk0p12'" > "images/cal.img"
adb shell "su -c 'stty raw; cat /dev/block/mmcblk0p9'" > "images/persist-lg.img"
adb shell "su -c 'stty raw; cat /dev/block/mmcblk0p11'" > "images/FOT.img"
adb shell "su -c 'stty raw; cat /dev/block/mmcblk0p2'" > "images/LNX.img"
adb shell "su -c 'stty raw; cat /dev/block/mmcblk0p10'" > "images/mpt.img"
adb shell "su -c 'stty raw; cat /dev/block/mmcblk0p5'" > "images/MSC.img"
adb shell "su -c 'stty raw; cat /dev/block/mmcblk0p7'" > "images/NVA.img"
adb shell "su -c 'stty raw; cat /dev/block/mmcblk0p1'" > "images/SOS.img"
adb shell "su -c 'stty raw; cat /dev/block/mmcblk0p8'" > "images/data.img"
adb shell "su -c 'stty raw; cat /dev/block/mmcblk0p13'" > "images/UDB.img"
adb shell "su -c 'stty raw; cat /dev/block/mmcblk0p6'" > "images/USP.img"

As you can see, this does not only include partitions mounted at the time the script was generated, but also all other "named ones".

Adebar is plain Bash + ADB, and reportedly works in Cygwin (as well as of course on Linux).

Izzy
  • 91,166
  • 73
  • 343
  • 943
  • pretty much ignorant of these things. Is it possible to identify blocks , meaning the ones you need to take back up using Windows only ? Also the next step how to restore is equally important and you may consider adding – beeshyams Feb 28 '16 at 12:17
  • 1
    a partition backup always backs up the entire partition, that's how it is supposed to work (that's also what my quoted script does, though it doesn't use dd). And I rather don't give ideas on how to restore those (hint: just reverse source and target, but don't do that with the system booted – i.e. the corresponding partition being used), can be tricky ;) – Izzy Feb 28 '16 at 12:34
  • This might be a noob question. if i backup "mmcblk0" using above shell command does that mean i have all the sub-subsequent partitions like mmcblk0p1, mmcblk0p2..... inside it or do i have to call script separate on each one(of course your tool will do it automatically, but i'm asking theoretical does mmcblk0 contains all the partition data) . – HarshaXsoad Feb 28 '16 at 13:25
  • @HarshaXsoad mmcblk0 would be the entire "drive" with all the partitions (you could inspect that probably with e.g. TestDisk). However, it's unlikely you want to restore it this way (basically, as soon as your device is booted at least one of the partitions will be in use), so it's better to capture the partitions separately. – Izzy Feb 28 '16 at 13:47
  • What do you mean by "device is booted", to OS or to recover mode/powered on. Can i restore the entire drive(mmcblk0) on recover mode with adb because i guess non of the partitions are mounted and won't be in use on that mode. Am i correct ? – HarshaXsoad Feb 29 '16 at 02:08
  • @HarshaXsoad No. /recovery will be mounted then (mmcblk0p1 in the above example). When booted to OS, you can't because of /data (mmcblk0p8). You theoretically cound from fastboot, where nothing is mounted – but fastboot only deals with partitions, not with entire drives (plus you'd have no console there to do it)- – Izzy Feb 29 '16 at 06:45
  • Is stty raw necessary? – Melab Aug 23 '19 at 21:26
  • @Melab yes. Compare that to the BIN command of FTP. Without that, you mess up the data. Alternatively, you can use adb exec-out instead of adb shell and then would not need the stty raw. – Izzy Aug 24 '19 at 08:55
  • @Izzy I thought it can now handle piping. Is that incorrect? – Melab Aug 24 '19 at 11:22
  • @Izzy That gives me su not found. I've booted into TWRP temporarily and it does not provide such a command. Is there any alternative? – Melab Aug 24 '19 at 11:37
  • In TWRP you can skip the su -c as you are root there by default. So just adb exec-out "cat /dev/block/mmcblk0p3" > "images/system.img" should work. – Izzy Aug 24 '19 at 13:34
  • @Izzy I used adb shell dd if=/dev/block/by-name/userdata > userdata.img. I should expect userdata.img to be messed up? – Melab Aug 26 '19 at 23:44
  • Try mounting it as loop device and see for yourself. Yes, I'd expect it to fail as you used shell instead of exec-out – and shell does a bunch of terminal conversions. – Izzy Aug 27 '19 at 06:13
2

Yes, with ADB, this is possible. However, there are also some unofficial images on TWRP and CWM, which may be unofficially ported to your device. If not, you can follow ADB instructions below.

NOTE: Do it at your own risk.

This is the compilation of some of my research on this specifically, so proceed at your own risk until I test it myself.


Prerequisites

You will need busybox installed on your android, ADB on PC, OS X/Linux native tools or Cygwin for Windows, USB debugging.


Once you are sure that everything is working on your phone, then you have a choice between backing the entire phone up, or partitions by name. To view partitions by name, type this in your adb shell or phone terminal:

ls /dev/block/platform/dw_mmc*/by-name

You should get a long list of names like USERDATA or SYSTEM. These are familiar when doing a nandroid on TWRP or CWM.


Backing up entire phone

I would recommend this one more because I had experience with restoring System and Data partitions from TWRP, but all of my photos disappeared.

Type in cygwin window

adb forward tcp:5555 tcp:5555
adb shell
su
/system/xbin/busybox nc -l -p 5555 -e /system/xbin/busybox dd if=/dev/block/mmcblk0

And in a new cygwin window

adb forward tcp:5555 tcp:5555
cd /path/to/store/the/backup
nc 127.0.0.1 5555 | pv -i 0.5 > mmcblk0.raw

This will netcat transfer the raw mmcblk0 to your computer.


Backing up by name

Backing up by name, you would do the same as with the whole phone, just replacing /dev/block/mmcblk0 in the dd command, with /dev/block/platfrom/dw_mmc*/by-name/USERDATA, replacing USERDATA with whatever partition you want.

John K
  • 479
  • 5
  • 23
  • When recovering (assume that i have bricked my phone) in which mode i can/supposed to restore above image with ADB(Since i can't load into OS). – HarshaXsoad Feb 28 '16 at 09:31
  • I think that the stock recovery supports ADB too. Check on your device first – John K Feb 28 '16 at 09:44
  • Ok, but I will test this method that I wrote down, because I don't want it to end up being incorrect. I am in fact testing the backup made this way now – John K Feb 28 '16 at 09:46
  • 1
    An easy way to find out what partitions to take (and which partition contains what) is using my little tool Adebar, which (amongst others) creates you a script for exactly this purpose: dd the partitions and get them to your computer. – Izzy Feb 28 '16 at 10:45
  • by dong "nc 127.0.0.1 5555 | pv -i 0.5 > mmcblk0.raw" i get something like this "0 B 0:00:00 [ 0 B/s] [<=>" (actual a progress bar) and creates an empty mmcblk0.raw file. what should i do. – HarshaXsoad Feb 28 '16 at 10:55
  • Yes, I got the same result when attempting on testing it. I will try fixing somehow – John K Feb 28 '16 at 10:57
  • If this helps by typing "cat /proc/emmc " in shell i got followings partno: start_sect nr_sects partition_name emmc_p1: 00000400 00000002 "ebr1" emmc_p2: 00004800 00005000 "protect_f" emmc_p3: 00009800 00005000 "protect_s" emmc_p4: 00014c00 00003000 "sec_ro" emmc_p5: 0001ec00 00200000 "android" emmc_p6: 0021ec00 0003f000 "cache" emmc_p7: 0025dc00 001e7000 "usrdata" emmc_p8: 00444c00 00a3b000 "fat" – HarshaXsoad Feb 28 '16 at 11:37
  • with this command also: "cat /proc/partitions ", major minor #blocks name 7 0 1254 loop0 253 0 524288 zram 179 0 7601664 mmcblk 179 1 1 mmcblk0p1 179 2 10240 mmcblk0p2 179 3 10240 mmcblk0p3 179 4 6144 mmcblk0p4 179 5 1048576 mmcblk0p5 179 6 129024 mmcblk0p6 179 7 997376 mmcblk0p7 179 8 5363712 mmcblk0p8 179 64 4096 mmcblk0boot1 179 32 4096 mmcblk0boot0 – HarshaXsoad Feb 28 '16 at 11:42
  • 1
    They say plagiarism is not a good thing to a platform meant for dissemination of knowledge. Follow How to reference material written by others. – Firelord Feb 29 '16 at 15:22
0

OK, that was my case some months ago:) My phone too was neither supported by cwm nor twrp. But after some research online, I rooted it and created nandroid backup..I have provided step-by-step procedure here- creating safe nandroid backup of any device

when the backup is complete, you will also get custom recovery for your device... I created this tutorial just to help people like you and me who were struggling to do nandroid backup.

nite
  • 1