[GUIDE] Backup your System partition using dd

aveemashfaq

Senior Member
Jul 27, 2012
98
60
0
27
warangal
Assalamu alaikum people,

I have seen many people complain that stock ROM is ruined or XYZ feature is missing or OTA has broken down their devices. It is safer to just backup your stock ROM before playing around. Some say that twrp backup is not working. So, we can use a fail-safe method that definitely works. I personally tested on my device. And since you are backing up your own system partition, it will definitely work for you too.

To do this, you need to have a rooted device. It is just one line of code. You can run it in terminal emulator app for android or you can connect your phone to PC.
Note:This command works with Honor 9 lite. For non-Honor devices, you must do "cat /proc/mounts" and understand the results to modify your code.
Steps to be taken
1. If you connect it to your PC, you need to do "adb shell". If you don't know what adb shell means, you better download Terminal emulator on your Honor phone and open it.

2. Then type "su" without the inverted commas inside terminal app or your adb shell. It will ask for root permissions. Grant it.

3.Paste the following code
Code:
dd if=/dev/block/platform/hi_mci.0/by-name/system of=/storage/emulated/0/system.img
The code will take some time and then display a result that it has succeeded and the bytes copied. Your system is backed up to your internal storage with the file name system.img. Now you can play around and if anything goes wrong, you can simply re-write your system.img and everything will be fine. Enjoy!!!
 

JamesBott

Senior Member
Feb 2, 2011
230
91
58
Ansbach
@aveemashfaq

Assalamu alaikum return to you.
have we a chance with this procedure to save "userdata" ? i think, it's encrypted.
your code work, i have now system.img, doing other test's with other rom's, reflash this system.img and this work ! nice way if not twrp installed !
 

Darkest-Dark

Senior Member
Mar 26, 2018
62
50
0
@aveemashfaq

Assalamu alaikum return to you.
have we a chance with this procedure to save "userdata" ? i think, it's encrypted.
your code work, i have now system.img, doing other test's with other rom's, reflash this system.img and this work ! nice way if not twrp installed !
You can save everything byte by byte... But that dont helps to decrypt it... I suggest to save everything from /sdcard to the external sd and after that wipe data, deactivate encryption and let the system recreate data unencrypted. Don't forget to save hw_init before...
 

JamesBott

Senior Member
Feb 2, 2011
230
91
58
Ansbach
@Darkest-Dark

i need not decrypted. i mean : if i make "dd if= .../userdata of= .../userdata.img "can i flash stock.system and flash this userdata.img AND phone WORK
with my userdata ! if encrypted or decrypted : that's no important. important is working ?
 

Darkest-Dark

Senior Member
Mar 26, 2018
62
50
0
@Darkest-Dark

i need not decrypted. i mean : if i make "dd if= .../userdata of= .../userdata.img "can i flash stock.system and flash this userdata.img AND phone WORK
with my userdata ! if encrypted or decrypted : that's no important. important is working ?
I don't understand why you would like to save data partition because there isn't any important... To save data of apps you could use titanium backup...
Here is what you wanna have:
Code:
dd if=/dev/block/platform/hi_mci.0/by-name/userdata of=/youwanttosave/userdata.img
 

aveemashfaq

Senior Member
Jul 27, 2012
98
60
0
27
warangal
Hey,

If you want to save userdata, it is not /something/userdata but it is /something/data. It is a good idea to backup all partitions before you start. I have accidentally formatted my /data partition using twrp and now the stock system will not boot at all. That is because stock data partition is in f2fs format and twrp reformatted it to ext4 format. I am not telling not to install twrp. I am just warning you that don't format data partition using twrp.

And also, remember that you cannot execute this code unless you have root access. And to get root access, you have to install twrp in the first place.

So, the code is

Code:
dd if=/dev/block/platform/hi_mci.0/by-name/data of=/storage/emulated/0/userdata.img
It will save your data in the internal storage with the name userdata.img
 

Darkest-Dark

Senior Member
Mar 26, 2018
62
50
0
Hey,

If you want to save userdata, it is not /something/userdata but it is /something/data. It is a good idea to backup all partitions before you start. I have accidentally formatted my /data partition using twrp and now the stock system will not boot at all. That is because stock data partition is in f2fs format and twrp reformatted it to ext4 format. I am not telling not to install twrp. I am just warning you that don't format data partition using twrp.

And also, remember that you cannot execute this code unless you have root access. And to get root access, you have to install twrp in the first place.

So, the code is

Code:
dd if=/dev/block/platform/hi_mci.0/by-name/data of=/storage/emulated/0/userdata.img
It will save your data in the internal storage with the name userdata.img
There is no data image at all. It's called userdata.

You can "erase" userdata by using fastboot or tell twrp to run rm - rf instead of format data Partition.
 

JamesBott

Senior Member
Feb 2, 2011
230
91
58
Ansbach
Hi,

i did tests. dd system work.

