Guide: Installing and Running a GNU/Linux Environment on Any Android Device
As many of you may well be aware, the Android operating system is powered by the Linux kernel underneath. Despite the fact that both Android and GNU/Linux are powered by the same kernel, the two operating systems are vastly different and run completely different types of programs.
Sometimes, however, the applications available on Android can feel a bit limited or underwhelming, especially when compared to their desktop counterparts. Fortunately, you can get a GNU/Linux environment up and running on any Android device, rooted or non-rooted. (The following instructions assume a non-rooted device.)
For those power users on Android tablets, or other Android devices that have large screens (or can plug into a bigger screen), the ability to run desktop Linux software can go a long way towards increasing the potential that an Android device has for productivity.
Setting Up GNU/Linux on Android
To get a GNU/Linux environment set up on your Android device, you only need to install two applications from the Google Play store: GNURoot Debian and XServer XSDL. After you do that, you will only need to run a small handful of Linux commands to complete the installation.
GNURoot Debian provides a Debian Linux environment that runs within the confines of the Android application sandbox. It accomplishes this by leveraging a piece of software called proot, a userspace re-implementation of Linux’s chroot functionality, which is used to run a guest Linux environment inside of a host environment. Chroot normally requires root access to function, but by using proot you can achieve similar functionality without needing root privileges.
GNURoot comes with a built-in terminal emulator for accessing its Debian Linux environment. This is sufficient for running command-line software, however, running graphical software requires an X server to be available as well. The X Window System was designed to have separate client and server components in order to provide more flexibility (a faster, more powerful UNIX mainframe could act as the client to X server instances running on much less powerful and less sophisticated terminals).
In this case, we will use a separate application, XServer XSDL, that GNURoot applications will connect to as clients. XServer XSDL is a complete X server implementation for Android powered by SDL that has many configurable options such as display resolution, font size, different types of mouse pointer behavior, and more.
2. Run GNURoot Debian. The Debian Linux environment will unpack and initialize itself, which will take a few minutes. Eventually, you will be presented with a “root” shell. Don’t get misled by this – this is actually a fake root account that is still running within the confines of the Android application sandbox.
apt-get update and
apt-get upgrade to ensure you have the most up-to-date packages available on your system. Apt-get is Debian’s package management system that you will use to install software into your Debian Linux environment.
4. Once you are up-to-date, it’s time to install a graphical environment. I recommend installing LXDE as it is simple and light-weight. (Remember, you’re running Debian with all the overhead of the Android operating system in the background, so it’s best to conserve as many resources as you can.) You can either do
apt-get install lxde to install the desktop environment along with a full set of tools, or
apt-get install lxde-core to only install the desktop environment itself.
5. Now that we have LXDE installed, let’s install a few more things to complete our Linux setup.
• XTerm – this provides access to the terminal while in a graphical environment
• Synaptic Package Manager – a graphical front-end to apt-get
• Pulseaudio – provides drivers for playing back audio
apt-get install xterm synaptic pulseaudio to install these utilities.
6. Finally, let’s get the graphical environment up and running. Start XServer XSDL and have it download the additional fonts. Eventually you will get to a blue screen with some white text – this means that the X server is running and waiting for a client to connect. Switch back to GNURoot and run the following two commands:
export DISPLAY=:0 PULSE_SERVER=tcp:127.0.0.1:4712 startlxde &
Then, switch to XServer XSDL and watch the LXDE desktop come up onto your screen.
I recommend putting the above two commands into a shell script so that you can easily restart LXDE if you close the session or if you need to restart your device.
Installing Linux Applications
Congrats! You’ve successfully gotten Debian Linux up and running on your Android device, but what good is running Linux without apps? Fortunately, you’ve got a massive repository of Linux applications at your fingertips just waiting to be downloaded. We’ll use the Synaptic Package Manager, which we installed earlier, to access this repository.
Click the “start” button at the lower-left hand corner, click Run, and then type
synaptic. The Synaptic Package Manager will load. From here, simply press the Search button at the top and then type the name of the application you’d like to install. Once you’ve found an application, right click it and select “Mark for Installation”. When you are finished marking packages, click the Apply button at the top to start the installation. Uninstalling packages follows the same procedure, except by right-clicking and selecting “Mark for Removal” instead.
Of course, since this isn’t a real Linux installation but rather a Linux environment running on top of, and within the constraints of, Android, there are a couple of limitations to be aware of. Some applications will refuse to run or will crash, usually due to the fact that some resources that are usually exposed on GNU/Linux systems are kept hidden by Android. Also, if a regular Android app can’t do something, then usually a Linux application running within Android can’t as well, so you won’t be able to perform tasks such as partitioning hard drives. Lastly, games requiring hardware acceleration will not work. Most standard everyday apps, however, will run just fine. Some examples include Firefox, LibreOffice, GIMP, Eclipse, and simple games like PySol.
I hope that you find this tutorial useful. While I personally performed these steps on my Google Pixel C, you can do this on most Android devices. Preferably on a tablet device with access to keyboard and mouse peripherals, of course. If you already run a GNU/Linux distribution on your Android device, let us know what you are using it for below!