I want to compile (through make) on my Android phone. I have root access.

I have almost all the things set up. But there's this hitch. All the configure files have a shebang of #!/bin/sh. I can execute them by $SHELL configure I've also set $CONFIG_SHELL But some configure files execute other shell scripts and they give the /bin/sh: no such file or directory.

I'm thinking about creating a symlink /bin/sh -> /system/bin/sh I've read somewhere that the root file system is the ramdisk and any changes to it will require to be done in the init.rc file. So, if I want to accomplish this I'd need to first create a directory 'bin' then make a symlink 'sh' in it. I doubt that ln will work in init.rc.

I have this another idea. Make a directory 'bin' somewhere preferably in Terminal IDE's (I'm using that) data directory. Then create a symlink in there sh -> /system/bin/sh. Then create 'bin' in / through and use mount the first bin to /bin through init.rc

Thirdly, I can just mkdir bin and cp /system/bin/sh /bin/sh

Also, all of these methods will fail and result in boot failure if any of the source directories cannot be found.

I want to know which method will be more safe and if there exists a safer alternative?

  • Make a Nandroid backup before doing your things. That's the most safest approach!
    – Firelord
    Aug 2 '15 at 13:48
  • @Firelord That's a given for me. I've bricked my phone far too many times for not to make a nandroid backup. Aug 2 '15 at 14:11

@vishalbiswas For that to work you may also need to export PATH and LD_LIBRARY_PATH

you can actually script out your required set up and push that script to xbin so it be run as executable. so you would be looking at something like this for setup name the script to what works for you

mount -o rw,remount /
mkdir /bin && mkdir /lib
chmod 755 /bin /lib
mount -o bind /system/bin /bin
mount -o bind /system/lib /lib
export PATH=/bin && export LD_LIBRARY_PATH=/lib

the above is loose, tinker with it a little, now to close it out mostly reverse order

umount /bin && umount /lib
mount -o ro,remount /

the directories /bin and /lib should vanish on reboot since they are living in ram and you shouldn't need to unset PATH and LD_LIBRARY_PATH as when you close your terminal instance those variables should die with it.

The other approach is to set up a no-frills chrooted arm linux in your external sd card's second partition. I use debian and customed my init.environ.rc as follows

# set up the global environment
on init
    export PATH /sbin:/vendor/bin:/system/sbin:/system/bin:/system/gcc/bin:/system/xbin:/bin:/usr/bin:/usr/sbin
    export LD_LIBRARY_PATH /system/lib:/system/gcc/lib:/system/vendor/lib
    export ANDROID_ROOT /system
    export ANDROID_ASSETS /system/app
    export ANDROID_DATA /data
    export ANDROID_STORAGE /storage
    export ASEC_MOUNTPOINT /mnt/asec
    export LOOP_MOUNTPOINT /mnt/obb
    export BOOTCLASSPATH [blah blah jars blah xD ]

# Debian CHROOT
    export DEBIAN_ROOT /debian
    export TMPDIR /tmp
    mount -t proc none /debian/proc
    mount -t sysfs none /debian/sys
    mount -o bind /dev /debian/dev
    mount -o bind /proc/net /debian/proc/net
    mount -t devpts none /debian/dev/pts

in this approach your file manager should read your chroot partition files directories and all without issue. i use total commander.

EDIT- i forgot the necessary entry in fstab it goes as follows, again adjust to your device's scheme

/dev/block/platform/msm_sdcc.2/by-num/p2              /debian      ext4    rw,errors=panic                               wait

Here is the tutorial i learned to do the above from http://whiteboard.ping.se/Android/Debian

Do look for a fairly current distro image though. As long as you don't try to delete a bind mounted directory without first UNMOUNTING IT [ i have never ever ever done that btw] you won't accidentally delete your system.

  • I'm currently doing it manually by creating those folders. While your approach looks cool, I'm not looking for a complete chroot environment. Though, I will be partitioning my sd with ext4. I am in the process of automating it with a script like you suggested. Aug 4 '15 at 7:08
  • @vishalbiswas hi again, this will not be a "full" chroot. terminal work only! =) personally i think wanting the whole X setup VNC or otherwise , doesn't make sense on these device. Once you get set up, you'll be happy. If you are using LP you may need to keep in mind that any binaries you compile must be PIE (position independent executable) pass -fPIE at the gcc command line. -fPIC should work as well.
    – moonbutt74
    Aug 4 '15 at 11:56
  • I meant about the Debian chroot Aug 4 '15 at 13:22
  • @vishalbiswas I'm talking about the chroot, it is terminal only, no xserver no vnc it isn't needed. When you need to switch over open your terminal, export your path, export PATH=/bin:/sbin:/usr/bin:/usr/sbin:$PATH chroot /debian /bin/bash and you are at terminal in debian
    – moonbutt74
    Aug 4 '15 at 14:28

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