Extracting stock Boot, Recovery and Persist images - Redmi K20 / Xiaomi Mi 9T Guides, News, & Discussio

Talking here about how to extract the stock Boot, Recovery and Persist images, needed in case of e.g. bootloop upon flashing Magisk or TWRP, to reflash the stock image(s).
Also, boot image is needed for patching from Magisk Manager (and flashing by Fastboot), as a preferable way to install Magisk.
Stock Recovery is needed if you want to revert from the custom one, and stock Persist is important because it contains certificate for Widevine L1 (needed for Full HD in eg Netflix)
From Recovery (zip) firmware
Download the Recovery (zip) image from:
https://c.mi.com/oc/miuidownload/detail?device=1700361
Extract the archive and find the boot.img inside.
However, it does not contain recovery.img
From Fastboot (tgz) firmware
Similarly, download the Fastboot (tgz) image from:
https://c.mi.com/oc/miuidownload/detail?guide=2
(check Desktop site if opening from the mobile browser)
Extract the archive, find the images folder with boot.img and recovery.img inside
From TWRP or OrangeBox
Boot and Persist images can be disk-dumped from TWRP or OrangeFox, from its Terminal, with the command:
Code:
dd if=/dev/block/bootdevice/by-name/boot of=/sdcard/boot.img
dd if=/dev/block/bootdevice/by-name/persist of=/sdcard/persist.img
Dumped images will be saved to Internal memory - both the official TWRP and OrangeFox support internal storage encryption (use your Android lock-screen password/pin), hence no need to format Data for TWRP to dump to Internal memory
Note:
Observe that if Magisk was installed, dumped Boot image won't be the stock one but the one already patched by Magisk
We could similarly dump the Recovery image, but since we must dump from TWRP or OorangeFox,
the dumped image won't be the stock one but the image of the installed custom Recovery
From Terminal Emulator app
Similarly, Recovery and Persist mages can be disk-dumped from Terminal emulator app:
Code:
su
dd if=/dev/block/bootdevice/by-name/recovery of=/sdcard/recovery.img
dd if=/dev/block/bootdevice/by-name/persist of=/sdcard/persist.img
By ADB
Finally, Recovery and Persist images can be also disk-dumped from ADB:
Code:
adb shell
su
dd if=/dev/block/bootdevice/by-name/recovery of=/sdcard/recovery.img
dd if=/dev/block/bootdevice/by-name/persist of=/sdcard/persist.img
Of course, ADB with drivers must be properly installed to the PC, and ADB debugging must be enabled in Settings, Developer options menu on the phone.
PC must be authorized from the phone once they get connected by USB cable
Finally, after the su command, root privilege must be granted to the Terminal emulator app before proceeding with dd command
Take care not to miss the authorization and root granting pop-ups on the phone if screen was switched of
Notes:
Observe that in both cases of Terminal emulator app and ADB, if custom Recovery was already installed, then you will be dumping the image of that custom Recovery
We can similarly dump the Bot image from Terminal emulator app or by ADB - but the root (Magisk) was prerequisite, hence the dumped image will be the Boot image already patched by Magisk

