KBOX Linux emulator for Android

KBOX2 is a BusyBox based Linux emulator for Android running inside Terminal Emulator for Android (Android App).

Installation
Run another Android App OneBox Package Managerinstaller once to create a kbox2 subdirectory under the terminal emulator application containing all necessary emulator software, providing simplified versions of a lot of Linux commands.


 * 1) There also exists a manual installation script, see http://kevinboone.net/kbox2_install.html
 * 2) Why is the Linux emulator installed below the subdirectory of the terminal emulator? Because the Android security model dictates that every app can only access its own executables and data files...

Restrictions
This should work for any off-the-shelf Android device. Your device needs not to be (and should not be) rooted.

As a consequence only user mode programs are allowed. TCP/IP privileged ports lower than 1024 cannot be used. For the same reason SUID programs are technically impossible (e.g. ping, route).

Since Android does not have real usernames, any program in the emulation needs to use fake usernames like "kbox" etc. Also remember when using e.g. ssh to use real usernames.

Run the emulator
By default the terminal emulator uses the standard Android shell /system/bin/sh.

To automatically run the emulator shell, execute: /data/data/jackpal.androidterm/kbox2/bin/kbox_shell

Preferences &rarr; SHELL &rarr; Command line
 * 1) You can automate the execution of this shell by replacing the default /system/bin/sh - shell via:

Libraries
The emulator has a primitive Android Bionic C-library.

The emulator is a BusyBox implementation, so it only has basic Linux functionality.

If you need the full Linux commands, then you better install http://kevinboone.net/coreutils_8.22_kbox.deb

Package manager
Additional packages can be installed using dpkg. See download section.

Processor
uname -a Linux localhost 3.0.31-963581 #2 SMP PREEMPT Mon Mar 4 18:06:43 KST 2013 armv7l GNU/Linux

Remark that my dual-core mobile has more power than my Raspberry Pi...

Storage
df 2>/dev/null Filesystem            Size   Used   Free   Blksize /                    1.18G   996M   211M   4096 /dev                  402M   112K   401M   4096 /dev/shm              402M  0.00K   402M   4096 /system              1.15G   972M   208M   4096 /storage/sdcard0     1.08G   996M   111M   4096 /storage/extSdCard   14.8G  11.0G  3.78G   32768

Host root directory
ls /android_root acct                      init.samsung.rc            res cache                     init.samsung.usb.rc        root config                    init.samsungskomer.rc      sbin d                         init.samsungskomer.usb.rc  sdcard data                      init.trace.rc              storage default.prop              init.usb.rc                sys dev                       lib                        system efs                       lpm.rc                     tmp etc                       mnt                        ueventd.goldfish.rc fstab.samsungskomer        modemfs                    ueventd.rc init                       preload                    ueventd.samsung.rc init.bt.rc                 prerecovery.rc             ueventd.samsungskomer.rc init.goldfish.rc           proc                       var init.rc                   recovery.rc                vendor

Top
top Mem: 802212K used, 21148K free, 0K shrd, 28696K buff, 158356K cached CPU0: 0.0% usr 50.0% sys  0.0% nic 50.0% idle  0.0% io  0.0% irq  0.0% sirq CPU1: 0.0% usr  0.0% sys  0.0% nic  100% idle  0.0% io  0.0% irq  0.0% sirq Load average: 24.42 12.60 6.26 1/1301 21656

PID PPID USER     STAT   VSZ %VSZ CPU %CPU COMMAND 18828    2 root     SW       0  0.0   0  9.3 [kworker/u:3] 2020 1667 system   S     640m 79.5   0  1.8 system_server 2219 1667 radio    S     506m 62.9   0  0.9 {m.android.phone} com.android.phon 20475    2 root     SW       0  0.0   0  0.9 [kworker/u:0] 1687 1680 root     S    45604  5.5   0  0.4 /system/bin/admsrv 1659    1 radio    S    12124  1.4   0  0.4 /system/bin/rild 14849 1667 u0_a126  S     486m 60.4   0  0.3 {LocationService} com.google.andro 20537    2 root     SW       0  0.0   0  0.3 [kworker/0:0] 3737 1667 u0_a144  S     524m 65.1   0  0.2 {.mobilesecurity} com.avast.androi 21460 15736 u0_a146 R     1308  0.1   0  0.2 top

Cleanup after installation
The KBOX2 Linux emulator is installed as an option into the Terminal Emulator for Android.

Especially when you are short of RAM you can easily gain 12,5 MB of (temporary) installer files once the emulator has been installed and is working fine.

If needed later, you can perform a fresh installation. Remember to save your user & data files on an external SD card.


 * Deinstall OneBox Package Manager


 * Remove directory /storage/sdcard0/com.monami_ya.onebox.manager (and kbox2-base-installer) via My Files

cd /data/data/jackpal.androidterm ls -l drwxrwx--x   2 u0_a146  u0_a146       4096 Apr 10 19:43 app_HOME drwxrwx--x   3 u0_a146  u0_a146       4096 Apr 11 21:00 cache drwxrwxr-x   2 u0_a146  u0_a146       4096 May  1  2013 installer-image drwxrwxr-x  10 u0_a146  u0_a146       4096 Apr 10 23:39 kbox2 -rwxr-xr-x   1 u0_a146  u0_a146    2714309 Apr 10 19:54 kbox2-base-installer drwxr-xr-x   2 system   system        4096 Apr 10 19:40 lib -rwxr-xr-x   1 u0_a146  u0_a146        142 Apr 26  2013 setup drwxrwx--x   2 u0_a146  u0_a146       4096 Apr 10 20:22 shared_prefs
 * Remove remaining installer files:

df 2>/dev/null Filesystem            Size   Used   Free   Blksize /storage/sdcard0     1.08G  1.04G  45.8M   4096

rm -rf installer-image/ setup kbox2-base-installer

df 2>/dev/null Filesystem            Size   Used   Free   Blksize /storage/sdcard0     1.08G  1.03G  56.0M   4096

Set the execution path
If you want to add user executables, you might need to change the exeuction path. Remember that the SD card cannot be used for bin files.

PATH='/bin:/sbin:/usr/bin:/usr/local/bin:/android_root/system/bin' vi /etc/profile ... PATH&#61;"${PATH}:/home/kbox/bin" cd /storage/extSdCard/kbox


 * Add the double quotes, or you would not be able to login any more!
 * /sbin and /usr/bin are symbolic links to /bin

Telnet daemon

 * Install kbox-login and utelnetd from KBOX2 download using dpkg.


 * Manually run the utelnetd daemon from the console.
 * Telnet via e.g. PuTTY

Remember to use port 10023 (no root access): telnet 192.168.1.41 Trying 192.168.1.41... telnet: Unable to connect to remote host: Connection refused

telnet 192.168.1.41 10023

Compile native ARM programs
Use gcc compiler; see download.


 * Requires 100 MB of RAM storage.
 * Currenlty only version 4.7 is supported

SSH client and server
Prerequite: kbox-login wget http://kevinboone.net/dropbear_0.52_kbox.deb dpkg -i dropbear_0.52_kbox.deb

Provides the client commands ssh and scp, and the /bin/ssh_daemon.sh ssh daemon.

To login to a remote system:

ssh ruser@...

To start the ssh server: /bin/ssh_daemon.sh &

To login: ssh -p 10022 ruser@192.168.1.41

Other packages
Other packages you can download from http://kevinboone.net/kbox2_downloads.html.

More packages exist... see http://kevinboone.net

Security
When running daemon programs, you can better stop the emulator before leaving your intranet...

Uninstalling the terminal emulator
Uninstalling the Terminal Emulator for Android will also remove the KBOX2 and any of its data files. Therefore it is adviced to use an (external) SD card for storage. Do not use /home/kbox to store data or program sources.

No privileged commands
No root access, no SUID, no system ports.

Consequence: any network tool requiring root privileges do not work.

ping www.pi.be ping: permission denied (are you root?)
 * ping, tcpdump, route, etc. do not work

route add -net 192.168.0.0/16 dev wlan0 route: ioctl 0x890b failed: Operation not permitted

Use higher (non privileged) port numbers.
 * TCP/IP ports below 1024 cannot be used by user (root required)

SD card
No exec rights; so you can only store executable programs in RAM.

Slow response
Sometimes slow response: Might be caused by to few free RAM.
 * Radio streaming interrupted
 * Console commands slowly responding (command entry echo; execution delay)

Telnet session fails
Timeout?
 * Login again...

Network commands fail
telnet 192.168.1.47 telnet: can't connect to remote host (192.168.1.47): No route to host

route -n Kernel IP routing table Destination    Gateway         Genmask         Flags Metric Ref    Use Iface 0.0.0.0        192.168.1.1     0.0.0.0         UG    0      0        0 wlan0 0.0.0.0        192.168.1.1     0.0.0.0         UG    383    0        0 wlan0 192.168.1.0    0.0.0.0         255.255.255.0   U     383    0        0 wlan0 192.168.1.1    0.0.0.0         255.255.255.255 UH    0      0        0 wlan0 192.168.1.30   192.168.1.1     255.255.255.255 UGH   0      0        0 wlan0


 * Why is 192.168.1.0/24 not working?
 * Why is there a 192.168.1.30/32?

Routing problems which cannot be manually solved, because route requires root access.

Symbolic links not supported
ln -s a b ln: b: Function not implemented Symbolic links not allowd on vfat file system: mount |grep extSdCard /dev/block/vold/179:97 /storage/extSdCard vfat rw,dirsync,nosuid,nodev,noexec,noatime,nodiratime,uid=1000,gid=1023,fmask=0002,dmask=0002,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0