Running Linux apps on Android without rooting your phone

Phone as Linux PC

Author(s):

UserLAnd lets you run Linux applications on your Android phone – all without replacing Android OS.

Smartphones are getting more and more powerful. Is it time to start thinking of a smartphone as something more like a tablet or a real computer? Is it possible to set up an Android phone with a full version of Linux – connected to a monitor, keyboard, and mouse?

Android OS is based on a modified version of the Linux kernel. In theory, a hardware-compatible Linux should be able to run on systems that Android OS runs on, but the Android developers at Google have added lots of proprietary drivers and bits. Additionally, the complexity of the communication hardware means that Android has drifted quite a distance from what we think of as a conventional Linux. Still, the power of the GPL means that Android OS is available to the community in source code form [1], and of course, developers all over the world are always tinkering with Linux to make it do useful things. A number of independent distros have evolved to provide mobile alternatives based on both the Linux kernel and the Android kernel (see the box entitled "Linux on Android Distros").

Linux on Android Distros

Several Linux distributions bill themselves as replacements for Android in the mobile space. These distros are all at various stages of completion – some work for certain phones but not others, and some are still in preliminary stages of development. Be sure to check the hardware compatibility list and read as much as you can about these alternatives before you install. Examples include projects such as:

  • Ubuntu Touch – a mobile version of Ubuntu. When Canonical backed off on their mobile initiative a few years ago, the UBports community took over the development and maintenance.
  • postmarketOS – a mobile OS based on Alpine Linux.
  • Sailfish OS – a commercial project that bills itself as "a European alternative to dominating mobile operating systems." Sailfish is based on the code from the old MeeGo mobile OS.
  • Mobian – a project promising Debian for mobile devices.

Another class of distros retains the Android base system but removes the proprietary parts, thus creating what is basically an Android-based system that is free of Google. Distros such as LineageOS, Replicant, /e/, and GrapheneOS are examples of open source, non-proprietary systems based on Android.

A full install of a mobile-based Linux on your smartphone provides a complete escape from Google's walled garden and offers access to the wide range of applications provided with Linux. But it also comes with some risks. You'll need to root your phone to replace the factory-installed OS, which will almost certainly void the warranty. If anything goes wrong, you might not be able to restore the original system.

This article describes a less radical alternative for running Linux on your Android. UserLAnd is a compatibility layer for Android OS that lets you run selected Linux distros on Android – all without rooting you phone. Of course, you are not really replacing Android, so if that is your goal, one of the alternative Linux mobile systems would be a better choice. But if you're looking for the Linux desktop, UserLAnd delivers it with minimal disruption. I'll show you what worked and what didn't – and I'll explore how the performance of a UserLAnd Linux smartphone compares to an average home computer.

A note on the hardware used in this study: My smartphone is powered by a 2018 Qualcomm Snapdragon 845 with 8 cores and 4GB RAM, including an Adreno 630 GPU. I also tested my daughter's phone, with the successor Snapdragon 855 and 6GB RAM plus an Adreno 640 GPU.

Monitor

If you want to embark on the adventure of converting your smartphone into a PC, the first step is to equip it with the necessary components. First comes the monitor. An Android smartphone with a USB-C port can output the screen image on a monitor or TV. However, not all recent Androids support this option; some – by Sony, for example – fail to identify the adapter.

But that does not mean you have to give up. If you don't have a working port, you can always fall back on wireless screen sharing with Google Cast or another similar tool. I have also had some good experiences screensharing (also known as screen mirroring) with Miracast on LG and Sony devices. Miracast is a Wi-Fi Alliance standard that connects two devices wirelessly via Wi-Fi Direct and was integrated into Android versions from 4.2 and up to 6.0. Google's Chromecast took the place of Miracast in later Android versions.

Mouse and Keyboard

You can easily connect a mouse or keyboard via Bluetooth or with a suitable adapter. I use a combined USB-C Type-C-to-HDMI-HDTV adapter, which offers one HDMI, one USB-C, and one USB-A 3.0 port. Because the adapter gets very warm, I added a passive heat sink which was available from another project.

I plugged a small dual distributor into the USB-A port, which also has space for a microSD card. I had to make the distributor narrower on the side to make room for the wide HDMI connector. A small extension or a differently designed distributor would also solve the problem if necessary. There are also adapters that offer four independent USB-A ports.

Software

Android 10 comes with a new desktop mode that it enables when an HDMI adapter is connected. Depending on the manufacturer, this feature works more (Samsung, Huawei) or less (LG) well. You can also disable desktop mode in favor of simple screen mirroring. No matter what you decide on, the LG smartphones always output Full HD at 60Hz. Many Android apps still have to be adapted to this new desktop mode (wide format).

In order to run conventional Linux applications on Android, you need to emulate a Linux runtime environment on the smartphone. Luckily, the Linux community has a solution: the UserLAnd project, which is hosted on GitHub [2]. The software is also available on F-Droid and in the Google Play Store, or you could also compile it yourself – more on that later. Rooting is not required, and you do not need Google services.

The display of the smartphone's screen content is handled by a VNC viewer, which also runs on the smartphone and then sends the image to the external monitor (Figure 1). Various viewers are available for this; I can recommend bVNC Free and RealVNC. The VNC session runs in the smartphone on the localhost address 127.0.0.1:5951.

Figure 1: The smartphone is ready for use in next to no time.

To completely fill the image area of the external monitor, you might have to set the format to 16:9. RealVNC v3.6.1 cannot cope with the Android 10 desktop mode at all, and bVNC always outputs an overly bright image; however, bVNC offers a well-scaled mouse pointer, at least in desktop mode. If the desktop is not completely visible or you want to enlarge a part of it, you can adjust with a two-finger gesture on the smartphone.

UserLAnd

The UserLAnd website offers the following description: "When UserLAnd first launches, it presents a list of common distributions and Linux applications. Clicking one of these then leads to a series of set-up prompts. Once these have been completed, UserLAnd will download and set up files required to start the task that has been selected. Based on the set-up, you will then be connected to your Linux distribution or application in a terminal or VNC viewing Android application."

UserLAnd offers a user-friendly (basic) installation of distributions such as Alpine, Arch, Debian, Kali, and Ubuntu. In addition, you can choose a desktop with LXDE or Xfce or just single applications like Firefox, LibreOffice, Octave, Gimp, and others.

The LXDE desktop environment is a good place to start, and it already comes with Firefox. If you were to install several desktop environments or a desktop and individual applications on top, UserLAnd would give each of these components its own runtime environment in its own session. This approach consumes a large amount of space, for example 850MB on the filesystem for Gimp alone. It makes more sense to opt for one desktop or one distribution and then add the applications internally, which would mean that Gimp needs only 80MB extra space.

If you decide to install a distribution and choose Ubuntu, the window manager twm first comes up with an xterm window. You can now install basic tools and the LXDE window manager (Listing 1, first two lines), which takes 20 to 40 minutes. Firefox is already included. Afterwards it makes sense to adjust the screen resolution to the monitor you are using. Edit the ~/.vncrc file with an editor like Leafpad or vi and then restart the session. It is also important to set the time zone (Listing 1, last line).

Listing 1

Basic Setup

$ sudo apt-get update
$ sudo apt-get install vim dialog tasksel lxde
$ sudo dpkg-reconfigure tzdata

Expansion

The Linux world is now accessible: lsb_release -a reports Ubuntu 18.04.5 LTS, and uname -a reveals the processor architecture – on the Snapdragon 845/855, aarch64. The first thing you might want to do is set the background image, the font size, or the theme.

On Android 10, the filesystem is not immediately accessible due to security policies. The feature is known as Scoped Storage and causes an app to only access app-specific directories. The UserLAnd project describes a way to import files into the Linux session [3]. It is also possible to bypass these security settings if you are aware of the risk.

To test access to the internal storage and the SD card(s), use the commands in Listing 2. In the storage/ directory, the SD card(s) and USB sticks should appear as directories with nine-digit numbers. emulated/0/ is usually the path to the internal storage. The DCIM directory is where the camera stores its photos and videos. You will also find other known directories, such as Android/data/.

Listing 2

Testing Storage

$ ls /host-rootfs/storage
$ ls /host-rootfs/storage/emulated/0