dd if=/dev/block/platform/hi_mci.0/by-name/userdata | gzip > /mnt/media_rw/8457-1CE9/dd-backup/stock-userdata.img
49274880+0 records in
49274880+0 records out
25228738560 bytes transferred in 824.913 secs

now flash system.img (developer-rom)
don't work by me

boot to bootloader
flash backup-system.img "ok"
flash backup-stock-userdata.img "fail"
target reported max download size of 471859200 bytes
Invalid sparse file format at header magi
error: write_sparse_skip_chunk: don't care size 857477578 is not a multiple of the block size 4096
error: write_sparse_skip_chunk: don't care size 385622474 is not a multiple of the block size 4096
fastboot: ../libsparse/sparse.c:144: write_all_blocks: Assertion `pad >= 0' failed.
Abgebrochen (Speicherabzug geschrieben)

in principle can work if solve "gzip or what here break"

now i have info, that new twrp is available and i "must" test this :)
if this twrp work then i open new thread

this backup with dd is in principle a simle way (thank's to @aveemashfaq for your thread here) :good:
i think if new twrp working - this info is more important (my opinion) :angel:
 

Darkest-Dark

Senior Member
Mar 26, 2018
62
50
0
Hi,

i did tests. dd system work.

dd if=/dev/block/platform/hi_mci.0/by-name/userdata | gzip > /mnt/media_rw/8457-1CE9/dd-backup/stock-userdata.img
49274880+0 records in
49274880+0 records out
25228738560 bytes transferred in 824.913 secs

now flash system.img (developer-rom)
don't work by me

boot to bootloader
flash backup-system.img "ok"
flash backup-stock-userdata.img "fail"
target reported max download size of 471859200 bytes
Invalid sparse file format at header magi
error: write_sparse_skip_chunk: don't care size 857477578 is not a multiple of the block size 4096
error: write_sparse_skip_chunk: don't care size 385622474 is not a multiple of the block size 4096
fastboot: ../libsparse/sparse.c:144: write_all_blocks: Assertion `pad >= 0' failed.
Abgebrochen (Speicherabzug geschrieben)

in principle can work if solve "gzip or what here break"

now i have info, that new twrp is available and i "must" test this :)
if this twrp work then i open new thread

this backup with dd is in principle a simle way (thank's to @aveemashfaq for your thread here) :good:
i think if new twrp working - this info is more important (my opinion) :angel:
I asked why you would like to save it... Its an f2fs partition not ext4... Its not quite easy...
Fastboot can handle it since Merge of 02/18... Isnt in honor9...

Even TWRP cant handle is safety...
 
  • Like
Reactions: JamesBott

aveemashfaq

Senior Member
Jul 27, 2012
98
60
0
27
warangal
Hi,

i did tests. dd system work.

dd if=/dev/block/platform/hi_mci.0/by-name/userdata | gzip > /mnt/media_rw/8457-1CE9/dd-backup/stock-userdata.img
49274880+0 records in
49274880+0 records out
25228738560 bytes transferred in 824.913 secs

now flash system.img (developer-rom)
don't work by me

boot to bootloader
flash backup-system.img "ok"
flash backup-stock-userdata.img "fail"
target reported max download size of 471859200 bytes
Invalid sparse file format at header magi
error: write_sparse_skip_chunk: don't care size 857477578 is not a multiple of the block size 4096
error: write_sparse_skip_chunk: don't care size 385622474 is not a multiple of the block size 4096
fastboot: ../libsparse/sparse.c:144: write_all_blocks: Assertion `pad >= 0' failed.
Abgebrochen (Speicherabzug geschrieben)

in principle can work if solve "gzip or what here break"

now i have info, that new twrp is available and i "must" test this :)
if this twrp work then i open new thread

this backup with dd is in principle a simle way (thank's to @aveemashfaq for your thread here) :good:
i think if new twrp working - this info is more important (my opinion) :angel:
Two things for you. First you should not compress them in gzip. It is only dd if=original_file of=destination.img. You have added |gzip in the middle which ruins things for you.

Second point. You can install images using twrp. I can confirm it works. fastboot flash does not work unless it is sparse image. so, you can restore using twrp.
 

ROO3VER

Senior Member
Feb 12, 2015
229
136
63
Antwerp
I have accidentally formatted my /data partition using twrp and now the stock system will not boot at all. That is because stock data partition is in f2fs format and twrp reformatted it to ext4 format. I am not telling not to install twrp. I am just warning you that don't format data partition using twrp.
Hi @aveemashfaq just red this post, like you i formatted my data partition and now my Honor 9 lite LLD-L31 C432 is in a bootloop ( data partition is formatted as f2fs not ext4).
I've tried restoring a backup, restoring with HuRupdater and flashing a custom ROM but it's still bootlooping.
Could you tell me how you got it fixed.


Edit: I found this thread by you:

https://forum.xda-developers.com/9-lite/how-to/guide-unbrick-device-recover-bootloop-t3772563

and i'm trying it out.
 
Last edited: