当 /system/bin/sh 丢失时,如何在 android 上获得可用的 adb shell?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21704211/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 04:57:05  来源:igfitidea点击:

How can I get a working adb shell on android when /system/bin/sh is missing?

androidshelladb

提问by Kirby Todd

I'm trying to build Android Jellybean from source for the Measy U2C HDMI stick. I've managed to build and install all the partitions (boot, kernel, misc, recovery, system...). The problem I'm having is that the system partition doesn't seem to be mounting. When I run

我正在尝试从 Measy U2C HDMI 棒的源代码构建 Android Jellybean。我设法构建并安装了所有分区(引导、内核、杂项、恢复、系统...)。我遇到的问题是系统分区似乎没有安装。当我跑

adb ls /system

I get the following output:

我得到以下输出:

000041ed 00000400 51301410 .
000041c0 00000800 00000003 lost+found
000041ed 00000000 00000001 ..

I'd like to adb shell into the device and try to debug why the system partition is not mounting but adb wants there to be a working shell in /system/bin/sh.

我想将 adb shell 插入设备并尝试调试系统分区未挂载的原因,但 adb 希望在 /system/bin/sh 中有一个工作 shell。

$ adb shell
- exec '/system/bin/sh' failed: No such file or directory (2) -

My question is, how can I get adb to look elsewhere for the shell command so i can get this working? Or is there an alternate way to remote into the device and debug this? There is a busybox install at /sbin/busybox so if I can just invoke that somehow, I can figure this out.

我的问题是,我怎样才能让 adb 在别处寻找 shell 命令,这样我才能让它工作?或者是否有另一种方法可以远程访问设备并进行调试?在 /sbin/busybox 有一个 busybox 安装,所以如果我能以某种方式调用它,我可以解决这个问题。

采纳答案by Chris Stratton

"SHELL_COMMAND" appears to be hardcoded in adb/services.c an unofficial copy of which is browsable at

“SHELL_COMMAND”似乎是在 adb/services.c 中硬编码的,其非官方副本可在以下网址浏览

https://github.com/android/platform_system_core/blob/master/adb/services.c

https://github.com/android/platform_system_core/blob/master/adb/services.c

Given that you are building from source you should be able to change this. But since you want to point it to a shorter path, you could also probably edit the binary and move up the terminating null.

鉴于您是从源代码构建的,您应该能够改变这一点。但是由于您想将其指向较短的路径,您也可以编辑二进制文件并将终止的空值向上移动。

Another approach to investigating your problem could be to see if you can get a working adb shell after booting to the recovery partition, and try manually mounting the problematic system partition there to see what errors result.

调查问题的另一种方法可能是查看在引导到恢复分区后是否可以获得工作 adb shell,并尝试在那里手动安装有问题的系统分区以查看导致什么错误。

Still another idea would be to put something in the startup scripts which launches an alternate shell listening on something which you could forward a socket to using adb - I'm not thinking of an obviousreason why setting up adb forwards would depend on the device side shell, but I haven't verified that by experiment or examining the code.

还有一个想法是在启动脚本中放一些东西,它会启动一个备用 shell,监听一些你可以将套接字转发到使用 adb 的东西——我没有想到一个明显的原因,为什么设置 adb 转发取决于设备端shell,但我还没有通过实验或检查代码来验证这一点。

If you wanted to get really clever, I believe that you could create a /system/bin containing a copy of shon the rootfilesystem. My recollection is that you can mount a filesystem over a non-empty directory - not sure if there would be an issue with open file descriptors to that directory, such as for the running shitself, but your mount is failing anyway, and you could try doing a manual mount elsewhere in order to debug that issue.

如果你想变得非常聪明,我相信你可以sh文件系统上创建一个包含副本的 /system/bin 。我的回忆是,您可以将文件系统挂载到非空目录上 - 不确定打开该目录的文件描述符是否会出现问题,例如运行sh本身,但无论如何您的挂载都失败了,您可以尝试在其他地方进行手动安装以调试该问题。