2

I would like to set up Canonical hosted Ubuntu Base image for arm on my Android phone.

I need a simple step by step answer on how to get started.

I would like to be able to use Ubuntu to run apps on my phone, without rooting it.

See this question for app installation.

Archisman Panigrahi
  • 28,338
  • 18
  • 105
  • 212
C.S.Cameron
  • 19,519

1 Answers1

4

Setting up Ubuntu in Termux involves three parts,

  1. Installing the base image
  2. Installing a DE (I will use XFCE in this answer, as it is user friendly but not heavy) and a VNC server
  3. (optional) Enabling sound, because VNC protocol does not support sound

Simplest method - If you don't want to get your hands dirty, install Termux, and simply download either Andronix (Website, GitHub) or AnLinux, and install Ubuntu 20.04 with them. These apps provide the scripts to download and extract the base image, to install desktop environments (e.g. XFCE), and setup the VNC server, which you simply need to copy-paste in Termux.

enter image description here enter image description here enter image description here

User interface of Andronix

How to use it?

When done, enter the command ./start-ubuntu20.sh to open Ubuntu, and the command exit to leave Ubuntu. Once you start Ubuntu, enter the command vncserver-start to start the VNC server (with the XFCE desktop), and the command vncserver-stop to stop it. (unfortunately, it is named ubuntu20, although it is actually Ubuntu 20.04, not Ubuntu Core 20. Once you get an idea how the script works, you can rename everything to ubuntu20.04, or anything else)

enter image description here Some of the entries (e.g. uptime) are wrong due to fake /proc entries, otherwise recent versions of Android would not let Ubuntu work.

How to access XFCE desktop with VNC Viewer?

Install a VNC viewer app in Android, e.g. VNC Viewer - Remote Desktop, or androidVNC. And open the address localhost:5901 to connect to the VNC Server. Tip: Choose quality: high, or 24-bit color (4 bpp) for better picture quality. Also, VNC Viewer - Remote Desktop supports the portrait as well as landscape mode very well. Other VNC viewers don't seem to have good support for the portrait mode.

xfce foliate Applications running in XFCE desktop. I installed Tango icon theme and Arc GTK theme

However, these apps will download the Ubuntu Base from their GitHub repo (where they have saved a copy), not from Canonical's website. All the scripts in these apps are available in their GitHub repositories under free licenses.

What does this script do?

This script downloads the Ubuntu rootfs image for the architecture of your device, and then sets it up to work with proot. Recent versions of Android (v10, v11) impose some restrictions, and that is why this script creates fake entries in /proc to fool Ubuntu and Android into functioning normally.


Enabling Sound

Andronix has made a script to enable sound. Run the following command in a termux (Not Ubuntu) shell.

 pkg install wget && wget https://andronixos.sfo2.cdn.digitaloceanspaces.com/OS-Files/setup-audio.sh && chmod +x setup-audio.sh && ./setup-audio.sh

To use sound

Start Ubuntu in a Termux shell, and open another Termux shell (don't open Ubuntu there). Run pulseaudio --start in the new Termux shell (not in Ubuntu), and now Ubuntu would be able to play audio. Audio demonstration - Youtube Video

Note that the file setup-audio.sh is cryptic (probably so that the competitor's of Andronix cannot use it), and its human readable form can be found here. It is so cryptic that people at Unix & Linux Stack Exchange thought that it could be a malware, but I have verified that it is not.


Slightly complex method - combine step 1. and 2. in one go (but download the images from Canonical, not from Andronix's GitHub repo).

Andronix has an automated script for downloading the rootfs, installing the DE, and then setting up the VNC server.

However, the Andronix script downloads the rootfs from their GitHub repo (a renamed version of the Ubuntu 20.04 (not 20.04.2) rootfs), not from Canonical's server.

We will modify the script to use the image from the Canonical's server instead. First install wget and nano in Termux (if already not installed), and then download the script.

pkg install wget nano

wget https://github.com/AndronixApp/AndronixOrigin/blob/master/Installer/Ubuntu20/ubuntu20-xfce.sh

Now open the script in Nano.

nano ubuntu20-xfce.sh

Change the contents of line 29 (use either Hacker's keyboard or scrcpy - see Tips:#6. Otherwise it is hard to edit in a mobile device),

wget "https://github.com/AndronixApp/AndronixOrigin/raw/master/Rootfs/Ubuntu20/focal-${archurl}.tar.gz" -O $tarball

to the following

wget "https://cdimage.ubuntu.com/ubuntu-base/releases/20.04/release/ubuntu-base-20.04.2-base-${archurl}.tar.gz" -o $tarball

Now save the file (ctrl + x), and run it.

sh ubuntu20-xfce.sh

Now head on to How to use it? and How to access XFCE desktop? (in previous parts of the answer). You can optionally follow Enabling sound to enable sound.


System requirements:

  • Recent versions of Termux work with Android 7 and higher. However, you can download slightly older versions of Termux which work with Android 5 and 6 (I have verified that they function correctly).
  • The Ubuntu rootfs + XFCE desktop consume ~ 1 GB of disk space, and ~ 300 MB of RAM.

Security

By default, Ubuntu rootfs cannot access the files in your Android phone. Data in Termux is isolated from other data in Android. And you can easily delete all files in Termux (including Ubuntu) by deleting the application data in Android settings. However, I bear no responsibility for any kind of issue arising from following this answer. The number of stars in GitHub would give you an idea about how many people are using these scripts. They are not malware.

Tips:

  1. One can change the screen resolution in VNCServer. I found that the resolution 700x1500 (in portrait mode) works very well in my 6.5 inch phone screen.
  2. Vanilla XFCE is boring, you can install your favorite icon themes and GTK themes.
  3. You can edit start-ubuntu20.sh/startubuntu.sh to access the internal storage and sdcard of your phone.
  4. By default, it uses the root account. However, you can create non-root account with su -s username, and give them sudo access.
  5. Choose quality: high, or 24-bit color (4 bpp) in the VNC Viewer for better picture quality.
  6. To edit files in Termux, install Hacker's Keyboard(Google Play, F-Droid) in Android, or use scrcpy to use your computer's keyboard for editing.
  7. Containerized apps (e.g. snaps and flatpak) are known not to work in this method. Quoting from the Andronix Docs

SNAP/Docker/Flatpak packages cannot be installed on any Linux environment. It is mainly due to two reasons. Primary being that both require kernel and bus modeules which are unavailable in PRoot environment and second being that both are mainly focused on Intel/AMD based architectures and not for arm architecture.

Feel free to edit this answer to make it better.

Archisman Panigrahi
  • 28,338
  • 18
  • 105
  • 212