I was looking for a way to run
busybox on a Motorola RAZRi with an x86 Intel Atom processor but I couldn't find any Android app from the Google play market that was running on the phone (when running any busybox command nothing happened and I was immediately getting the prompt back).
So I decided to cross-compile busybox for Android myself. Now you will find other posts claiming to have done so by downloading an ARM-cross compiler from codesourcery.com but I had two problems with that approach:
- I needed an x86 cross-compiler and,
- I read various complaints of people not being able to run various busybox commands with this method.
Cross-compiling busybox with the Android NDK
My only option was to use the Android NDK itself, since it comes with full support of the ARM, x86, and MIPS architectures. I ended up manually configuring busybox by eliminating any module that would not cross-compile due to missing header files and/or libraries in the Android NDK.
To cut the story short, I managed to cross-compile busybox using the Android NDK compilers for both ARM and x86 architectures (I didn't try MIPS since I don't have a device with a MIPS processor to test the resulting binaries).
To build busybox yourself, download the
busybox-android.patch,
busybox-android.config, and
build.sh script and run the latter with the following options:
$ build.sh <android NDK dir> <NDK toolchain> <Android ABI> <Toolchain compiler version> <Android Native API Level> <Install prefix>
The script will download the busybox version 1.21.0 source code, apply the busybox-android.patch and configure busybox for the right architecture.
For example if you have your Android NDK installed under /home/android/android-ndk-r8d, to build busybox for the Intel x86 architecture call the build.sh script like the following:
$ build.sh /home/android/android-ndk-r8d x86-4.7 x86 4.7 android-14 /home/android/busybox-x86
and the cross-compiled busybox binaries will be installed under the /home/android/busybox-x86 directory. Similarly if you want to build busybox for the ARM processor, run the following:
$ build.sh /home/android/android-ndk-r8d arm-linux-androideabi-4.7 armeabi-v7a 4.7 android-14 /home/android/busybox-arm
Download busybox binaries
The busybox binaries for x86 (compiled using the above procedure), can be found
here.
Installing busybox
The above procedure was tested with release r8d of the Android NDK and for both ARM and x86 devices.
Pre-requisites
Installation Procedure
To install busybox on an x86 Android (rooted) device, I run the following commands with the phone connected to the computer via USB:
# logon to the phone and become root to mount the /system file system read/write
$ adb shell
shell@android:/ $ su -
shell@android:/ # mount -o rw,remount -t ext4 /dev/block/system /system
shell@android:/ # chmod 0777 /system/xbin
shell@android:/ # exit
shell@android:/ $ exit
$
then change directory to the location of the busybox binary file and push it to the phone:
$ adb push busybox /system/xbin/
log back on as root and change permissions appropriately:
$ adb shell
shell@android:/ $ su -
shell@android:/ # chmod 755 /system/xbin/busybox
shell@android:/ # chmod 0755 /system/xbin
shell@android:/ # exit
shell@android:/ $ exit
$
Installing busybox on an ARM Android device is very similar, only the mounting instruction line changes:
$ adb shell
shell@android:/ $ su -
shell@android:/ # mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
shell@android:/ # chmod 0777 /system/xbin
shell@android:/ # exit
shell@android:/ $ exit
$
$ adb push busybox /system/xbin/
$ adb shell
shell@android:/ $ su -
shell@android:/ # chmod 755 /system/xbin/busybox
shell@android:/ # chmod 0755 /system/xbin
shell@android:/ # exit
shell@android:/ $ exit
$