(Extracted stock) image files can be flashed by various ways
From Fastboot
Image files must be on the PC:
Code:
fastboot flash boot boot.img
fastboot flash recovery recovery.img
(I didn't test for persist.img, but found a note somewhere that it doesn't work)
You can also temporarily boot with the given boot.img (it won't be flashed and next time you reboot, it will reboot with the boot image that was flashed/installed previously):
Code:
fastboot boot boot.img
(As far as I tested, it's not possible similarly to temporarily boot with the given recovery image, without really flashing it)
By ADB
Image files must be on Internal memory at /
At the same place wherre you disk-dumped them
Adb must be enabled, phone must be rooted and adb must be granted root privilege
Code:
dd if=/sdcard/boot.img of=/dev/block/bootdevice/by-name/boot
dd if=/sdcard/recovery.img of=/dev/block/bootdevice/by-name/recovery
dd if=/sdcard/persist.img of=/dev/block/bootdevice/by-name/persist
From Terminal Emulator app
Similarly like by adb, but here just use "su dd" instead of "adb shell su dd"
Of course, phone must be rooted and Terminal Emulator app must be granted root privilege
From TWRP
From Advanced, Terminal.
Similarly like by adb, but use just "dd" instead of "adb shell su dd"
However, boot.img and recovery.img can be also flashed from Install menu in TWRP.
Select Image (by default is ZIP File), navigate to your boot.img (recovery.img) and select to flash to Boot (Recovery).
Persist.img cannot be flashed that way because e.g., official TWRP does not offer to patch to Persist
From OrangeFox
Image files can be flashed by "dd" command, just like from TWRP (OrangeFox is developed on top of TWRP)
However, image files can be also flashed directly from the main menu in OrangeFox.
Not only boot.img and recovery.img but also persist.img - see attached screenshot

Reserved

Same applies also for disk-dumping/flashing persistbak.img
It's a good idea to backup both Persist and PersistBack, if something goes wrong you can also restore persisback.img to Persist
Btw, backup (dd) also sdf.img and keep;
dd if=/dev/block/sdf of=/sdcard/sdf.img
restore if you loose IMEIs:
dd if=/sdcard/sdf.bin of=/dev/block/sdf

The fastboot rom comes with the stock persist image?
Maybe with that and the new 3.4.0 recovery (which can flash persist) I can get widevine l1 back.
---------- Post added at 02:31 PM ---------- Previous post was at 02:31 PM ----------
The fastboot rom comes with the stock persist image?
Maybe with that and the new 3.4.0 recovery (which can flash persist) I can get widevine l1 back.

Cni said:
The fastboot rom comes with the stock persist image?
Maybe with that and the new 3.4.0 recovery (which can flash persist) I can get widevine l1 back.
---------- Post added at 02:31 PM ---------- Previous post was at 02:31 PM ----------
The fastboot rom comes with the stock persist image?
Maybe with that and the new 3.4.0 recovery (which can flash persist) I can get widevine l1 back.
Click to expand...
Click to collapse
I doubt you could find persist.img in tgz but download, extract and check
However, you can disk-dump persist.img and persistbak.img, save, rename persistbak.img to persist.img and flash it back, maybe it still contains your L1 certificate
If anything goes wrong, just flash your persist.img back

Has anyone got the L1 certificate using this method?

tylerberk said:
Has anyone got the L1 certificate using this method?
Click to expand...
Click to collapse
No, you can't get back Widevine L1...

Super useful guide, especially if you already have a ROM installed and don't want to download the whole ROM again. Tahnk you for the tips, OP!

boot, recovery, Huawei Lua-u22​

Related

[GUIDE][ROM]Install a factory image from google without wiping data

This guide is for people who want a stock ROM strait from google without wiping their data and without relying on another dev to put together an update.zip to do the job.
Standard Disclaimer. You're responsible for your actions and your device. This guide just tells you what is possible. It is not as simple as booting to recovery and running an update.zip, but it will get the job done and it will be a fully factory system image with no modifications since you got it strait from google.
Pre-requisits:
Working ADB and fastboot and the ability to boot into the bootloader
A factory image from google for your device
A way to verify the MD5
A tool to extract the image files, I used 7 zip
Latest version of SuperSU
Optional:
Latest version of TWRP or your other favorite recovery
Begin:
Download the google factory image you want and verify the MD5.
Download the latest SuperSU and verify the MD5
Copy the SuperSU update zip to your device's sdcard
Extract/unzip the files from the google image until you get to the bootloader, flash scripts, and the image-xxxxxxxx-xxxx.zip file
Unzip the image-xxxxxxxx-xxxx.zip file as well. This file contains the individual images for boot, cache, recovery, system, and userdata
If you do not have fastboot in your command path, copy it to the folder that contains the bootloader and the individual images
Boot your device into bootloader mode
Open a command prompt or terminal and change to the directory where the bootloader image exists, run the below commands
Code:
fastboot erase boot
fastboot erase cache
fastboot erase system
fastboot flash bootloader bootloader-manta-mantamf01.img (Verify that you have the right image name, it will be different for different devices)
fastboot reboot-bootloader
After a reboot your device should be back at the bootloader
Change to the directory where the individual images exist and run the below commands
Code:
fastboot flash boot boot.img
fastboot flash cache cache.img
fastboot flash system system.img
At this point you have a fully stock system image, now you will want to boot to a custom recovery and install SuperSU for root access
If you want to install a new custom recovery you should do so now
Use the volume keys on the device and boot into recovery
Install the SuperSU update zip you copied to the device earlier
Reboot and be patient. Eventually you should see the "Andorid is updating" dialog. Once it completes you'll have applied a complete google factory image with root to your device without wiping out your data.

How to use ramdisk extraction utility to flash TWRP

Hey guys,
I consider myself pretty switched on but I can't understand how exactly the " ramdisk extraction utility" is used to flash TWRP.
Correct me if I'm wrong but it is used to unpack a boot.img file into separate files, one of which is the recovery. It then repacks it and allows it to be flashed via "fastest flash boot boot.img"
Ive found tools that repack boot.img files but all appear to be for Linux.
Can someone assist me by guiding me to a tutorial or offer step by step instructions on flashing TWRP onto my z2?
Basically all I want to do is understand how to flash any recovery I want when running a custom rom.
P. S - can someone explain the concept of why it dosnt work when I try to install TWRP as described in their website with
*terminal emulator or in adb shell:
su
dd if=/sdcard/fotakernel.img of=/dev/block/platform/msm_sdcc.1/by-name/FOTAKernel
Thank you.
Nothing guys?
Im not sure how to help you
1. Install fastboot
2. Use fastboot to flash recovery
Fastboot flash recovery recovery.img
3. You need a custom kernel
4. Find a kernel that supports fotakernel(recovery partition fyi)

How to fix Android boot loop, ADB?

My android (jellybean) tablet was turned off in middle of update and now is in boot loop. It was rooted with USB debugging on.
I MUST recover files (PDFs, .doc, .wav .JPEG, etc ) without erasing them.
Questions:
1 Do I use Odin and TWRP together?
2 Will Odin flash Samsung stock firmware erase files on device?
3. Will TWRP .img file erase everything?
4. Are these instructions correct?
I recommend you install TWRP recovery. It's the most feature-rich of all the recoveries I have used, and I will be assuming that is the recovery you use for the rest of this.
1. Boot into TWRP. (how? TWRP is an .img file )
2. Push your ADB public key to your device to force authentication.
____On Windows, do: adb push %UserProfile%\.android\ad
bkey.pub /data/misc/adb/adb_keys
3. Reboot into Android. Try adb shell and see if you get a shell prompt. If so, great! Exit it and run adb logcat, and read the huge error log for problems. If you didn't get the shell, well, then I think you're screwed, unless someone has cooked up a recovery zip for enabling adb.
What happens after ADB logcat?
Thank you..

(GUIDE) Unbrick (secure boot error) without restoring to stock

I'M NOT RESPONSIBLE FOR PEOPLE NOT FOLLOWING INSTRUCTIONS OR HARD BRICKED PHONES.
To follow this guide you must at least be able to access TWRP or Download mode or Fastboot at least.
(This guide applies too if your phone boots but with the Secure Boot error 1003 <- this error doesnt let your phone charge powered off)
1. Download Unbrick.zip
2. Download LG root zvb method zip from HERE (thanks to AUTOPRIME & Team CODEFIRE)
2a. Extract unbrick zip and root zvb zip in the same location
2b. right click "open command prompt" inside the folder of extraction.
3. Have LG drivers installed (you can find them in the forums)
4. If you have access to download mode and no TWRP installed you must first nuke LAF
4a. use the command prompt window we opened on 2b. and nuke laf using dd if=/dev/zero of=/dev/block/platform/msm_sdcc.1/by-name/laf
4b. type LEAVE (this will leave your G3 on fastboot)
5. On the same window we must flash TWRP. using fastboot flash recovery twrp.img
5a. then fastboot flash boot boot.img, fastboot flash aboot aboot.img, fastboot flash laf laf.img
5b. fastboot reboot should take you to twrp where you can flash any rom (I suggest FULMICS)
5c. If the rom you flash fails to boot or you keep getting secure boot error keep on with this guide.
6. Enter twrp and copy the boot, aboot and laf imgs to your internal storage
6a. open a cmd prompt and enter adb shell
6b. use dd command as follows:
dd if=/sdcard/aboot.img of=/dev/block/platform/msm_sdcc.1/by-name/aboot
dd if=/sdcard/boot.img of=/dev/block/platform/msm_sdcc.1/by-name/boot
dd if=/sdcard/laf.img of=/dev/block/platform/msm_sdcc.1/by-name/laf
7. Reboot to recovery and flash any custom rom this should fix your Secure Boot error Sprint LG G3. :highfive:
Thanks to all devs who worked on root and roms for this amazing phone!
Thanks! I had a working phone but still got the boot error. I copied the unbrick.zip to my phone and used the terminal in TWRP to run the dd commands in step 6b and it fixed the error! Reinstalled a fresh fulmics and everything is working fine.

[ROOT] How to flash recovery within Android with terminal / adb shell

Hi,
this is a small tutorial to show you how to flash the recovery, also eRecovery, via command line / adb shell within Android.
Flashify and other apps never worked for me, so I used commands to flash it without the need of fastboot.
It's a small tutorial for those who never worked with commands like this.
Please notify me if something went wrong or if you found any other issues.
I wanted to make a small script but I stopped it because of the lack of available commands in Android.
DISCLAIMER:
Read this tutorial first.
Never flash custom recovery to eRecovery.
Never flash recoveries from different devices.
Don't try to flash other partitions with this commands if you don't want to risk a brick.
Requirements:
- Oreo / EMUI 8 installed, Nougat hast other partition names. Pie isn't supported by me until final release.
- working root access
- terminal emulator app (I recommend Termius, it's easy to use and has nice features, it's free to use)
> or a PC, and USB cable and working ADB, also USB Debugging enabled in developer settings
- recovery img files on your phone, I recommend it to put them into your user root /data/media/0/ (internal memory)
NOTE: All commands are case sensitive!
Now open your terminal app or open the adb shell.
Type following command to enable root access:
Code:
su
SuperSU will ask you for root access, grant it.
Following command is needed to figure out, which type of memory your phone has:
Code:
ls /dev/block/platform
There are two possible outputs:
If you've a device with the faster UFS memory, it's ff3b0000.ufs, if eMMC it's hi_mci.0.
From now I'll write MEMORY instead of ff3b0000.ufs or hi_mci.0.
For flashing the recovery fire up following command:
Code:
dd if=/PATH/TO/YOUR/RECOVERY.IMG of=/dev/block/platform/MEMORY/by-name/recovery_ramdisk_a
Example: dd if=/data/media/0/twrp_3.2.1.img of=/dev/block/platform/ff3b0000.ufs/by-name/recovery_ramdisk_a
The output should look like this:
Code:
65536+0 records in
65536+0 records out
33554432 bytes transferred in 0.247 secs (135847902 bytes/sec)
If not, check your command and file paths.
For flashin the eRecovery fire up following command:
Code:
dd if=/PATH/TO/YOUR/ERECOVERY.IMG of=/dev/block/platform/MEMORY/by-name/erecovery_ramdisk_a
Example: dd if=/data/media/0/ERECOVERY_RAMDI.IMG of=/dev/block/platform/ff3b0000.ufs/by-name/erecovery_ramdisk_a
IMPORTANT NOTE: DO NOT INSTALL TWRP IN THIS! Flash only stock eRecovery!
The dd command won't give you any progress output, so be a bit patient. It should be done in a few second, but don't close the terminal app or connection before you got any output.
Unix systems like Android will give an output if something went wrong, always.
I use this to flash new TWRP versions or to flash stock recovery before I update.
If you recently updated your phone, you still need to flash via fastboot, because you lost root during the update.
The dd commands also work with fastboot. Mostly you'll use "fastboot flash recovery_ramdisk", but if you need to flash eRecovery, you can use the dd command.
23. February 2019:
Pie should also work, but you have to remove the "_a" after the partition name.
Example:
dd if=/data/media/0/twrp_3.2.1.img of=/dev/block/platform/ff3b0000.ufs/by-name/recovery_ramdisk
Please report if it's working or not.
How to know the path to the recovery_ramdisk?? Is all devices the same?? I didn't get it right the 1st time .. it shows path is invalid
Sent from my VTR-L29 using Tapatalk
fr3ker said:
How to know the path to the recovery_ramdisk?? Is all devices the same?? I didn't get it right the 1st time .. it shows path is invalid
Sent from my VTR-L29 using Tapatalk
Click to expand...
Click to collapse
Should be the same on every device. Remember, case sensitive and use _ and not -.
Maybe it's different on non UFS devices, which one do you have?
Are you able to post a screenshot of your command and output?
Jannomag said:
Should be the same on every device. Remember, case sensitive and use _ and not -.
Maybe it's different on non UFS devices, which one do you have?
Are you able to post a screenshot of your command and output?
Click to expand...
Click to collapse
Maybe @fr3ker is not on Oreo? The recovery_ramdisk partition is only for Oreo. In Nougat it is just called recovery. I don't know how the Pie partitions are called.
M1chiel said:
Maybe @fr3ker is not on Oreo? The recovery_ramdisk partition is only for Oreo. In Nougat it is just called recovery. I don't know how the Pie partitions are called.
Click to expand...
Click to collapse
Also my thought, I wanted to add this to the requirements when I created this post but apparently I forgot this. Now it's added as first point.
Hi.
I have a hard bricked p10. When I connect to laptop it's says USB SER. It doesn't not turn on I can't access recovery with power + vol. I can't get into fastboot. Anyway I can access fastboot to flash kernel and erecovery?
Jannomag said:
I use this to flash new TWRP versions or to flash stock recovery before I update.
Click to expand...
Click to collapse
Is it mandatory to flash stock recovery before update? Is it applies only to ota update or ff method?
Yes, FF or OTA are using stock recovery to flash the update. With TWRP it won't work.
Updated?
@ Jannomag:
Have you checked this for Pie meanwhile?
I currently have the problem, not being able to enter fastboot with:
Code:
sudo adb reboot bootloader
Additionally, there's something I do not understand. For the dd-command for flashing, why is the input-file (if=) the file in "/dev/block/platform/..." and the output on the sd-card? Wouldn't mean flashing an img to the device, that if= on the sd (or connected PC) and of= the path to the device (phone)?
Blümchen Blau said:
@ Jannomag:
Have you checked this for Pie meanwhile?
I currently have the problem, not being able to enter fastboot with:
Code:
sudo adb reboot bootloader
Additionally, there's something I do not understand. For the dd-command for flashing, why is the input-file (if=) the file in "/dev/block/platform/..." and the output on the sd-card? Wouldn't mean flashing an img to the device, that if= on the sd (or connected PC) and of= the path to the device (phone)?
Click to expand...
Click to collapse
WTF....Why didn't I notice this terrible mistake! Thank you for reading my post completely, you're 100% correct, I'll correct this directly after I submit this post.
Huawei did also a small change at naming the recovery partition, which I'll update, too.
I had also the problem that I wasn't able to boot into fastboot by command before I fried my phone - I couldn't figure out the reason for this.
Again, thank you!
Jannomag said:
Again, thank you!
Click to expand...
Click to collapse
Your'e welcome! I did update now, but didn't need your (correct ) way to fastboot, because the method described by borgerapper did the trick for me to get into fastboot and flash the needed original recovery.
Thanks anyway!

Categories

Resources