我应该在哪里安装Toybox? -- installation 领域 和 file-system 领域 和 command-line 领域 android 相关 的问题

Where should I install Toybox?


简体版||繁體版
3
vote

问题

中文

我拥有一个rooted三星galaxy s继承4g运行股票和roid4.1.2。

如果您有Android 6.0"Marshmallow" 或更好,那么您有 toybox 。这是一包命令行工具,为有时使用终端仿真器的高级用户提供方便。不幸的是,Android 4.1.2不包括Toybox。相反,它包括一些与使用不太好的工具。

有时我使用杰克帕维奇写的终端仿真器;其他时候,我使用 adb shell 从笔记本电脑。

  1. 将toybox安装到我的系统分区或我的数据分区时会更有意义吗?两个分区都有足够的自由空间。

  2. 当Android和ToyBox提供命令时,我希望Toybox版本获胜。在Linux上,我可能会将Toybox安装到 /home/unforgettableid/bin /usr/local /opt 。您能否在我的手机上建议我建议一个明智的地方,以安装Toybox(以及它的大量符号链接)?

[编辑:我想知道各种busybox安装程序是否是多少。此外,我想知道Android如何设置路径环境变量。同样,我也想知道是否有办法改变该变量并使我的更改跨重启。最后,我想知道是否在我的路径中首先将玩具箱工具放在我的路径中可能会以非明显的方式打破东西。]


可能相关:"Android文件夹层次结构"

english

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".

        

回答列表

5
 
vote

我应该在哪里安装Toybox?

将Toybox安装到我的系统分区或我的数据分区时会更有意义吗?

取决于。如果您不打算再次恢复出厂重置手机,可以选择数据分区,否则,选择"系统分区" 。

当Android和Toybox提供命令时,我希望Toybox版本获胜。

path 变量包含包含可执行二进制文件的目录的位置。如果您决定保留单独的目录,请为您的符号链接,配置$ path以首先将命令搜索到目录中。如果它找到一个,它将执行它。

在Linux上,我可能会将Toybox安装到 /home/unforgettableid/bin /usr/local /opt 。您能否在手机上建议我为我安装Toybox(以及它的大量符号链接)的明智的地方?

所有这些位置都不存在于Android。由于您使用的是Android 4.1.2,我假设您将使用具有FAT文件系统格式化的外部SD卡。 Symlinks不适用于FAT文件系统(至少在FAT32或VFAT上至少),因此您最好的选择是在 /data /system

或者,您可以在外部SD卡下进行图像,使用Android内核支持的文件系统(通常ext2 | ext3 | ext4)格式化图像,然后将其安装在环回模式下的任何位置。我虽然没有尝试过这种方法。

我想知道各种Busybox安装程序是否如何

busybox(由Stericson )放置 Busybox 二进制进入 /system/xbin 并创建 symlink for它的小程序在同一目录下的二进制文件。

也,我想知道Android如何设置路径环境变量。同样,我也想知道是否有办法改变该变量并使我的更改跨重启持续存在

我不知道何时android设置$ path。但是,您使用的shell很可能是具有配置文件。

  • mksh mirbsd korn shell ; 默认shell 在Android上)有一个配置文件 data/misc/wifi/wpa_supplicant.conf0 在<代码> data/misc/wifi/wpa_supplicant.conf1 。您可以在那里设置$ path,更改将持续跨重启。
  • for bash shell,配置文件 data/misc/wifi/wpa_supplicant.conf2 位于 data/misc/wifi/wpa_supplicant.conf3

似乎两个文件都是仅适用于互动会话,所以如果您尝试使用adb来访问未在<代码>置于Toybox或其符号链接data/misc/wifi/wpa_supplicant.conf4 ,<代码> data/misc/wifi/wpa_supplicant.conf5 ,<代码> data/misc/wifi/wpa_supplicant.conf6 ,<代码> data/misc/wifi/wpa_supplicant.conf7 或<代码> data/misc/wifi/wpa_supplicant.conf8 ($ path中的默认位置),您将收到"命令:未找到" 错误。这是因为默认的$路径将被使用。

我还没有找到这个问题的解决方案,但请参阅此答案下面的评论。

