• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

[GUIDE]Porting TWRP without source

Search This thread
Thank you! Sorry for being so ignorant but, what's file mgr? File Manager? If so, I'm on windows, should I search for something to uncompress .lz4?

EDIT: Ok, I have unpack it with lz4 on windows and working on it right now.
Wasn't ignorance on your part. I forget that that other OS is out there sometimes. Yeah, I meant file manager, shouldn't have abbreviated. If you uncompressed it to get recovery.img you should be good to go.
 

LUCID_DREE

Member
May 4, 2020
12
0
I have got corrected all the mount point errors but still it has got the biggest bug, pls help here,. That even after decryption of the data partition , the TWRP can't read it, on opening it,it's just an empty folder
Find out the mount points using the instructions in the guide.
Try solving one error at a time (start with mounting the partitions properly), at times it is tough to get a TWRP working because of several issues, but you will get it done eventually.
 
I have got corrected all the mount point errors but still it has got the biggest bug, pls help here,. That even after decryption of the data partition , the TWRP can't read it, on opening it,it's just an empty folder
You may need to get recovery.log from twrp. Go to Advanced > Copy Log > swipe to copy logs to sdcard you shouldn't need kernel.log. Get that and post it then maybe someone can help you.
 

Augustoandro

Senior Member
Jun 20, 2017
558
237
Pune
hey i have SOME questions before i do this... since my phone is Samsung A9 (2018) [SM-A920F] which i think is the most underrated phones for development,

1. is the twrp can be any twrp from any hpone but atleast it have same SoC and device resolution?
2. Is this method still works on 2021? 😋
I apologize for the delay.
The TWRPs I have provided the link to in the guide are the most editable and you will have much better chance in porting one. At times, taking a TWRP that has same SoC might not be a good choice, in fact it might be the worst. Speaking from experience.
As for your second question, why not just try it out? This guide was not written in just a day, I had to add several parts for several months as my fellow contributors were trying out the guide (I have mentioned them in the second last section where I have thanked them all for their hardwork). Who knows?, you might find a way to port a TWRP to a device that has several issues as of now.
Just try it out, ask for help if you get stuck somewhere. There are some really helpful contributors on this thread. ALL THE BEST
 
  • Like
Reactions: Ajihidayat

sajibrgd

Member
Jul 27, 2021
5
0
20
Dhaka,Bangladesh
Yes, I know XDA is filled with such guides.
But you can only port a TWRP if you implement parts of all the guides.
This guide is a summation of all those guides.

NOTE:
I would be using AIK-Linux in this tutorial, since I don't recommend Windows for all this, who knows what problems you will get into.

REQUIREMENTS:
1.Download these TWRP recoveries in accordance with your screen resolution.
A. If your screen resolution is 480x850, 480x854; download
https://twrp.me/lg/lgnexus4.html
B. If your screen resolution is 720x1280, 800x1280 or 720xsomething; download
https://twrp.me/asus/asusnexus720123g.html
C. If your screen resolution is 1080x1920, download
https://twrp.me/motorola/motorolanexus6.html
2. Download Android Image Kitchen-Linux from this thread:
https://forum.xda-developers.com/showthread.php?t=2073775

