[Tutorial] Add TWRP to AOSP LP 5.0 boot.img

mcfisch

Senior Member
Oct 26, 2007
365
146
0
Albany, CA
I've updated the boot.img for paxb build 504 with TWRP to replace CWM. Some were asking how to do this.

Always keep a backup of a file known as working. If your device doesn't boot after flashing a modified file, just reflash that backup.

To perform this mod on your own follow these steps:

1. Download and unpack the Android Image Kitchen
2. Extract the boot.img from the downloaded ROM to the kitchen directory
3. Unpack the image:
Code:
unpackimg.bat boot_cwm_pabx_504.img
Output:
Code:
Android Image Kitchen - UnpackImg Script by osm0sis @ xda-developers

Supplied image: boot_cwm_pabx_504.img

Removing old work folders and files . . .

Setting up work folders . . .

Splitting image to "/split_img/" . . .

BOARD_KERNEL_CMDLINE androidboot.hardware=sony user_debug=31 msm_rtb.filter=0x3F ehci-hcd.park=3 vmalloc=400M
BOARD_KERNEL_BASE 80200000
BOARD_NAME
BOARD_PAGE_SIZE 2048
BOARD_KERNEL_OFFSET 00008000
BOARD_RAMDISK_OFFSET 02000000
BOARD_TAGS_OFFSET 00000100

Unpacking ramdisk to "/ramdisk/" . . .

Compression used: gzip
9694 blocks

Done!
This process will overwrite previously extracted contents!!!

4. Create a directory for the original image content, e.g. "boot_cwm_pabx_504" and COPY the created directories "ramdisk" and "split_img" into it. This ensures you can recreate it if necessary or access its original contents

5. Repeat step 4 for a downloaded TWRP (or any other recovery) image, e.g. "openrecovery-twrp-2.8.0.1-yuga.img".

6. Locate the "*-ramdisk.cpio.gz" file in the dirs from step 5, most likely in "split_img".

