Where to download binaries of coreutils

binary

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?

Best Answer

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
    
Related Question