Saturday, October 28, 2017

installation - Where should I install Toybox?


I own a rooted Samsung Galaxy S Relay 4G running stock Android 4.1.2.


If you have Android 6.0 "Marshmallow" or better, then you have Toybox. This is a package of command-line tools, handy for advanced users who sometimes use a terminal emulator. Unfortunately, Android 4.1.2 does not include Toybox. Instead, it includes some other tools which aren't as nice to use.


Sometimes I use the terminal emulator written by Jack Palevich; other times I use adb shell from a laptop.




  1. Would it make more sense to install Toybox to my system partition, or to my data partition? Both partitions have far more than enough free space.




  2. When a command is provided both by Android and by Toybox, I want the Toybox version to win. On Linux, I might install Toybox to /home/unforgettableid/bin or /usr/local or /opt. Could you please suggest a sensible place for me to install Toybox (and its large collection of symlinks) on my phone?





[Edit: I wonder what the various BusyBox installers do. Also, I wonder how Android sets the PATH environment variable. As well, I also wonder whether or not there's a way for me to change that variable and to make my change persist across reboots. Finally, I wonder whether or not putting the Toybox tools first in my PATH would be likely to break things in non-obvious ways.]




Possibly related: "Android Folder Hierarchy".



Answer



If your Android version ships with Toybox and some Toybox symlinks, you can leave those in /system/bin. But, if you're installing Toybox yourself, it might be wisest to put the freshly-installed Toybox, and all its symlinks, in /system/xbin.


Let me explain why.


As Firelord points out in his answer: adb shell starts an interactive shell. But commands such as adb shell ls start a non-interactive shell. For performance reasons, non-interactive shells never read any config files. Because they don't read any config files, their search path is hardcoded.


It's nice to have Toybox available even to non-interactive shells; in fact, if it's unavailable to such shells, it can be confusing. So you definitely want to install Toybox to a location which is on the search path.



But you might not want to put the Toybox symlinks any earlier in the search path than Android's cp, ls, and other basic utilities. I've never checked, but I theorize that your version of Android might include apps which depend on quirks of the stock Android command-line utilities. To learn more, see this post, in which the Android command-line tools maintainer explains why Android had to stick with its non-Toybox ls for some months.


Most of the stock Android command-line utilities are in /system/bin. The only directory which falls later in the stock Android shell's search path is /system/xbin.


That is why you may want to put Toybox and all its symlinks in /system/xbin.




Tip: If you want, you can create a shell script which simply passes all of its parameters to Toybox. You can give this shell script an ultra-short name such as t. This makes it easier to request that your device should run a Toybox toy instead of a stock Android command. For example, to run Toybox ls, simply enter t ls.


No comments:

Post a Comment

samsung galaxy s 2 - Cannot restore Kies backup after firmware upgrade

I backed up my Samsung Galaxy S2 on Kies before updating to Ice Cream Sandwich. After the upgrade I tried to restore, but the restore fails ...