You could also research manufacturer-specific paths. However, on Android 10 or higher, you can't access the paths directly: Permission denied. You then either have to follow the hints in the UserLAnd tutorial [3] or look at the section in this article entitled "Building Your Own UserLAnd."

System expansion continues now with applications like an office package, C, Java, Gimp, VLC, or games (Listing 3, lines 1 to 4). OpenJDK 11 JRE is already included with LibreOffice. You can set up a variety of other programs just as easily, for example Octave, Gnuplot, or Inkscape (Figure 2).

Listing 3

System Expansion

01 $ sudo apt-get install libreoffice thunderbird
02 $ sudo apt-get install gcc g++ make
03 $ sudo apt-get install gimp vlc
04 $ sudo apt-get install xboard crafty scid fruit stockfish
05 $ sudo apt-get install cups hp-ppd hplip iputils-ping system-config-printer
Figure 2: With little effort, you can start and run many of the standard Linux applications.

First Difficulties with Eclipse and CUPS

Installing the Eclipse IDE for Java is unexpectedly difficult; sudo apt-get install eclipse does not return the desired results. On the Internet, the use of Snap is recommended, but I couldn't get Snap to work either. Fortunately, you can also download the precompiled IDE from Eclipse.org [4]. What is unpleasant is that you then have to copy it manually onto the filesystem (usually to /usr/lib/eclipse/ with a start link in /usr/bin/), and it does not add itself to the Start menu.

Printing with CUPS does not immediately work either. For a printer from HP, however, adding a few components is all it takes (Listing 3, line 5). In the test, printing failed at first. The cause of this failure was the /data/user/0/tech.ula/files/support/libcrypto.so.1.1 file. I solved the problem with the workaround shown in Listing 4. Annoyingly, Android restores the libcrypto.so.1.1 after each reboot, so the script has to run once per session. The UserLAnd project might fix this bug soon.

Listing 4

libcrypto.so Workaround

$ mv /data/user/0/tech.ula/files/support/libcrypto.so.1.1 /data/user/0/tech.ula/files/support/libcrypto.so.1.1_orig
$ cp /usr/lib/aarch64-linux-gnu/libcrypto.so.1.1 /data/user/0/tech.ula/files/support
$ sudo /etc/init.d/cups start

After you replace libcrypto.so.1.1, the final step is to configure system-config-printer. In addition, you need to install the tool again and launch it, and then you can conveniently bind (WLAN) printers. After that, the printer is available to many programs.

Sound, OpenGL, and Cameras

The UserLAnd project has a good tutorial on how to use the Android sound system [5]. You'll need to route the sound output via TCP to another Android process. First you have to install the Android Termux app. Add the first two lines from Listing 5 to ~/.bashrc. Then, in UserLAnd, install the pulseaudio package and add the last line from Listing 5 to .bashrc.

Listing 5

Additions to .bashrc

pulseaudio --start --exit-idle-time=-1
pacmd load-module module-native-protocol -tcpauth-ip-acl=127.0.0.1 auth-anonymous=1
export PULSE_SERVER="127.0.0.1"

Now the VLC player can also output sound – and many nice games will work too (see the box entitled "Games"). However, some games only display an error message because I have not yet been able to install OpenGL. I also couldn't get the Linux system to access the smartphone's cameras.

Games

I could only check a few of the large number of games available in Ubuntu. Some refuse to launch completely unless you set up sound output or OpenGL first. However, some games do run and are easy to install, including Pingus, Maelstrom, and Gnome Sudoku, as well as XBoard with the chess engines Crafty and Fruit (Figure 3).

Figure 3: Crafty and Fruit are strong chess engines, playing against each other here on XBoard.

Performance

Once you get Linux up and running on your Android phone, the next question might be, does it provide the performance you'll need to make it a viable option? You can test the performance with exactly the same benchmarks you would use on a real PC to compare the results directly. Sysbench requires small adjustments (see Listing 6).

Listing 6

Benchmarking with Adjustments

$ sudo apt-get install sysbench hardinfo
$ cd /usr/lib/aarch64-linux-gnu
$ sudo mv libc.so libc_script.so
$ sudo ln -s /lib/aarch64-linux-gnu/libc.so.6 libc.so
$ sysbench --threads=8 cpu run
$ sysbench --threads=8 memory run
$ sysbench --threads=1 --file-test-mode=seqwr fileio run
$ sysbench --threads=1 --file-test-mode=seqrd fileio prepare
[... Reboot required ...]
$ sysbench --threads=1 --file-test-mode=seqrd fileio run

The Hardinfo GUI tool depends on the VNC viewer. RealVNC is clearly the winner with 1,449 points compared with bVNC which only scores 930 points. Before running the seqrd fileio run test, you need to restart the Linux system to avoid unrealistic results due to caching. The Phoronix test suite [6] (Listing 7) also provides interesting results. I would also have liked to run the 3D graphics tests like unigine-heaven from this suite, but they are only available in binary format for x86_64 machines.

Listing 7

Phoronix Test Suite

$ sudo apt-get install unzip gdebi-core
$ gdebi Downloads/phoronix-test-suite_10.0.1_all.deb
$ phoronix-test-suite run sunflow

The surprise: An average family computer clearly outclasses a smartphone, but cannot totally outrun it. The 3D graphics performance is probably the only real drawback (Figure 4).

Figure 4: Smartphones can keep up with PCs for some tasks. The performance is sufficient for general office work, web browsing, and certain games that aren't too demanding.

Alternative Browsers

During the tests, Firefox did not run at times, for example, due to problems with fonts. You can install a different browser if you are having trouble with Firefox [7]. Not all of browsers are available for the ARM architecture, but Chromium and Epiphany work. For a successful start, you have to add the option --no-sandbox.

Building Your Own UserLAnd

Why compile UserLAnd yourself? First, compiling UserLAnd lets you work around the Android 10 storage policy. Second, you might have new ideas and want to collaborate on the project. If the motive is to disable the storage restrictions, you should definitely be aware of the risk of removing what is in principle a sensible security barrier.

You can download the source code of UserLAnd directly from GitHub [2] and then open it with Android Studio 4.x [8]. If you want to bypass the new storage policy, you can compile UserLAnd with an older Android SDK, such as version 28, which predates the restrictions. To install version 28, you have to edit the app\gradle.build file in three places (Listing 8).

Listing 8

Changes to app\gradle.build

compileSdkVersion 28
targetSdkVersion 28
versionName "2.7.2-Android9"

As usual, you'll need to set your own device as a developer device and install the software APK from the PC with adb [9] or via the file manager in the device. Annoyingly, you have to uninstall the official UserLAnd version beforehand (due to the different or missing signature) and thus lose all data the Linux system set up.

Limits and Problems

Probably the most annoying weakness of the UserLAnd solution for Linux on Android is the limited number of open windows (three to six), which can even decrease during the session. UserLAnd then reports

Maximum number of clients reached. Failed to open display.

What is also very annoying is that the connection to the VNC server occasionally breaks down. Then you lose all your unsaved data because you can't connect to the session anymore.

Some VNC viewers had trouble transferring keystrokes for non-English character sets. AndroidVNC does not have the problem, but it is no longer maintained and has many other shortcomings. RealVNC's PC viewer, on the other hand, transfers the key combinations correctly.

Wireless mice often react clumsily. This seems to be a hardware problem that cannot be solved via the energy-saving settings. It is also annoying that you cannot shut down a Linux session and have to stop it in Android instead.

On the positive side, the filesystem can be exported and used as a backup – very handy for transfers to other devices, but keep in mind that backing up the filesystem can take some time.

Conclusions

The age of full-fledged pocket-sized computers has arrived. Once a few teething problems have been solved, these computers can be used at home without restrictions. Smartphones can already handle many basic applications, but you still need modern desktop computers or laptops for special tasks and 3D games with high performance and resource requirements. I also own a smartwatch with a dual-core CPU and 4GB RAM, and I am already wondering whether I'll be able to get a Linux distribution running on it.

The Author

Dirk Ambras works at Airbus as an IT expert. He used to work for Siemens as an operating system developer for cell phones in the areas of graphics, games, and Java. The fun of working with embedded devices is something he has never lost.