Search code examples
androidshelladb

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


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

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


Solution

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

    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.

    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 obvious reason why setting up adb forwards would depend on the device side shell, but I haven't verified that by experiment or examining the code.

    If you wanted to get really clever, I believe that you could create a /system/bin containing a copy of sh on the root filesystem. 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 sh itself, but your mount is failing anyway, and you could try doing a manual mount elsewhere in order to debug that issue.