7. Ensure the "ramdisk" and "split_img" directories in the kitchen root dir are those from the image you want to modify (i.e. copy back from the folder created in step 4. Then remove the "*.cpio" from the "ramdisk\recovery" directory

8. Extract the TWRP "*.cpio" file from the "*-ramdisk.cpio.gz" in step 6 to "ramdisk\recovery" and rename it to "ramdisk-recovery.cpio"

9. rebuilt the image with the updated content:
Code:
repackimg.bat
Output:
Code:
Android Image Kitchen - RepackImg Script
by osm0sis @ xda-developers

Packing ramdisk . . .

Using compression: gzip

Getting build information . . .

kernel = boot_cwm_pabx_504.img-zImage
cmdline = androidboot.hardware=sony user_debug=31 msm_rtb.filter=0x3F ehci-hcd.park=3 vmalloc=400M
board =
base = 80200000
pagesize = 2048
kernel_offset = 00008000
ramdisk_offset = 02000000
tags_offset = 00000100

Building image . . .
10. Step 9 creates a file called "image-new.img". Rename it to something more self-explanatory, i.e. "boot_twrp_2.8.0.1_pabx_504.img"

11. To flash the file flash it like any other file using the new name:
Code:
adb reboot bootloader
fastboot flash boot boot_twrp_2.8.0.1_pabx_504.img
fastboot reboot
That's it, enjoy your new recovery.

Note: I had issues getting TWRP 2.8.1.0 working, so I'm still using the predecessor 2.8.0.1.

The latest pabx "boot.img" modified with TWRP is attached.

Known issues
  • after restoring a Nandroid backup access to the internal storage isn't allowed anymore
    Open a terminal or run through a adb shell:
    Code:
    restorecon -FR /data/media/0
 

Attachments

Last edited:

arismelachrinos

Senior Member
Feb 26, 2014
390
112
43
cant understand what you mean in step 7 and 8..... i just unpacked boot.img (the img that i want to put a recovery on it) and then i created a folder and i copied split_img and ramdisk into it.....then i unpacked twrp.img and it replaced the previous split_img and ramdisk folders with the twrp ones..... i still have the folder i created with the original split_img and ramdisk folders from boot.img but i can understand what to do next....

well, sorry for that,...i think i got it now that i read it about 20 times..... one question though :
i copy ramdisk.cpio.gz from the twrp and i move it to the recovery folder of the boot img without extracting? just renaming it from ramdisk.cpio.gz to ramdisk-recovery.cpio ???
 
Last edited:

langeveld024

Senior Member
Jun 7, 2012
1,720
805
143
cant understand what you mean in step 7 and 8..... i just unpacked boot.img (the img that i want to put a recovery on it) and then i created a folder and i copied split_img and ramdisk into it.....then i unpacked twrp.img and it replaced the previous split_img and ramdisk folders with the twrp ones..... i still have the folder i created with the original split_img and ramdisk folders from boot.img but i can understand what to do next....

well, sorry for that,...i think i got it now that i read it about 20 times..... one question though :
i copy ramdisk.cpio.gz from the twrp and i move it to the recovery folder of the boot img without extracting? just renaming it from ramdisk.cpio.gz to ramdisk-recovery.cpio ???
Yeah I didn't fully understand that either, but i just tried it.
You delete ramdisk-recovery.cpio from /ramdisk.
You extract ramdisk.cpio.gz to the /ramdisk folder.
You rename it to ramdisk-recovery.cpio.
Repack image.

(note that when the kernel you use is already a dualrecovery kernel -lightning for example, cwm philz+twrp- and u want it to be multirom twrp, u need to edit init.sh also found in /ramdisk folder somewhere)

BTW thanks for this guide! I was messing with this a few days ago and I couldn't get it to work, thanks to you I now understand why!:thumbup:
 
  • Like
Reactions: arismelachrinos

arismelachrinos

Senior Member
Feb 26, 2014
390
112
43
I tried to put latest twrp into latest boot.IMG of Thomas lollipop 23/11/14 build and I thought it worked but I press volume up and down to enter the recovery and it does nothing....it doesn't boot,it just freezes with the led lighting.... please help I really want twrp to work with lollipop
 

langeveld024

Senior Member
Jun 7, 2012
1,720
805
143
I tried to put latest twrp into latest boot.IMG of Thomas lollipop 23/11/14 build and I thought it worked but I press volume up and down to enter the recovery and it does nothing....it doesn't boot,it just freezes with the led lighting.... please help I really want twrp to work with lollipop
Reread what I wrote.
You probably didn't extract ramdisk.cpio.gz, or you putted it into /split_img I think. Cuz I had that too, but if you follow the exact steps it will work!
 
  • Like
Reactions: arismelachrinos

arismelachrinos

Senior Member
Feb 26, 2014
390
112
43
no I did exactly what you said... I fully understood the instructions,I extracted it , I named it right and I moved it right... well, I will try again tomorrow but I don't think it will boot into it... Thomas boot.img has a cwm recovery ,does this have smthg to do with it?
 

mcfisch

Senior Member
Oct 26, 2007
365
146
0
Albany, CA
no I did exactly what you said... I fully understood the instructions,I extracted it , I named it right and I moved it right... well, I will try again tomorrow but I don't think it will boot into it... Thomas boot.img has a cwm recovery ,does this have smthg to do with it?
What version of TWRP did you use? 2.8.1.0 will likely not work, use an older one instead.
 
  • Like
Reactions: arismelachrinos

mcfisch

Senior Member
Oct 26, 2007
365
146
0
Albany, CA
cant understand what you mean in step 7 and 8..... i just unpacked boot.img (the img that i want to put a recovery on it) and then i created a folder and i copied split_img and ramdisk into it.....then i unpacked twrp.img and it replaced the previous split_img and ramdisk folders with the twrp ones..... i still have the folder i created with the original split_img and ramdisk folders from boot.img but i can understand what to do next....

well, sorry for that,...i think i got it now that i read it about 20 times..... one question though :
i copy ramdisk.cpio.gz from the twrp and i move it to the recovery folder of the boot img without extracting? just renaming it from ramdisk.cpio.gz to ramdisk-recovery.cpio ???
Adjusted the description of step 8, should be more clear now what to do.
I've also added a note to point out explicitly that each run of "unpackimg.bat" will overwrite existing data.
 
  • Like
Reactions: arismelachrinos

arismelachrinos

Senior Member
Feb 26, 2014
390
112
43
thank you sooooo much.... i did it with the second try...the only thing i changed was that i downoaded a previous version of twrp because it wont work with the latest one...thanks a lot.... what about cwm? is it the same proccess?
 

arismelachrinos

Senior Member
Feb 26, 2014
390
112
43
i tried to do this on the cm12 expirimental build and the boot.img of that zip doesnt have a recovery folder inside ramdisk folder... i did create one just to see if it works and it didnt
 

mcfisch

Senior Member
Oct 26, 2007
365
146
0
Albany, CA
i tried to do this on the cm12 expirimental build and the boot.img of that zip doesnt have a recovery folder inside ramdisk folder... i did create one just to see if it works and it didnt
Look for a *.cpio or *.cpio.gz file and replace that accordingly. The place doesn't really matter for you, the ROM knows where to find it. CM might expect it respectively at another place. Will take a look later if I can find something...
 

arismelachrinos

Senior Member
Feb 26, 2014
390
112
43
Look for a *.cpio or *.cpio.gz file and replace that accordingly. The place doesn't really matter for you, the ROM knows where to find it. CM might expect it respectively at another place. Will take a look later if I can find something...
can you please take look at this?because i did search all the ramdisk folder and i found nothing.... i uploaded the boot.img so that you dont have to download the rom zip
https://www.mediafire.com/?5d6swrdegr53iel
 

shoey63

Recognized Contributor
Jun 5, 2012
4,003
3,982
253
Somewhere in Oz...
Look for a *.cpio or *.cpio.gz file and replace that accordingly. The place doesn't really matter for you, the ROM knows where to find it. CM might expect it respectively at another place. Will take a look later if I can find something...
Won't work like that. Needs a script to be inserted into the ramdisk, @pabx style, plus the recovery folder with ramdisk-recovery.cpio inside.
 
Last edited:
  • Like
Reactions: Pablosch23

RohitBopnna

Senior Member
Jun 6, 2014
145
57
0
was thinking why the latest TWRP was not working, then realized that the TWRP is written to be loaded into the FotaKernal.
then it worked with TWRP flashed into FotaKernal.
have pabx_aosp_yuga-509 installed
1. Followed your steps exactly to create a new boot_pabx_aosp_yuga-509.img (with the latest TWRP image "recovery-twrp-2.8.4.1-yuga.img").
2. Flashed recovery-twrp-2.8.4.1-yuga.img into the FotaKernal.
3. Flashed the new boot_pabx_aosp_yuga-509.img
it works :)

Edit: On my Xperia Z c6002 (yuga)
 
Last edited:
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone