0

Question :How to infuse/push/modify/install busybox SU in twrprecovery.img for getting root privilages commands

I want to take backup restore flash change some PM Package management and SM storage Management settings of my android 5.1.1 /6.0 mobile phone through adb shell commands or through twrp terminal without installing twrp or SU or rooting mobile device

  1. Firstly I want to take backup of mobile system.img userdata.img through adb pull command and then recover write back adb push

My concerns related to first :

a. As adb pull reads and copy data but adb push writes on the device b. Will adb push work without rooting mobile phone without root privilages.
c. If phone bricked or something gets wrong while rooting and phone is not rooted then will adb push work or not.

Steps of commands using for backup of device
    Adb devices
    adb reboot bootloader
    adb pull /dev/block/mmcblk0 mmcblk0.img
    Adb push mmcblk0.img /dev/block/mmcblk0 mmcblk0.img
  1. Using PM package manager on unrooted mobile android 5.1.1 with following commands but error

    Adb devices adb reboot bootloader adb shell pm set-install-location 2 adb shell pm get-install-location

Error of command

/sbin/sh: pm: not found

what I understood from above error means that PM binary command file is not available in /sbin/sh/ folder as phone is not rooted so what I think if I put these binary files or install busybox within twrprecovery.img before loading and run temporary pm command so that I don't have to root the device and temporary set the changes in device.

If it's possible then kindly share the link for step by step procedure for modifying twrprecovery.img before booting in pc computer windows as I am new novice to adb shell Linux commands

  1. Thirdly As whenever I run SM storage manager command adb shell following command on unrooted android 6.0 mobile from it gives following errors

    Adb devices adb reboot bootloader adb shell sm has-adoptable adb shell sm set -force- adoptable true

It gives following errors

/sbin/sh: sm: not found

what I understood from above error means that SM binary command file is not available in /sbin/sh/ folder as phone is not rooted so what I think if I put these binary files or install busybox within twrprecovery.img before loading and run temporary pm command so that I don't have to root the device and temporary set the changes in device.

If it's possible then kindly share the link for step by step procedure for modifying Twrprecovery.img before booting in pc windows as I am new novice to adb shell Linux commands

  1. Now if boot in fastboot mode and run twrprexovery.img or cwgmod recovery.img with these commands and then in twrp or cgmod terminal windows can I run busybox or Super user or PM SM command

    Adb devices Adb boot bootloader Fastboot boot twrprecovery.img

  2. Secondly the whole ideas is that I want to virtually temporary use twrp terminal with busybox or Super user binary to execute services packages like PM (package manager) SM (storage manager) within from twrp recovery menu terminal (loaded in fastboot boot twrprecovery.img mode). Or adb sideload If it's possible technically feasable. If yes then can we modify twrprexovery.img and infuse insert busybox in it before loading or after loading.

twrp adb sideload or teminal

  1. Thirdly I don't want to install twrp or busybox or any super user binary file inside mobile device and don't want to install anything inside mobile except the changes alteration of settings done after execution of SM PM commands. That is I want to execute PM SM from within twrprecovery.img
Androidquery
  • 467
  • 1
  • 5
  • 19
  • On the devices I know adb reboot bootloader boots into bootloader mode. Bootloader mode means fastboot mode. And if device is in fastboot mode only fastboot works, but not adb. See https://android.stackexchange.com/q/221634/2241 – Robert Aug 13 '21 at 12:09
  • 1
    Sorry but yout question doesn't make much sense. There are some random pieces, not clear what you are trying to do. At least you need to understand the difference between normal Android OS vs. fastboot/bootloader mode vs. recovery mode. pm, sm and other similar commands are interfaces to access Android's services like Package Manager, Storage Manager etc. And Android OS is not running when you are in bootloader or recovery mode. So these services aren't running either. – Irfan Latif Aug 13 '21 at 15:26
  • @IrfanLatif bro thanks a lot for a comment after long time...yes what I want to do is run PM (package manager) SM (storage manager) in bootloder mode without pushing in device just want to temporary run set values and exit. As PM (made for andorid 4.0 kitkat) binary is not available in android 5.1 after rooting and SM (available in android 6 marshmellow) so either pushing binary in device want to run virtually from twrp recovery image or busy box in twrp terminal window if possible – Androidquery Aug 13 '21 at 19:21
  • @alecxs bro thanks to answer again just to clarify that questions I tried to modify twrpr recovery image as you answer there but was not suceedul just sarted a new thread to clarify and get more suggestions advice opinion from experts. If posible or not if yes then how any tricks to do it. As twrprexoveey image ia giving eroor of mount 0 may be encryption error. Want to try if it works or not. Your answers was okay gr8 in that question but for novice it's little tricky I m still trying to get some simple links step by step – Androidquery Aug 13 '21 at 19:36
  • 1
    as already stated sm is not even a binary How to use an external sdcard as internal in Android Lolipop 5.1.1? therefore (as already stated too) one can't run sm/pm in recovery mode. furthermore no su required because twrp shell is already root. regarding ramdisk modifications there is step by step instructions (osm0sis AIK xda thread) what step you are struggling? – alecxs Aug 13 '21 at 20:22
  • @alecxs bro okay thanx I had not seen AIK link for modifying I will see and study it and try thanks a lot. For sm there is a windows batch file made by someone for muiui mobile don't know if it will work or not see the detail link https://miui.blog/any-devices/sd-card-auto-formatting-tool-windows-linux/ – Androidquery Aug 13 '21 at 21:01
  • that will format MicroSD as adoptable-storage which is only supported since android 6+ – alecxs Aug 13 '21 at 21:47
  • (1) fastboot and adb are completely independent boot modes with different protocol languages. if you messed up aboot you can't unbrick from fastboot. just don't touch it. adb is always available in twrp, there is no problem to restore backup (2) pm, sm depends not on rooting. pm always works in android, but set-install-location is only available android 6+ (3) seen this link before, that will just format MicroSD as adoptable-storage (no root required) which is only supported since android 6+ (you don't have it therefore of no use) – alecxs Aug 15 '21 at 09:32
  • no. have a look into bootStrapServices and think about it. busybox is just supersede/predecessor to toybox (self-hosting core utils) which is default in android – alecxs Aug 15 '21 at 10:16

1 Answers1

1
  1. a) adb pull requires root access. This can be achieved by running custom recovery like TWRP.
    b) adb push works the same way like adb pull and requires root access (without rooting android).
    c) adb daemon only works on booted kernel (android or recovery) therefore not on bricked devices.

    Warning: Never write whole mmcblk0 because this contains bootloader and little kernel, therefore fastboot will not work in case you bricked!

    Backup every partition on it's own instead. you will get a full list of symlinks to all partitions from adb

    adb shell ls -l /dev/block/bootdevice/by-name
    

    commands for raw backup of device (encrypted)

    adb reboot bootloader
    fastboot boot twrp*.img
    adb pull /dev/block/bootdevice/by-name/boot
    adb pull /dev/block/bootdevice/by-name/system
    adb pull /dev/block/bootdevice/by-name/modem
    adb pull /dev/block/bootdevice/by-name/persist
    adb pull /dev/block/bootdevice/by-name/userdata
    ...
    

  1. Android service Package Manager pm requires java which is not available in recovery mode.
    It might be possible to start java when /system is mounted and even possible to execute pm but still Package Manager will badly crash because of missing framework dependencies.
    Someone could figure out all required services and may be able to start them in right order, but that ends up similar to fully booted android and is not worth the effort.

  1. Android service Storage Manager sm is not available in recovery mode for the same reason.
    Furthermore adoptable-storage isn't available on Android 5.1.1 regardless it is rooted or not.
    It is pointless to copy files like sm.jar from other android version and there is no way to run it from recovery, not even temporary. Integrating adoptable-storage on android 5 will result in compiling custom ROM which requires lot of patience. Anyone who manages this most likely would become a skilled developer during this long troubleshooting period.

  1. su sm pm and busybox are unrelated to each other. None of that tools will help to edit some storage settings in a way to overcome problem 2. + 3.
    Furthermore /data is encrypted and storage settings can not edited -offline- until you decrypt userdata or disable encryption (which requires factory reset and modification of boot).

  1. It is possible to temporary push desired binaries like busybox into RAM while in recovery mode, or permanently integrate it in recovery ramdisk by modification of twrp.img

    Steps for adding busybox into recovery ramdisk

    • download twrp.img
    • download Android.Image.Kitchen.Win32.zip
    • download Busybox.Installer.zip
    • disable antivir heuristic and extract the zip files. make sure Android_Image_Kitchen \ android_win_tools \ sudo.exe is not in quarantine
    • place twrp.img in Android_Image_Kitchen directory
    • open cmd.exe, navigate to directory and execute unpackimg.bat
    • copy busybox-arm-selinux binary into Android_Image_Kitchen \ ramdisk \ sbin directory and rename it busybox
    • execute repackimg.bat

  1. There is no need to root android for doing modifications in boot.img
    you can even install custom init.rc script or init.d shell script without installing su or busybox

    You can write custom mount script for MicroSD Card sdext2 partition. You can even do all the symlinks offline from twrp recovery adb shell commands.
    But this is unusual and over-complicated when one could just install Link2SD as system app and automatized the whole symlink handling.

    However, for more information about creating custom init.rc or init.d script refer to
    How to run an executable on boot and keep it running?

alecxs
  • 4,034
  • 3
  • 16
  • 34
  • bro great thanx a lotz just sleeppy just now it's midnight here I will try all in morning still great compiled efoorted answe.bro thanks a lot hope all works fine – Androidquery Aug 14 '21 at 18:51
  • bro as you said "adb fastboot daemon only works on booted kernel (android or recovery) therefore not on bricked devices." Then how we can recover use the images if it's bricked...how to get the mobile back if it's bricked – Androidquery Aug 15 '21 at 08:51
  • as u you say aboout PM SM command executables that java is needed yes when I tried 3 years before it gave java error but I have seen many articles forums to use PM SM command without rooting in adb shell one I am sharing http://www.baatkar.com/2015/12/how-to-install-apps-directly-into-your.html may be PM command was inbuilt in android 4 kitkat and lower versions but not in android 5.1 is there any option to way in android 5.1 or android 6 through any other ways or hacks or tricks or scripts... – Androidquery Aug 15 '21 at 09:09
  • SM storage manager can java JDK installed on pc. some links batch file using Adb shell sm partition disk:179:160 mixed 25 but works in MI xiomi mobile unrooted android 5.1.1 or.android 6 https://miui.blog/any-devices/sd-card-auto-formatting-tool-windows-linux/. Another link which says it can be done in android 6 without rooting https://stackoverflow.com/questions/38044532/how-to-turn-a-portable-sd-card-into-internal-storage-via-adb-command. And another link https://www.bettermobileapp.com/article/12200839/Tutorial%3A+How+to+enable+adoptable+storage+on+an+MIUI+phone+with+Android+6 – Androidquery Aug 15 '21 at 09:30
  • Can SM PM run in modified old twrp recovery version with busybox. Is there any other recovery image which have java and service enabled like.CWM TWRP like other recoveries https://maheshtechnicals.com/2020/07/21/best-custom-recovery-for-android/ – Androidquery Aug 15 '21 at 09:43
  • Bro as busybox I thought will infuse PM SM SU or system commands to twrp or any image and will able to run java and programs as I readed that Busybox allows you or programs to perform actions on your phone using Linux (copied from Unix) commands. Android is basically a specialized Linux OS with a Java compatible (Dalvik) machine for running programs. Is there any other alternative of busy box which canbbe in built in twrp or CWM which make the temporary run java and other services to run PM SM commands in recovery mode – Androidquery Aug 15 '21 at 09:57
  • 1
    @Androidquery again I don't know what you are trying to do. None of the links you provided mention anywhere that pm or sm commands can be run from TWRP. We've already tried to explain that these are not merely commands (like those provided by busybox or toybox or any other standalone multi-command binary). They are simple CLI tools to conveniently access Android's services which are running in Java stack. It's the whole operating system, not a small program that you can run in recovery. What's the point of recovery if the whole Android OS is running inside it. You've been misguided. – Irfan Latif Aug 16 '21 at 11:07
  • @IrfanLatif bro recovery means to recover the os and troubleshoot I can understand safe mode.or recovery mode can't run all services on boot baa those services may be giving problems so it's made silent in safe mode or recovery mode but if there is no root previlages administrative rights to modify the setting the. How will admin troubleshoot modify settings in recovery and as java dependies files or android services as alecx bro replied can be individually run by mounting system. Is there any recovery or custom rom which is there which can enable or run services java to run SM PM – Androidquery Aug 24 '21 at 06:02