无论如何,让我们现在安装Toybox。


如何在Android设备上安装Toybox?

注意:解决方案假定您的android rooted,即 adb 是在PC中设置的,并且您的设备连接到带有 USB调试启用。

安装到系统分区

如果选择标准位置,则不需要在$ PATH中的变化。 BusyBox更喜欢 Abcdefghijklmnabcdefghijklmn19

  • 重新安装在 RW 模式中的系统分区。 如果需要,请参阅无法重新汇编/系统在RW
  • 警察 toybox 二进制文件到 network0 并为其提供可执行权限。 (为其他二进制文件设置的默认权限是 network1 。)

    可以使用 chmod

      network2  
  • Toybox 二进制提供的各种工具创建符号链接。这取决于你如何创建它们。

    我使用了一个非常简单的方法,但它需要一个* nix system

      network3  

    我在这里正在做的是执行 toybox 二进制文件,用新行替换空白空格,以便在新行中显示每个工具。稍后我删除了最后一行(它在输出中是空白的),删除运输返回方便的 Toybox 二进制创建一个符号链接。

    如果您在PC中没有* nix操作系统,则可以使用此方法:

      network4  

完成!您的Toybox及其小程序已准备好执行。

安装到数据分区

  1. network5 下创建一个目录( network6 hustheforth)
  2. toybox 二进制文件复制到 network7 并为其提供可执行权限。 (为其他二进制文件设置的默认权限是 network8 。)

      network9  
  3. Toybox 二进制提供的各种工具创建符号链接。这取决于你如何创建它们。

    我使用了一个非常简单的方法,但它需要一个* nix system

      network={     ssid="Telekom"     key_mgmt=NONE     priority=42 } 0  

    只有位置发生了变化,其余过程是一个在系统分区中安装的一个过程

  4. 编辑默认shell的配置文件并添加

      network={     ssid="Telekom"     key_mgmt=NONE     priority=42 } 1  

    这将导致shell调查 network={ ssid="Telekom" key_mgmt=NONE priority=42 } 2 首先执行二进制,如果可用。

完成! 享受您的玩具箱及其小足。

 

Where should I install Toybox?

Would it make more sense to install Toybox to my system partition, or to my data partition?

Depends. If you don't plan to factory reset the phone ever again, you can choose data partition, else, choose system partition.

When a command is provided both by Android and by Toybox, I want the Toybox version to win.

The PATH variable contains the location of the directories containing executable binaries. Should you decide to keep a separate directory for your symlinks, configure $PATH to search for a command into your directory first. If it finds one, it will execute it.

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?

All those locations don't exist for Android. Since you're using Android 4.1.2, I suppose you would be having your external SD card formatted with a FAT filesystem. Symlinks don't work on FAT filesystems (not on FAT32 or vfat at least) so your best bet is to install under /data or /system.

Alternatively, you can make an image under your external SD card, format that image with a filesystem supported by your Android's kernel (often EXT2 | EXT3 | EXT4), then mount it in the device anywhere in loopback mode. I've not tried this method though.

I wonder what the various BusyBox installers do

Busybox (by Stericson) places the busybox binary into /system/xbin and creates symlink for its applets to its binary under the same directory.

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

I do not know when Android sets up $PATH. However, the shell you're using would most likely be having a configuration file.

  • mksh (MirBSD Korn Shell; the default shell on Android) has a configuration file mkshrc in /system/etc. You can set $PATH there and the change would be persistent across reboots.
  • For bash shell, the configuration file is bashrc located under /system/etc/bash.

It appears that both files are meant for interactive sessions only, so if you attempt to use adb for accessing a Toybox or its symlink which is not placed under /sbin, /vendor/bin, /system/sbin, /system/bin or /system/xbin (the default locations in $PATH), you would receive a "COMMAND: not found" error. This is because the default $PATH would be used instead.

I've not found a solution for this problem yet, but see the comments below this answer.

Anyhow, let's install Toybox for now.


How do I install Toybox on an Android device?

Note: the solution assumes that your Android is rooted, that adb is setup in PC, and that your device is connected to a PC with USB debugging enabled.

Installation into system partition

