Project:Android/tarball

This guide covers the installation of Gentoo Prefix on Android devices by using a precompiled stage3 tarball.

The CPU on the target device should be at least a ARMv7-A with FPU, consult list of arm cores if in doubt. It would be no problem if the device CPU was advertised as dual core or more, or released later than 2011. The device list may be helpful, too.

A rooted device is needed to install Gentoo. Because most Android system have  option set for user writable partitions, which prevents applications to be executed. At the same time, the possibility to run Gentoo on non-rooted devices is being explored.

Busybox newer than 1.17 will be needed. If you don't have that yet, it is recommended to use Stericson's version

Prepare the Gentoo Directory
Gentoo on Android hardcodes the directory prefix (also known as EPREFIX ) at build time in many places, most notably the interpreter field of ELF and config files of portage. The precompiled stage3 tarball points its EPREFIX to. Root privilege is required either to make a new directory in or to mount an ext4 partition at. A minimum of 500MB free space is required, and 2GB is recommended.

can be located either in internal flash (often mounted as ext3/ext4/f2fs at ) or in a external SD card. To prepare the partitions on the SD card, follow the instructions on SDCard.

The tarball
Download the latest tarball (2016.10.26), and then extract it into the directory.

Tutorial
If you know how to do it, this section can be safely skipped.

Obtain an interactive root shell via adb, a terminal emulator (e.g. Termux), or dropbear:

Make sure to be in a directory of at least 500MB free space. Download and extract the tarball and verify:

Start Gentoo
In a shell, execute:

Failed to find the Prefix shell?
When the SHELL variable is defined to be something Prefix is unaware of, you will run into the following error:

To fix it, explicitly state that the Prefix bash should be used:

Beyond
Congratulations! Now you have a full functional Gentoo on your favorite Android device. As long as you are familiar with Gentoo, you can unleash its power immediately. If not, the sections of Working with Gentoo and Working with Portage of the Gentoo Handbook are your good starting points. Please also report your installation.

Gentoo ebuild repository
Before compiling anything, choose a mirror

Synchronize:

Symlink Hacks
Most of the ebuild still need, , to build. Before having a solution, we have to live with symlinks of these binaries back to. This is handled by the script.

ssh Server
Terminal emulators from Android GUI are generally not good at handling key bindings. The adb shell defaults to a 80x24 terminal. To have a full-featured terminal, a real server is necessary.

Put your ssh public key into. Be sure to set 700 and 600 permission bits to directory and  file respectively.

Out of Memory
Mobile devices do not usually have as much memory as workstations. Building big applications, such as or  could cost a lot of memory. The Android lowmemorykiller might kill the emerge building process if memory runs low.

Turn off Android
Once the ssh server is running, it is possible to turn off the Android runtime to save about 500MB of memory:

Further stop remaining Android services, for example, mediaserver and adbd:

Disable the Android lowmemorykiller:

Add Swap space
Adding a swap file or partition of similar size of system memory could ease up the memory shortage.

gcc and ld
Let and  to trade time for memory. Remove  from CFLAGS in, and put   and   into the LDFLAGS variable.


 * lets use pipes rather than temporary files for communication between the various stages of compilation.
 * normally optimizes for speed over memory usage by caching the symbol tables of input files in memory.  tells  to instead optimize for memory usage, by rereading the symbol tables as necessary. This may be required if  runs out of memory space while linking a large executable.