LET'S BEGIN:
1. Unzip Android Image Kitchen zip file.
3. Now, navigate to the unzipped folder of AIK (Android Image Kitchen).
4. Just Right Click and select "Open Terminal here".
5. Copy and paste your stock recovery.img and paste it in AIK folder.
6. In the terminal, type the command
Code:
su
Enter your root password, then type
Code:
./unpackimg.sh
7. This will unpack your stock recovery.img. Do not close the terminal.
8. Cut the new folders, ramdisk and split_img, and paste them somewhere outside of AIK folder.
9. Remove the stock recovery.img in AIK folder.
10. Now, copy and paste the twrp_recovery.img according to your screen resolution in the AIK folder.
11. Now, revert back to the terminal and type
Code:
./unpackimg.sh
12. This will unpack your twrp_recovery.img
13. Delete all the files in the new split_img folder we got by unpackimg twrp_recovery.img
14. Copy and paste all the files in stock split_img folder to the new split_img folder.
15. Delete following files from new ramdisk folder.
A. default.prop
B. fstab.devicename_or_chipsetname
C. ueventd.rc
D. Any other file like ueventd.devicename.rc
16. Copy and paste these files from stock ramdisk folder to new ramdisk folder.
Code:
default.prop
fstab.devicename
ueventd.rc
17. Now go into stock ramdisk/etc folder and copy recovery.fstab
18. Paste the recovery.fstab file in new ramdisk/etc folder.
19. Edit the twrp.fstab file according to the newly pasted recovery.fstab
20. You will have to replace"/sdcard" with "/external_sd" and "/usb" with "/usb-otg".
21. If the partitions stated above are not available in your fstab files then add these lines. Order may change on the format in which the files are written.
Code:
/external_sd          vfat         /dev/block/mmcblk1p1  flags=removable;storage;display="SDCARD"
/usb-otg                auto         /dev/block/sda1    flags=removable;storage;display="USB-OTG"
22. Edit the following lines as shown in default.prop
Code:
ro.secure=0
ro.adb.secure=0
security.perf_harden=0
ro.debuggable=1
persist.sys.usb.config=adb,mtp
23. Now, come out of the ramdisk folder and open the terminal.
24. Type
Code:
./repackimg.sh
25. Your new TWRP img would be generated and named as image-new.img by default. You may change the name later.

When you have successfully built the TWRP, or if you want to request one instead of creating yourself, contact me on this thread:
https://forum.xda-developers.com/android/general/unofficial-twrps-devices-source-code-t3833338


SPECIAL INSTRUCTIONS FOR MEDIATEK DEVICES:
1. The recovery.fstab you will get after unpacking your stock recovery.img would be flawed in most cases. I believe OEMs do this deliberately.
2. In order to know which partition is mounted at which location and at which device, you'll need DiskInfo (Install it from Play Store) and a root explorer.
3. Enable the following Diskinfo settings:
Code:
Show mount path
Show partition name
Show file system
Expert mode
Unmounted partitions
Device Mapper partitions
Temporary filesystems

4. Use the root explorer to find the path of your partitions. They would be located under /dev (mtk devices have bootimg and recovery here generally) and some other partitions like /system, /cache would be deeper inside.
5. You can trace their exact locations by navigating within the /dev directory for partition names like mmcblk0p5.


SPECIAL INSTRUCTIONS FOR DEVICES THAT DON'T HAVE RECOVERY.FSTAB WITHIN STOCK RECOVERY.IMG
1. In the ramdisk/etc folder, there might be a dummy recovery.fstab file with the symbol of link on it.
2. Right click on the file and select "Show Target". You'll get to know the path of original recovery.fstab file. It might be within the unpacked recovery or inside some other partition on your phone.
For example: Honor 7C devices have their recovery.fstab in /vendor/etc folder.

TROUBLESHOOTING INSTRUCTIONS:
1. If you get a dm-verity error or facing an encryption problem, go to this thread and flash the "dm-verity and forceencrypt disabler zip".
https://forum.xda-developers.com/android/software/universal-dm-verity-forceencrypt-t3817389
2. If you encounter a bootloop while booting into your new TWRP, please consult post #20 of this thread.
3. At times, the path of partitions during recovery boot is not the same as those during normal boot. That's why you may get errors like
Code:
Updating partitions details...
Failed to mount '/cache' (Invalid argument)
Failed to mount '/system' (Invalid argument)
Failed to mount '/data' (Invalid argument)
Failed to mount '/metadata' (Invalid argument)
...done
Unable to mount storage
Failed to mount '/data' (Invalid argument)
To resolve this, in your TWRP terminal type the following command
Code:
find /dev/block -name by-name
Replace the paths of the partitions in your fstab files with the ones you get as output using the command above (only the partitions which failed to mount).

If there are some bugs or you need some assistance in porting TWRP, contact me by mentioning in your post, for example @Augustoandro, we'll work on it to make it bug-free.