No change in $PATH is required if you choose a standard location. Busybox prefers /system/xbin.

  • Remount the system partition in rw mode. If required, see Can't remount /system in rw
  • Copy the toybox binary to /system/xbin/ and give executable permission to it. (The default permissions set for other binaries is rwxr-xr-x.)

    You can do so using chmod

    adb shell su -c "chmod 755  /system/xbin/toybox" 
  • Create symlinks for various tools accessible by toybox binary. It is up to you how you create them.

    I used a very simple method, but it requires a *nix system

    adb shell toybox | sed 's/\ /\n/g' | head -n -1 | tr -d '\r' | while read line; do adb shell su -c 'ln -sf /system/xbin/toybox "/system/xbin/$line"'; done 

    All I'm doing here is executing the toybox binary, replacing the white-spaces with a new line so that each tool shows up in a new line. Later on I'm removing the last line (it was blank in output), removing carriage return conveniently put by adb, and then for each line of output I'm creating a symlink to toybox binary with the name of the tool, in the same directory.

    You can use this method if you don't have a *nix OS in PC:

    adb shell su toybox | toybox sed 's/\ /\n/g'| toybox sed '$d'| while read line; do  toybox ln -sf /system/xbin/toybox /system/xbin/$line; done 

Done! Your Toybox and its applets are ready to be executed.

Installation into data partition

  1. Create a directory under /data (/data/my_bin henceforth)
  2. Copy the toybox binary to /data/my_bin and give executable permission to it. (The default permissions set for other binaries is rwxr-xr-x.)

    adb shell su -c "chmod 755  /system/xbin/toybox" 
  3. Create symlinks for various tools accessible by toybox binary. It is up to you how you create them.

    I used a very simple method, but it requires a *nix system

    adb shell su -c "/data/my_bin/toybox" | sed 's/\ /\n/g' | head -n -1| tr -d '\r'| while read line; do adb shell su -c "ln -sf /data/my_bin/toybox '/data/my_bin/$line'"; done 

    Only the location has changed, the rest of the procedure is alike to one followed for installation in system partition

  4. Edit your default shell's configuration file and add

    PATH=/data/my_bin:$PATH  

    This would cause the shell to look into /data/my_bin first and execute the binary, if available.

Done! Enjoy your Toybox and its applets.

 
 
     
     
0
 
vote
vote
最佳答案
 

如果您的Android版本用Toybox和一些Toybox Symlinks船舶,则可以将其中的 /system/bin 留出。但是,如果您自己安装了Toybox,则将新鲜安装的Toybox和所有符号链接均最为妙,在 /system/xbin 中。

让我解释原因。

因为答案中的fireelord指出: adb shell 启动一个交互式shell。但是 adb shell ls 等命令启动一个非交互式shell。对于性能原因< / a>,非交互式shell永远不会读取任何配置文件。因为它们没有读取任何配置文件,他们的 search path 硬编码。< / p>

很高兴有玩具箱甚至是非交互式炮弹;事实上,如果它对这种贝壳不可用,它可能会令人困惑。所以你肯定想将Toybox安装到搜索路径上的位置。

但您可能不希望在搜索路径中提前将Toybox符号链接放在Seand android的 cp ls 等基本实用程序。我从未检查过,但我理论您的版本的Android可能包含应用程序,依赖于库存Android命令行实用程序的怪癖。要了解更多信息,请参阅此帖,其中android命令行工具维护者解释为什么Android必须坚持其非Toybox Abcdefghijklmnabcdefghijklmn6 几个月。

大多数库存Android命令行实用程序是 /system/bin 。唯一跌落于股票的Android shell搜索路径的目录是 /system/xbin

这就是为什么您可能想要将Toybox放入 /system/xbin 中的所有符号链接。


提示:如果需要,您可以创建一个shell脚本,只需将其所有参数传递给Toybox。您可以为此shell脚本提供超短名称,例如 /system/xbin0 。这使得您可以更轻松地要求您的设备应该运行Toybox玩具而不是Stock Android命令。例如,要运行Toybox Abcdefghijklmnabcdefghijklmn11 ,只需输入 /system/xbin2

 

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.

 
 
     
     

相关问题

