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: 381
 
286 posts
Join Date:Joined: Feb 2013
More
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.
Code:
apt-get install -y gcc build-essential libncurses5-dev libpam0g-dev libsepol1-dev libselinux1-dev
--EDIT-(30AUG2014)--
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:
Code:
cd
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 defconfig 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".
Code:
make defconfig
If all goes well, we now have a Makefile and are ready to compile:
Code:
make clean && make LDFLAGS=-static
Let "make" crank out the binary for a couple minutes. The extra variable we set before make is an environment variable 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".


5) Now let's copy it to /system/usr/bin to install for test usage.
Code:
cp ./busybox /sdcard
(Open a new terminal tab to get into Android Environment)
sysrw
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
sysro
PATH+=:/system/usr/bin
.. and done. Run some scripts and enjoy your static busybox!

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

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


***** Attached is a busybox static binary (v1.23.0 August 2014 snapshot, 374 applets included!, 1.37MB 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.
Code:
e.g.
> echo Hello | xargs -I{} echo {} world!

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

-------------------EDIT-2-(30AUG2014)----------------------
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, 1740KB 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.***


-------------------EDIT-3----------------------
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. 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 anyway for completeness of the snapshot build and because they work and are needed for a root.gz initrd or some chroot environments.)


-------------------EDIT-4-(06SEPT2014)----------------------

:
: 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:
Code:
cd /data/media
zip='/sdcard/Download/2014-09-06__arm-buildroot-linux-uclibcgnueabi.tar.lz.zip'
unzip -op "$zip" | lzip -d | tar -xf -
Then let's open up the "Complete Linux Installer" 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:
Code:
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!

**IMPORTANT Notes: 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; 12th October 2014 at 09:28 PM. Reason: syntax, update
The Following 8 Users Say Thank You to 7175 For This Useful Post: [ View ]