StackrootServer-side web stacks and the Linux systems that hold them, from config to debug.

Linux on Android

A Linux on Android emulator is a program that boots a real Linux kernel and a full root file system inside the phone, so a single install gives you a working Linux desktop with 3 to 4 distinct ways of running it: a system image, a container, a user mode kernel, or a chroot.

A smartphone running a Linux terminal emulator on its screen.

The choice decides how much of the Android system you touch, how fast the terminal runs, and whether the same setup survives a reboot. This page works through each option and what it is good for, from the one that survives a reboot to the one that needs no root at all.

The options split by how they reach a Linux environment. A distro image is a complete operating system; a container shares the phone kernel and runs Linux userspace on top; a user mode kernel emulates a second kernel inside the phone kernel. None of these are the same thing as the desktop Linux you would install on a server, and none is the same as Linux Mint, the user friendly distro that is not an option for phones because it is built for hardware that has an x86 CPU and a graphics card. The closest thing to that world, and the reason people reach for these tools, is running Linux distros that ship as .deb packages, the same packaging a LAMP server uses. If your goal is a web stack, the short answer is that a container image or a user mode kernel gets you the same tooling as Linux for the LAMP stack in about the same space, and you do not need to start from the harder path of Building Linux from scratch to get a working shell.

What a Linux emulator on Android actually does

A Linux emulator on Android gives you a Linux environment by one of 3 mechanisms. The mechanism is the whole decision, because it sets what runs, what is fast, and what survives.

System image

A system image is a whole distro in a file, such as Ubuntu Touch or a custom Debian image, and it boots like a phone OS. It runs a real kernel, so it is fast and complete, and it is the only option that can boot into a graphical desktop. It is the heaviest option and the one most likely to fight the Android system for the same hardware.

Container

A container is a Linux root file system running on the Android kernel, and it is the lightest of the 3. Terminals, the shell, and compiled programs run at full phone speed. It shares the phone kernel, so it cannot run a second kernel, and it needs a way to start, usually Termux. It is the default recommendation for a shell.

User mode kernel

A user mode kernel, such as the one inside the proot environment, emulates a second Linux kernel on top of the Android kernel. It needs no root and no boot file, which is why it is the most common starting point. The cost is that it is the slowest of the 3, because it translates syscalls instead of running them, so it feels slow on disk heavy work and on a phone below 4 GB of RAM.

Running Linux without root

To run Linux without root, you start in Termux and use proot-distro, because it is the option that works on an unmodified phone. The 3 steps are the whole install: open Termux, run the install command for your chosen distro, and log in. On a modern phone this takes about 5 minutes for the first boot. No reboot, no unlock, no recovery. The limit is that a phone that disables the external storage mount or that ships a locked bootloader will refuse the image, so the no root path works on most phones but not all of them. This is the option to pick when you want a working shell and nothing more.

Choosing a distro for the phone

To choose a distro, you match the distro to the amount of RAM and the kind of work, because the phone is a small machine and most desktop distros are not built for it. The short list below is the one that actually fits.

  • Debian, the stable base, the smallest image, and the one the rest are built from
  • Ubuntu, the most common image, with the largest package set and the heaviest base
  • Alpine Linux, the smallest footprint, at about 50 MB, and the one that uses the busybox toolset
  • Arch, the rolling release, for people who want the newest packages and accept the newer base

RAM sets the ceiling. A phone with 4 GB runs a container and a user mode kernel comfortably. A phone with 6 GB or more runs a system image without swapping. Below 4 GB, drop to the container and drop the desktop. A desktop environment, such as a VNC session with a 300 MB Xfce install, is a separate decision from the kernel and it is the thing that fills the phone, not the distro.

The LAMP stack on a phone

To run a LAMP stack on a phone, you install the 4 layers in the same order you would on a server: the Linux base, the Apache web server, the MySQL or MariaDB database, and the PHP interpreter. On a container image the install is one command per layer and the whole stack fits in under 500 MB, so it is a real environment, not a demo. On a user mode kernel the same stack runs but slower, because each process pays the proot syscall cost, and a phone below 4 GB will swap once the database starts. The honest use of this is a development and test box, where you commit code and push it to a real server, not a production box, because a phone is not a server and the data lives in a path that a factory reset deletes. If your real target is a desktop, the same image is the starting point for Linux for the LAMP stack on hardware that can carry it, and the container image is the version that runs here.

Performance, storage, and battery

To estimate performance, storage, and battery, you measure the 3 numbers that matter on a phone and set your expectations from them. A container runs at full phone speed and uses only the space of its packages. A user mode kernel runs at roughly half container speed on disk heavy work and uses the same space. A system image runs at full speed but uses the space of a desktop, in the 2 GB range, and it drains battery the fastest because it keeps a kernel and a desktop alive in the background. Storage is the hard limit: a 64 GB phone holds a container and a small stack, but a full desktop image plus the Android system will push the free space below 4 GB, which is the point at which Android itself starts to slow down. The rule is to keep the phone free of the desktop if the phone is under 128 GB.

Which option fits which task

To pick an option, you match the task to the mechanism, because each of the 4 options is the best answer to a different question. The table below is the decision.

OptionRoot neededSpeedUse for
ContainerTermuxFullShell, packages, a test LAMP stack
User mode kernelNoLowerA no root shell, a light desktop
System imageYesFullA full desktop on a phone with 6 GB RAM
Debootstrap chrootYesFullA clean base to build a custom image from

The default is the container for a shell and the user mode kernel when you will not touch root. The system image is the answer only when the phone has the RAM to carry a desktop. A Debian image from a debootstrap chroot is the base for building something custom, and it is the path that mirrors Building Linux from scratch at the package level, without the days of work the full build takes. Pick the mechanism first and the distro second, and the choice is the same as picking a server, except that the ceiling is set by the phone.

Where to go next