3  手动安装Split APK  ( Install split apk manually ) 
最近我必须知道一个名为split apks的东西,并发现切片作为无效的apk文件,只有基础是。不幸的是,这意味着通常的默认包安装程序无法处理此操作,因此我必须知道另一件名为SAI的东西,一个拆分APK安装程序,能够与或没有root工作。然而,好奇,我想知道它是如何在内部工作的,并开始做一些研究。我没有走得太远,但我必...

9  如何在SD卡上找到交换分区的路径名?  ( How to find the pathname of the swap partition on sd card ) 
作为 < / a>警告,你不应该在错误的分区上启用交换,或者您可以销毁您的手机: 在我们进一步进一步之前好的!之前的手机有一个分区布局,其中MMCBLCK0是SDCard(外部)我们的手机使用MMCB1CCK1用于外部SD。这很重要,因为如果使用应用程序,它可能会预设使用mmcblck0作为交换分区。使用此设置将导...

24  是否可以从命令行激活“USB系列”Android设置?  ( Is it possible to activate the usb tethering android setting from the command ) 
我想在Bash脚本中激活"USB系列" ,因此有可能使用 adb shell 来运行命令行以更改一些Android设置? edit1 : 以下命令打开所需的设置,但不单独更改任何内容: am start -n com.android.settings/.TetherSettings 我发现的 tethe...

3  我应该在哪里安装Toybox?  ( Where should i install toybox ) 
我拥有一个rooted三星galaxy s继承4g运行股票和roid4.1.2。 如果您有Android 6.0"Marshmallow" 或更好,那么您有 toybox 。这是一包命令行工具,为有时使用终端仿真器的高级用户提供方便。不幸的是,Android 4.1.2不包括Toybox。相反,它包括一些与使用不太好...

0  如何修复“mount:'remount' - >'/ system':没有这样的文件或目录”?  ( How to fix mount remount system no such file or directory ) 
angler:/ # mount -o rw, remount /system mount: 'remount'->'/system': No such file or directory 1|angler:/ # 当我在手机中尝试在Kali Linux中: root@kali:~# mount -o ...

7  如何使用adb更改“首选网络模式”而无需重新启动?  ( How to change preferred network mode using adb without reboot ) 
我正在尝试将手机的(cm 12,股票4.2,rooted)首选的网络模式从"gsm / wcdma" (0)更改为"WCDMA仅" (2),反之亦然(可以有其他模式也是)仅使用命令行。基于这个答案我可以使用命令将相关变化与 Settings.db 进行相关变化: adb shell su settings...

1  是否可以在Android上安装“IPRUTE2”?  ( Is it possible to install iproute2 on android ) 
我试图在googleSource的页面中使用 git clone ,但它没有多大。我想从包中使用 ss 命令,但我不知道如何安装它。我的手机是手臂32位。 ...

1  如何调查内存使用量?  ( How do i investigate the memory usage ) 
我是一个micromax a74,with(rooted)Android 4.2.2。最近我面临着一些应用程序的崩溃并开始分析RAM的使用。 设置&gt; apps&gt;运行没有帮助: 有时我发现只有2 MB免费! 我想知道哪个应用程序正在消耗内存? 我还尝试过 top -n 1 -m 8 : 但我...

24  是否有任何命令行SSH客户端可用于rooted Android手机?  ( Are there any command line ssh clients available for rooted android phones ) 
我当然有connectbot,但我正在寻找我可以脚本的东西。 编辑:要澄清这里,我对来自终端的脚本不感兴趣。我要做的是以自动/计划方式运行SSH命令。 tasker和locale执行是Cron的等同器,我只需要的是'ssh'命令从 脚本运行 。 ...

3  如何为rooted设备安装其他终端命令的捆绑?  ( How to install bundles of additional terminal commands for rooted devices ) 
我最近扎根了HTC野火S设备并闪过Android 4.1.2 AOKP果冻豆类自定义ROM。一个好处是我现在可以使用终端。 我有点习惯于在台式机上使用终端仿真器,但从中从未在Android设备上做过。我注意到没有找到一些命令,例如: $ tree /system/bin/sh: tree: not found ...




© 2022 it.wenda123.org All Rights Reserved. 问答之家 版权所有