Special thanks to @aIecxs for his troubleshooting instructions of bootloop, "Failed to mount /partition_name (invalid argument)" error and also @inguna for guiding me on how to fix the "SDCARD not detected by the TWRP" problem and also fixing the MTP, ADB not working issue.
Another thanks to @seanybiker and @avirus for their troubleshooting instructions on "DM-Verity and forceencrypt" errors.

CREDITS:
@HostZero for his porting guide.
@osm0sis for his awesome Android Image Kitchen
@Zackptg5 for his "DM-Verity and Forceencrypt disabler zip".
For mediatek device after showing all path form diskinfo like
mount path
partition name
file system
Expert mode
Unmounted partitions
Device Mapper partitions
Temporary filesystems
What should i do...how to build twrp by showing this path
 

Augustoandro

Senior Member
Jun 20, 2017
558
237
Pune
For mediatek device after showing all path form diskinfo like
mount path
partition name
file system
Expert mode
Unmounted partitions
Device Mapper partitions
Temporary filesystems
What should i do...how to build twrp by showing this path
Use the partitions you found to edit the recovery.fstab and twrp.fstab files.
You can follow rest of the instructions from the guide.

HIT THANKS IF FOUND USEFUL
 
  • Like
Reactions: sajibrgd
@Augustoandro I have tried following your guide with one of the verions of TWRP that you provided as well as with a different version of TWRP from a device with the same Mediatek CPU as mine and both times when I try to go into recovery it just goes onto the screen with the OEM logo (acer in my case) and then it goes black and repeats that so basically a boot loop, I also tried to find the recovery.log from thread #20 but the problem is that the recovery.log in there is only from my original recovery but it's not updating to the TWRP one as when I look at the file details it shows an older time back from when I booted into the original recovery and also the log doesn't have a mention of TWRP so I am pretty sure that the log isn't for TWRP, do you know any other places I could look to possibly find the log so that you could (or I could) try to figure out the problem?
 

rohitrss

Member
Nov 27, 2013
35
5
Moto G
Xiaomi Redmi Note 7
Samsung M40 Recovery port issue

Dear Dev
Im using Samsung M405f aka M40 [ soc :Snap Dragon 675 and Res: 1080x2340 px, 409 PPI] same as Xiaomi Redmi Note 7 Pro

Stock-M405F Recovery
Redmi-Note-7-TWRP

I have followed your steps and to my surprise, I did not find fstab.xxx in my stock recovery. I skipped the step 16.B since i did not have any fstab files except recovery.fstab later I repacking my recovery.img and converted into recovery.img.tar using 7zip to make it odin flashable. after Successfully flashing I rebooted into recovery by pressing Vol+ and power button and to my surprise it boot into stock recovery which I have not expected.
I request you to inspect both the official twrp of another device and my stock recovery , so that there would be a clear picture of things to consider while building twrp for my device which would very help for script buddies like me
Hi, did you manage to port the TWRP recovery for M40?
 

Augustoandro

Senior Member
Jun 20, 2017
558
237
Pune
@Augustoandro I have tried following your guide with one of the verions of TWRP that you provided as well as with a different version of TWRP from a device with the same Mediatek CPU as mine and both times when I try to go into recovery it just goes onto the screen with the OEM logo (acer in my case) and then it goes black and repeats that so basically a boot loop, I also tried to find the recovery.log from thread #20 but the problem is that the recovery.log in there is only from my original recovery but it's not updating to the TWRP one as when I look at the file details it shows an older time back from when I booted into the original recovery and also the log doesn't have a mention of TWRP so I am pretty sure that the log isn't for TWRP, do you know any other places I could look to possibly find the log so that you could (or I could) try to figure out the problem?
My guess is that your TWRP is not being flashed properly.
Erase the recovery partition and flash it again.
If even that doesn't work, then check the files in kernel folder after unpacking the TWRP image. Make sure you used the correct stock firmware while porting the TWRP.

HIT THANKS IF FOUND USEFUL
 

rohitrss

Member
Nov 27, 2013
35
5
Moto G
Xiaomi Redmi Note 7
@Augustoandro Can you create a guide on creating/porting TWRP if kernel sources are available? I have Samsung Galaxy M40 (updated to Android 11) and its sources are available at https://opensource.samsung.com/uploadSearch?searchValue=m40. The main concern than I have is how do I test any TWRP/Recovery if I started to port any recovery image. I have not done this before so any help would be appreciated.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    @Augustoandro Instead of using motorolanexus6 as base TWRP

    can we use TWRP of a device which is very similar to ours? In Galaxy M40's (1080 x 2340p resolution) case it would be Redmi Note 7 Pro.
    Yes, you can. The TWRPs I suggested in the guide are most editable. And have had the most success according to my experience.
    If you find better editable ones, you are free to use them.

    HIT THANKS IF FOUND USEFUL
    1
    I have vivo y15s and unlocked bootloader but after unlock it goes to stock recovery and wipes data itself without prompting. But wiping data fails and it does not boot system because after vivo logo it reverts back to stock recovery and fails to wipe data.
    I used twrp build by auto porting by hovatek, but it didn't boot. I have a stock recovery and all firmware dump. Will the problem solved using twrp? Can you please build a Twrp?
    This problem cannot be solved even I flash full firmware using sp flast tool(mtk6580), only restoring dump backup solves the problem.
    firmware version: PD1304DW_EX_A_1.70.5
    Stock Recovery Link(bin format): https://drive.google.com/file/d/18f6ithUDCr1NSkxzcZoUpol_OzCJ8UKf/view?usp=sharing

    boot.bin: https://drive.google.com/file/d/1VC6Rg40fVb2a-iMmvwhmze8mpZjUC_wl/view?usp=sharing

    Scatter file: https://drive.google.com/file/d/1G4M9XziBV5nIbULZsO4nYGPHT2DjHMOt/view?usp=sharing

    Available version firmware in google: PD1304DE_EX_A_1.10.5
    Recovery: https://drive.google.com/file/d/1U_qP6PsQPdY7THN2F_YqlhgXfEYYiD94/view?usp=sharing


    Tried patched boot image but all goes to wipe data failed and in fastboot mode to remote failed.
    Feel free to use this guide for porting a TWRP of your own.
    I have stopped porting TWRP for others since I don't have that much time anymore.
  • 33
    Yes, I know XDA is filled with such guides.
    But you can only port a TWRP if you implement parts of all the guides.
    This guide is a summation of all those guides.

    NOTE:
    I would be using AIK-Linux in this tutorial, since I don't recommend Windows for all this, who knows what problems you will get into.

    REQUIREMENTS:
    1.Download these TWRP recoveries in accordance with your screen resolution.
    A. If your screen resolution is 480x850, 480x854; download
    https://twrp.me/lg/lgnexus4.html
    B. If your screen resolution is 720x1280, 800x1280 or 720xsomething; download
    https://twrp.me/asus/asusnexus720123g.html
    C. If your screen resolution is 1080x1920, download
    https://twrp.me/motorola/motorolanexus6.html
    2. Download Android Image Kitchen-Linux from this thread:
    https://forum.xda-developers.com/showthread.php?t=2073775

    LET'S BEGIN:
    1. Unzip Android Image Kitchen zip file.
    3. Now, navigate to the unzipped folder of AIK (Android Image Kitchen).
    4. Just Right Click and select "Open Terminal here".
    5. Copy and paste your stock recovery.img and paste it in AIK folder.
    6. In the terminal, type the command
    Code:
    su
    Enter your root password, then type
    Code:
    ./unpackimg.sh
    7. This will unpack your stock recovery.img. Do not close the terminal.
    8. Cut the new folders, ramdisk and split_img, and paste them somewhere outside of AIK folder.
    9. Remove the stock recovery.img in AIK folder.
    10. Now, copy and paste the twrp_recovery.img according to your screen resolution in the AIK folder.
    11. Now, revert back to the terminal and type
    Code:
    ./unpackimg.sh
    12. This will unpack your twrp_recovery.img
    13. Delete all the files in the new split_img folder we got by unpackimg twrp_recovery.img
    14. Copy and paste all the files in stock split_img folder to the new split_img folder.
    15. Delete following files from new ramdisk folder.
    A. default.prop
    B. fstab.devicename_or_chipsetname
    C. ueventd.rc
    D. Any other file like ueventd.devicename.rc
    16. Copy and paste these files from stock ramdisk folder to new ramdisk folder.
    Code:
    default.prop
    fstab.devicename
    ueventd.rc
    17. Now go into stock ramdisk/etc folder and copy recovery.fstab
    18. Paste the recovery.fstab file in new ramdisk/etc folder.
    19. Edit the twrp.fstab file according to the newly pasted recovery.fstab
    20. You will have to replace"/sdcard" with "/external_sd" and "/usb" with "/usb-otg".
    21. If the partitions stated above are not available in your fstab files then add these lines. Order may change on the format in which the files are written.
    Code:
    /external_sd          vfat         /dev/block/mmcblk1p1  flags=removable;storage;display="SDCARD"
    /usb-otg                auto         /dev/block/sda1    flags=removable;storage;display="USB-OTG"
    22. Edit the following lines as shown in default.prop
    Code:
    ro.secure=0
    ro.adb.secure=0
    security.perf_harden=0
    ro.debuggable=1
    persist.sys.usb.config=adb,mtp
    23. Now, come out of the ramdisk folder and open the terminal.
    24. Type
    Code:
    ./repackimg.sh
    25. Your new TWRP img would be generated and named as image-new.img by default. You may change the name later.

    When you have successfully built the TWRP, or if you want to request one instead of creating yourself, contact me on this thread:
    https://forum.xda-developers.com/android/general/unofficial-twrps-devices-source-code-t3833338


    SPECIAL INSTRUCTIONS FOR MEDIATEK DEVICES:
    1. The recovery.fstab you will get after unpacking your stock recovery.img would be flawed in most cases. I believe OEMs do this deliberately.
    2. In order to know which partition is mounted at which location and at which device, you'll need DiskInfo (Install it from Play Store) and a root explorer.
    3. Enable the following Diskinfo settings:
    Code:
    Show mount path
    Show partition name
    Show file system
    Expert mode
    Unmounted partitions
    Device Mapper partitions
    Temporary filesystems

    4. Use the root explorer to find the path of your partitions. They would be located under /dev (mtk devices have bootimg and recovery here generally) and some other partitions like /system, /cache would be deeper inside.
    5. You can trace their exact locations by navigating within the /dev directory for partition names like mmcblk0p5.


    SPECIAL INSTRUCTIONS FOR DEVICES THAT DON'T HAVE RECOVERY.FSTAB WITHIN STOCK RECOVERY.IMG
    1. In the ramdisk/etc folder, there might be a dummy recovery.fstab file with the symbol of link on it.
    2. Right click on the file and select "Show Target". You'll get to know the path of original recovery.fstab file. It might be within the unpacked recovery or inside some other partition on your phone.
    For example: Honor 7C devices have their recovery.fstab in /vendor/etc folder.

    TROUBLESHOOTING INSTRUCTIONS:
    1. If you get a dm-verity error or facing an encryption problem, go to this thread and flash the "dm-verity and forceencrypt disabler zip".
    https://forum.xda-developers.com/android/software/universal-dm-verity-forceencrypt-t3817389
    2. If you encounter a bootloop while booting into your new TWRP, please consult post #20 of this thread.
    3. At times, the path of partitions during recovery boot is not the same as those during normal boot. That's why you may get errors like
    Code:
    Updating partitions details...
    Failed to mount '/cache' (Invalid argument)
    Failed to mount '/system' (Invalid argument)
    Failed to mount '/data' (Invalid argument)
    Failed to mount '/metadata' (Invalid argument)
    ...done
    Unable to mount storage
    Failed to mount '/data' (Invalid argument)
    To resolve this, in your TWRP terminal type the following command
    Code:
    find /dev/block -name by-name
    Replace the paths of the partitions in your fstab files with the ones you get as output using the command above (only the partitions which failed to mount).

    If there are some bugs or you need some assistance in porting TWRP, contact me by mentioning in your post, for example @Augustoandro, we'll work on it to make it bug-free.

    Special thanks to @aIecxs for his troubleshooting instructions of bootloop, "Failed to mount /partition_name (invalid argument)" error and also @inguna for guiding me on how to fix the "SDCARD not detected by the TWRP" problem and also fixing the MTP, ADB not working issue.
    Another thanks to @seanybiker and @avirus for their troubleshooting instructions on "DM-Verity and forceencrypt" errors.

    CREDITS:
    @HostZero for his porting guide.
    @osm0sis for his awesome Android Image Kitchen
    @Zackptg5 for his "DM-Verity and Forceencrypt disabler zip".
    2
    @JLowe
    I apologize for the delay in replying.

    1. The topmost part
    Code:
    #<src> <mnt_point> <type> <mnt_flags>
    has already been commented out by "#", so leave it as it is.
    2. For listing the system partition in fstab files, always use "/system".
    3. Always include all entries from the stock recovery.fstab in your TWRP recovery.fstab and edit your twrp.fstab in accordance with it.
    4. Whatever partititon is not available in your stock, never include it in your TWRP fstab (applies to both recovery.fstab and twrp.fstab). If you can't find a partition neither in your stock fstab nor via DiskInfo , it just means those partitions don't exist on your device.
    5. Never include files not available in your stock recovery to your TWRP.

    HIT THANKS IF FOUND USEFUL
    2
    Hi and thanks for the extensive guide!

    I'm trying to port TWRP to a digital signage display using a RK3288 chip (basically a huge 43 inch tablet)
    I managed to find a version of TWRP for RockChip devices that I was able to flash using the official TWRP app. After rebooting to recovery however, TWRP wasn't able to find the partitions properly.
    When trying to run a backup (the main scope is to be able to backup/restore), I got the following messages:


    and so on.

    I'm assuming that it's because of the recovery.fstab/twrp.fstab that are not configured properly, but I seem not to be able to match the syntax of the original files with the new ones.
    My original recovery.fstab looks like this:


    And the twrp.fstab (for now) looks like this:


    What is confusing is that I also have a recovery.emmc.fstab in my orginal ramdisk/etc folder. It looks like this:


    Since this i s a port for the same board "family" (I see RK30boar mentioned all over the place), I'm I right assuming I only need to adapt the file system tables in order to get it working?

    For good measure (and not to be blamed for not giving enough info when requesting help :D), here is the content of the original default.prop:


    Help or a hint in the right direction would be much appreciated :)
    Thanks and cheers
    Oli
    I really apologize for the delay in replying.
    Check the point number 3 in TROUBLESHOOTING INSTRUCTIONS section in the guide.
    I have just added the instructions to the guide for everyone.
    Thank you for bringing this to my attention, I had forgotten to add these instructions in the guide.

    HIT THANKS IF FOUND USEFUL
    2
    SuperSU or Magisk won't install into system but into boot and data

    in TWRP you have a terminal. type
    Code:
    ls -ld $(find /dev/block -name by-name)/*
    you can manually mount, all you need is a folder as mount point
    Code:
    mkdir /system_root
    mount /dev/block/bootdevice/by-name/system /system_root
    mount
    2
    Hi I tried to Port a Recovery for my H96 Max RK3399 TV Box .
    I used TWRP From My RK3328 TVBox.
    I can Boot in Recovery, but its not Mounting any Partition (everywhere 0MB)
    I Think the problem is in .Fstab File but I am Not sure.
    I would appreciate help

    Sorry for my poor English
    Partitions not being recognized means the problem is in fstab files. Both recovery.fstab and twrp.fstab need to be edited.
    I am sure of it.

    HIT THANKS IF FOUND USEFUL