Or Continue to Thread: [GUIDE] [BIN] Busybox 1.23.0 S…
Find Your Device:
25th August 2014, 04:35 AM   |  #1  
7175's Avatar
OP Senior Member
Thanks Meter: 424
308 posts
Join Date:Joined: Feb 2013
About Busybox: busybox.net/about.html
More on Busybox: busybox.net

This is just for anyone who wants to try, and especially those without access to a PC.

: --------------- BUILD STEPS --------------

Things we'll need besides your phone:
- "Android Terminal Emulator" app
- "Complete Linux Installer" app , I also recommend trying "linux deploy" for more advanced usage
- internet/wifi
- latest "busybox" source

1) We need to get Ubuntu or Debian booted for a sufficient build environment (kali linux works well too). I've used them all on Android but I like the better stocked terminal in the Ubuntu images. I used the app "Complete Linux Installer" which is free and works beautifully, very simple and easy. In the app you want to follow the short instructions to download an Ubuntu image, rename it to ubuntu.img, and place it in a folder named ubuntu in /sdcard. Then hit menu in the app and click the terminal screen icon that says "Launch". An Ubuntu terminal will now open in Android Terminal Emulator. Super quick and easy.

2) Let's download GCC and ncurses-devel (libncurses5-dev) as some crucial build environment tools.
apt-get install -y gcc build-essential libncurses5-dev libpam0g-dev libsepol1-dev libselinux1-dev
For Selinux compatibility and loginutils, we need to also download a few extra packages. Already included in the code above.

3) Now the cool thing about this chroot Ubuntu environment is that we still have access to the sdcard to transfer files between Android environment and the chroot jail. Extract your downloaded busybox source to your Ubuntu home with something like:
tar -xf /sdcard/Download/busybox*bz2
cd busybox*

4) Now we can build busybox statically. The first thing we do is generate a Makefile by running "make" with a "defconfig" (default configuration file) Usually you will run "./configure" with other programs, but busybox compiles more like a kernel, so it uses a config which has a huge checklist of options.

(After successfully compiling busybox, we can go back and customize the .config; this entails that for each "CONFIG ..." line we see, we can uncomment it and mark it "y" or "n" to configure some option... This can be more easily done from a terminal busybox menu interface with "make menuconfig". You just need to crank font down to 7 or use telnet/ssh)
Skip "make defconfig" if you use a customized ".config".
make defconfig
If all goes well, we now have a Makefile and are ready to compile:
make clean && make LDFLAGS=-static
Let "make" crank out the binary for a couple minutes. The extra variable we set after make is to compile statically. When compiling is complete we'll have a few different busybox binaries at the root of the source directory. We use the one named "busybox" since we're not debugging.

5) Now let's copy it to /system/usr/bin to install for test usage.
cp ./busybox /sdcard
(Open a new terminal tab to get into Android Environment)
mkdir -p /system/usr/bin
cp -f /sdcard/busybox /system/usr/bin
chmod 0555 /system/usr/bin/busybox
/system/usr/bin/busybox --install -s /system/usr/bin
.. and done. Run some scripts and enjoy your static busybox!

**Commands to run if you have compile errors:
apt-get build-dep busybox
apt-get install -y build-essential
apt-get -f update
dpkg --configure -a

: --------------- DOWNLOADS --------------

***** Attached are flash installers for busybox (v1.23.0 stable, non-SELinux, 374 applets included!, ~1.1MB size) or busybox (v1.23.0 stable, SELinux, 386 applets included!, ~1.6MB size) *****
Since it's up-to-date it has some nice extras most people haven't seen like a "-I" option for xargs! Yes, that is correct, busybox xargs has its testicles back.
$ echo Hello | xargs -I{} echo {} world!
> Hello world!

: ---------- UPDATES ----------

Got a Selinux-enabled busybox attached now. This means Selinux flags are integrated into applets like ls, id, ps, tar, etc, and there are now 12 extra Selinux applets to give a total of 386 applets, ~1.6MB in size. The previous one is more portable, but this one can completely replace toolbox and gives you Selinux control for Android 4.4+. Plus it's pure maxed-out awesomeness.

***I've also attached the .config files for each busybox I've compiled, so anybody can remake them (from their phone!) as I've posted. You just need to download and extract the .config file to the root of your busybox source directory and type "make".***

YashdSaraf has made some very useful flash zips to install either the non-selinux- or selinux-enabled busybox 1.23.0 via recovery. Installation replaces the stock busybox in /system/xbin. I've attached the zips he made to the end of this OP.

(**Note: Thought I'd mention that there will be a handful of applets that don't work in "Android" environment such as su(don't worry this isn't linked with the installer) Part of this is because of the way Android's default file structure is an amputated modified version of linux. With almost all of them, slight modifications to environment and file structure can be made to get them to work. This is just normal behaviour of busybox in android. The su and init applets shouldn't be used in Android though. I keep them compiled into the binary anyway for completeness of the build and because they work and are needed for a root.gz initrd or some chroot environments. It also doesn't hurt keeping them compiled in. You just have to remember not to link them when installing busybox.


: How to compile against(using) uclibc for a smaller binary!!

Download the attached arm-linux-uclibcgnueabi toolchain package that I pre-compiled. Extract to /data/media:
cd /data/media
unzip -op "$zip" | lzip -d | tar -xf -
Then let's open up the "Complete Linux Installer" or "Linux Deploy" terminal.
To use the toolchain with a busybox build, we just need to specify the parameter CROSS_COMPILE which is a prefix to the compile tools. So if you extracted the toolchain to /data/media, you will use:
make clean && make LDFLAGS=-static CROSS_COMPILE=/android/data/media/arm-buildroot-linux-uclibcgnueabi/bin/arm-buildroot-linux-uclibcgnueabi-
When you're done you should have a busybox binary with 374 functions with size around 1.1MB. That's a 20% decrease in size from using the standard glibc toolchain!

- The toolchain can't be used with lollipop since it's not compiled with -fPIC. II'll fix this later. Busybox is fine since it's static, it's just the toolchain I uploaded.
- Selinux-enabled busybox .config errors out when building using the uclibc toolchain; I think this is a lack of support issue. In the "Complete Linux Installer" app you'll need to add the mount "/data/media" in options. This gives you access to it as "/android/data/media", very very useful for extra space needs.
Last edited by 7175; 6th January 2015 at 09:23 AM. Reason: syntax, update
The Following 11 Users Say Thank You to 7175 For This Useful Post: [ View ]