KBOX Linux emulator for Android

From eLinux.org
Revision as of 04:02, 17 October 2015 by Geertivp (talk | contribs) (How to Access the Android file system)
Jump to: navigation, search

KBOX2 is a BusyBox based Linux emulator for Android running inside Jack Palevich's Terminal Emulator for Android or ConnectBot (Android terminal emulators).

With this solution you have a (basic) Linux system in the pocket. You can even compile programs.

Installation of KBOX2

KBOX2 is used on Adroid 4 systems. Run another Android App OneBox Package Manager installer 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.

18px <translate> Note:</translate>

  1. There also exists a manual installation script, see KBOX2 installation; you can use this script to install KBOX in the ConnectBot application directory /data/data/org.connectbot
  2. Why is the Linux emulator installed below the subdirectory of a terminal emulator? Because the Android security model dictates that every app can only access its own executables and data files...

Installation of KBOX3

KBOX3 is used on Adroid 5 systems. Here we document using the ConnectBot terminal emulator.

cd /data/data/org.connectbot

Now you can follow the installation instructions on KBOX3 installation.

Create a symbolic link:

ln -s kbox3/bin/kbox_shell kbox

Now start the emulator manually:


To install more packages, see KBOX3 downloads.


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).

Hidden files remain invisible, even when using ls -lad *

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.

The external SD card is vfat mounted, so specific Linux features can't be used. It can however be used as a storage device, e.g. /storage/extSdCard/Download can be used to store installation kits.

Run the emulator

By default the Jack Palevich's terminal emulator uses the standard Android shell /system/bin/sh.

To automatically run the emulator shell, execute:


18px <translate> Note:</translate>

1. You can automate the execution of this shell by replacing the default /system/bin/sh - shell via:
Preferences → SHELL → Command line
2. An alternative shell is not available from the ConnectBot terminal emulator. In this case you can use a symbolic link.


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 [[#Coreutils|]]

Platform resources


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...


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


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
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
  • Remove remaining installer 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
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

How to

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.


vi /etc/profile
cd /storage/extSdCard/kbox

18px <translate> Note:</translate>

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

Access the Android file system

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

Install additional packages

Additional packages can be installed using dpkg. You can download installation packages from KBOX2 or KBOX3 downloads using wget.

Download install and run

An example:

cd /storage/extSdCard/Download1
wget http://kevinboone.net/file-5.22_kbox3.deb
dpkg -i file-5.22_kbox3.deb
file file-5.22_kbox3.deb
file-5.22_kbox3.deb: Debian binary package (format 2.0)

18px <translate> Note:</translate>

  1. Or /sdcard/Download

Telnet daemon

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

Remember to use port 10023 (no root access):

telnet: Unable to connect to remote host: Connection refused
telnet 10023

Compile native ARM programs

Use gcc compiler; see download.

18px <translate> Note:</translate>

  • 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@

Coreutils package

The coreutils package provides Linux commands with more options than the standard BusyBox versions.

Other packages

Other packages you can download from KBOX2 or KBOX3 downloads.

Other packages
Package Description
ftp FTP client
gawk awk script processor
nano Text editor
Perl Perl script processor
rsync Remote file synchronisation
strace Command tracing

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


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

KBOX and Android versions

KBOX installation scripts for different Android systems
Version Notes
KBOX Android
KBOX1 2 Obsolete
KBOX2 4 Current version1
KBOX3 4.2 or 5 For the newest Android 4/5 devices2,3,4

18px <translate> Note:</translate>

1. The KBOX2 manual installation script works with other terminal emulators like ConnectBot; you need to install in directory /data/data/org.connectbot
2. Android Lollipop (5.0.2) fails to run the KBOX3 emulator:
fakechroot: dlopen: undefined symbol: dlopen

After the standard installation you need to manually overwrite libfakechroot.so. Copy http://www.kevinboone.net/libfakechroot_fix_dlopen_1.so to /sdcard/Download

cd /sdcard/Download
cat libfakechroot_fix_dlopen_1.so > /data/data/jackpal.androidterm/kbox3/lib/libfakechroot.so
3. The KBOX2 manual installation does not work on Android 5 since only position independent (PIE) executables are allowed...
4. Android 5 does not allow terminal emulators to write to external SD card storage /storage/extSdCard. Reading is not a problem. (you could use the Android or Windows explorer program instead to transfer files from /sdcard)

Known problems

Uninstalling the terminal emulator

Uninstalling the Terminal Emulator for Android will also remove the KBOX2 and any of its data files without any warning. 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?)

Use the built-in Android ping command:

which ping


rm /bin/ping

which ping


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

(no solution here)

  • TCP/IP ports below 1024 cannot be used by user (root required)

Use higher (non privileged) port numbers.

SD card

The external SD card is a vfat file system. Therefore exec rights are not available; so you can only store executable programs in RAM.

Slow response

Sometimes slow response:

  • Radio streaming interrupted
  • Console commands slowly responding (command entry echo; execution delay)

Might be caused by to few free RAM.

Telnet session fails


  • Login again...

Network commands fail

telnet: can't connect to remote host ( No route to host
route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface         UG    0      0        0 wlan0         UG    383    0        0 wlan0   U     383    0        0 wlan0 UH    0      0        0 wlan0 UGH   0      0        0 wlan0
  • Why is not working?
  • Why is there a

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 allowed on the 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

External links

Older versions: