3

I'm trying to install some commands on an android device (namely file and a better version of ls), and I'm looking for the ARM binaries for it (namely the 5TE architecture) but I'm unable to find a place to download them. Googling things like "arm ls binary" or "ls binary" are giving me everything but what I want.

Is there a single place to find the binaries?

  • Have you looked into crosscompiling your own? – Bratchley Dec 16 '14 at 14:45
  • 1
    Have you checked BusyBox? It is available for android. – kirill-a Dec 16 '14 at 14:49
  • file is not part of GNU coreutils – Stéphane Chazelas Dec 16 '14 at 15:26
  • @Bratchley I hadn't, but I might have to. @kirill-a I'll look into that. @Stephane I know, I was asking for ls in particular, and hoped there might be a place where all "low level" commands like that are kept – Mitch Dec 16 '14 at 15:40
6

The least painful way to install Linux utilities on an Android device is to install a whole distribution in a subdirectory. “Normal” distributions (Debian, Arch, Fedora, etc.) provide binaries that are dynamically linked with Glibc, which Android doesn't provide. They need to be executed with the loader (/lib/ld-linux*.so) of Glibc.

A simple way to set up such a system is to use Debian's deboostrap to build an initial Debian directory tree, transfer it to the Android device, and from then on install packages with apt-get and other standard Debian tools. There are a couple of pages on the topic on the Debian wiki: ChrootOnAndroid, HotwoDebianInAndroid.

  1. First, install Debootstrap. On Debian or derivative, just install the debootstrap package. On some other Linux or other Unix variant, just grab the debootstrap source tarball or check it out from Git: it's only a shell script and supporting data files.

  2. Determine whether your device supports hardware floating point. If it doesn't, replace armhf by armel below. You can tell by checking /proc/cpuinfo under Android (or anything else using a Linux kernel): you must have ARMv7 (or ARMv8) with the features thumbee and vfpv3.

  3. If you don't already have it, install BusyBox on the Android device. While it isn't strictly necessary, it'll come handy below. You can retrieve the busybox-static Debian binary package, extract the BusyBox executable with ar p busybox-static_*_armhf.deb data.tar.gz | tar -xzf - ./bin/busybox, and transfer the busybox binary to the Android device. Below, I assume that BusyBox is located at /vendor/bin/busybox.

  4. If your Android device is capable of mounting an SD card that's formatted as ext2/ext3/ext4 (or any other filesystem that supports unix permissions, i.e. not FAT), mount the SD card on your Unix PC and run the following command as root:

    debootstrap --arch=armhf --foreign wheezy /media/sdcard/debian http://http.debian.net/debian
    

    If not, run the following command as root (or under fakeroot, if you have it):

    sh -c 'debootstrap --arch=armhf --foreign wheezy /tmp/debian http://http.debian.net/debian && tar -zcf /tmp/debian.tar.gz -C /tmp debian'
    

    Now you need to transfer /tmp/debian.tar.gz to your Android device. You can do it over adb (adb push /tmp/debian.tar.gz /) or any other way that works for you, then unpack the tarball (use the BusyBox tar):

    tar -zxvf /debian.tar.gz
    
  5. Set up a comfortable environment to run Linux programs. The easy way is to run them in a chroot. I assume that the Debian system is located at /media/sdcard/debian and that you have BusyBox. Create a shell script:

    #!/vendor/bin/busybox sh
    LINUX_ROOT=/media/sdcard/debian
    alias bb=/vendor/bin/busybox
    unset LD_LIBRARY_PATH PATH SHELL
    export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    # Bind-mount filesystems if not already done
    for d in /dev /media /proc /sys; do
      bb grep -q " $LINUX_ROOT$d " /proc/mounts || bb mount -o rbind "$d" "$LINUX_ROOT/$d"
    done
    for d in /data /system; do
      if ! bb grep -q " $LINUX_ROOT$d " /proc/mounts; then
        mkdir -p "$LINUX_ROOT/android/$d"
        bb mount -o rbind "$d" "$LINUX_ROOT/android/$d"
      fi
    done
    exec bb chroot "$LINUX_ROOT" /bin/bash "$@"
    

    Make this script executable and put it in /vendor/bin or anywhere else on the Android PATH. Before you can fully enjoy the Linux installation, you need to finish debootstrap's job: in the chroot, run

    /debootstrap/debootstrap --second-stage
    
1

While the GNU page does not seem to provide ARM binaries for the coreutils project, I managed to come across this page, which somehow provides compiled binaries for version 8.14.

I downloaded it myself, and the ls binary provides the following metadata:

$ file ls
ls: ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), stripped

Which should fit for an ARM system. Now, as Bratchley said, the best way is probably to compile coreutils for an ARM target. As far as I'm concerned, I compiled coreutils directly from an ARM system (Raspberry Pi, ARM6L), and all compatibility checks went fine.

  • Note that to run these binaries, you'll need Glibc, which Android doesn't provide. – Gilles Dec 16 '14 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.