Skip to main content

Running postmarketOS on Android Termux proot without flashing a custom rom

Categories   Smartphone Termux Tutorial
Tags   PostmarketOS Termux GNOME KDE Plasma PinePhone
Table of Contents

閱讀中文版

Running postmarketOS and Phosh on Android phone without rooting or flashing a custom ROM.

I’ve taken the unofficial and weird approach of running postmarketOS on Termux Proot, so that we can run mobile Linux on Android.

A video demonstration. Phosh + postmarketOS runs on Sony Xperia 10 V Android 14.

1. Motivation
#

Why do I do this? To explore the possibilities of running mobile Linux on an Android phone. And we needed a desktop environment designed for touchscreens.

It’s my personal wish to run mobile Linux on my Sony Xperia 5 & 10 series, but not many people have ported postmarketOS for them, and I didn’t succeed myself. So I’m just using Termux to taste the sweetness of the mobile Linux OS. I would like to share this highly experimental method of running postmarketOS on Android with you.

postmarketOS is a GNU/Linux system designed for out-of-season mobile phones. Based on Alpine Linux, it has full Linux functionality and is able to run Linux pc applications, and it has become one of the most popular distro choice among PinePhone users. However, postmarketOS is not available for all Android phones, see postmarketOS pmbootstrap installation instruction. In order to port a postmarketOS to an Android phone, you need to pacth the Linux kernel a lot, and since many drivers are not compatible between Android and Linux, it is more difficult to create a postmarketOS ROM than to port LineageOS. Even if you finally get it up and running, there will be lots of missing proprietary drivers, which makes the system unpleasant to use.

Moreover, the entry barrier for installing postmarketOS is very high, and for many mobile phone users, they can’t even unlock the bootloader, so it’s impossible to flash a custom ROM. This makes Termux a good option to consider, as it allows you to run Linux containers on your Android without rooting, and display the Linux container X server screen with Termux X11. The first question we have to ask is whether pmbootstrap can be run on Termux. According to this Github issue, chroot is hard to run on Android without rooting. So we use a slower proot instead.

Termux provides rootfs for Alpine Linux, and postmarketOS is originally based on Alpine Linux, so if you do a little trick to convert Alpine Linux to postmarketOS, you can get those packages designed for mobile Linux. Why don’t we use Alpine Linux directly, because some packages of postmarketOS are not being upstreamed, some packages are not found in Alpine Linux’s repsitory.

Finally, let’s talk about Phosh, a desktop environment developed by Purism, a free software company, designed for Linux phones. Its Wayland compositor, Phoc, is based on wlroots. In the PinePhone community, Phosh is one of the best rated interfaces. According to my personal experience of using PinePhone, I think Phosh is the most stable interface although the interface is very simple, and Phosh is very resource-saving. The animation of Phosh is still very smooth even running on the underpowered PinePhone which equipped with Allwinner A64 processor. I think Phosh is very useful for users who want to interact with Linux system in Termux X11. Because most Android phones don’t have keyboard and mouse, so if you run XFCE, KDE Plasma, GNOME and other traditional Linux desktops in Termux X11, it would be very awkward. So that , the touchscreen-optimized Phosh would be an excellent choice.

However, you may ask, Phosh is a Wayland compositor, how can it run on Termux X11? Although we cannot use Wayland directly, the nested Wayland session under X11 is still possible. Some compositors can do this, such as Weston or Cage. Some features of Wayland can still be used even running under X11 environment. However, simply running cage will result in an incomplete X session and no way to detect the resolution of the phone. So before running cage, I will start a X window manager in the first place. I choose Openbox for performance-wise.

2. Prerequisites
#

3. Install Proot Alpine Linux
#

postmarketOS provides two updating channels, Edge and Stable. The version number of Stable channel can be found in Wiki, currently it is v24.06.

The default Alpine Linux of Termux proot uses Edge branch, but this branch is unstable, so I suggest to switch it to Alpine 3.20 (corresponding to postmarketOS v24.06).

  1. Start Termux and install proot Alpine Linux.
pkg update

pkg install proot-distro pulseaudio

proot-distro install alpine
  1. Change the Alpine Linux repository from Edge to v3.20.
proot-distro login alpine --shared-tmp

apk update

apk add vim

vim /etc/apk/repositories

# Change "http://dl-cdn.alpinelinux.org/alpine/edge/main" to "http://dl-cdn.alpinelinux.org/alpine/v3.20/main"
# Change "http://dl-cdn.alpinelinux.org/alpine/edge/community" to "http://dl-cdn.alpinelinux.org/alpine/v3.20/community"

apk update

apk upgrade
  1. Add a new user, add it to sudo group, and set the timezone
apk add sudo

addgroup storage

adduser -g wheel,storage,video,audio user

visudo

sudo ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime

sudo setup-timezone
  1. Enable SSH remote connection in Termux proot.
sudo vim /etc/ssh/sshd_config

# Change `Port` from 22 to 8023

ssh-keygen -A

rc-update add sshd

rc-serive sshd start

# Check the IP address.
ip addr

4. Convert Alpine Linux installtion to postmarketOS
#

  1. Add the postmarketOS v24.06 (Alpine v3.20) repository.
vim /etc/apk/repositories

# Add this line at the top:
https://mirror.postmarketos.org/postmarketos/v24.06

# For your reference, the url of the Edge channel is: https://mirror.postmarketos.org/postmarketos/master/
  1. Install postmarketos-keys
apk add -u --allow-untrusted postmarketos-keys

apk update && apk upgrade
  1. Add the following lines to /etc/os-release
PRETTY_NAME="postmarketOS v24.06"
NAME="postmarketOS"
VERSION_ID="v24.06"
VERSION="v24.06"
ID="postmarketos"
ID_LIKE="alpine"
HOME_URL="https://www.postmarketos.org/"
SUPPORT_URL="https://gitlab.com/postmarketOS"
BUG_REPORT_URL="https://gitlab.com/postmarketOS/pmaports/issues"
LOGO="postmarketos-logo"

5. Installing Phosh desktop environment
#

  1. Install Openbox and Cage:
sudo apk add openbox cage
  1. The Phosh package name is postmarketos-ui-phosh. It is recommended to install some of the mobile device packages made by postmarektOS along with it:
sudo apk add postmarketos-ui-phosh \
postmarketos-tweaks \
firefox \
mobile-config-firefox \
font-noto \
font-noto-cjk \
font-noto-cjk-extra \
font-noto-cjk-extra

6. Launch Termux X11 and Phosh
#

The inspiration to start Phosh in proot comes from phosh-vnc and termux-phosh, although running it with WayVNC is one way, why not make good use of Termux X11 for better performance?

The process of starting Phosh desktop is as follows: start PulseAudio audio server on Termux side, start Termux X11, then log in to Proot Alpine, start Openbox, cage and Phosh.

The whole process is as follows:

  1. Luanch Termux and start Pulse Audio
pulseaudio --start --load="module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1" --exit-idle-time=-1

pacmd load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1
  1. Luanch Termux X11 APP and start Termux X11 in Termux
export DISPLAY=:0

termux-x11 :0 & 
  1. Start virglrenderer
virgl_test_server_android &
  1. Log into Alpine Linux
proot-distro login alpine --user user --shared-tmp
  1. Launch Openbox, cage, Phosh
export DISPLAY=:0

export XDG_RUNTIME_DIR=/tmp

openbox &

cage phoc -E '/usr/libexec/phosh' -U &
  1. In Termux X11 wait for the Openbox window to come out, double click on the title bar to maximize it.

  2. Tap Preferences in your phone’s notification bar and set Termux X11’s Output to Scaled to zoom in to a size that fits your phone.

  1. And change the Termux X11 Pointer to Direct Touch to simulate a touch screen.

7. Phosh user experience
#

Most of the touch gestures work. The control logic of Phosh is to swipe up from the bottom to view all the tasks, and swipe up to close the app window.

Note Phosh in proot is not a full Linux environment, so some functions are not available.

For example, Phosh uses GNOME Control Center to adjust system settings, but the GUI app cannot be opened, so many places have to be changed with commands. For example, to modify the file manager Portfolio to open the app with a specific file format preset, you should use xdg-mime to modify it. Also GNOME Software doesn’t work, please use apk command to install the apps.


Regarding Chinese input methods: Phosh’s built-in Squeekboard only supports English. Press and hold the bar at the bottom of Phosh to activate it (it seems that it doesn’t work in proot environment). In order to type Chinese, you’ll have to use your Android phone’s keyboard.

You can wake Android keyboard by pressing the back button in the Termux X11 APP. And then scroll the toolbar at the bottom to left to type charcters.

8. Let’s try other desktop environments?
#

Besides Phosh, the desktop environments of postmarketOS are Plasma Mobile and SXMO, but I think they have more problems, one is unstable and the other is too complicated.

Plasma Mobile

Plasma Mobile is a desktop envrionment based on the PC version of KDE Plasma, which can be launched with X11 or Wayland backend.

Personally, I think this desktop envrionment is very unstable, so it is better to use the PC version of KDE Plasma.

Packages name: postmarketos-ui-plasma-mobile。Launch in X11: startplasma-x11. Launch in Wayland: startplasma-wayland

You can start Plasma Mobile X11 session by: dbus-launch --exit-with-session startplasma-x11 &

SXMO

The package name is postmarketos-ui-sxmo but Termux X11 only support X server so I choose postmarketos-ui-sxmo-de-dwm.

  1. Install SXMO packages
sudo apk add postmarketos-ui-sxmo-de-dwm postmarketos-tweaks-sxmo-x11 feh dwm svkbd conky clickclack
  1. Execute: export XDG_RUNTIME_DIR=/tmp before launching SXMO.

  2. SXMO can be launched by executing dbus-launch --exit-with-session /usr/bin/sxmo_xinit.sh &

  3. The configuration files of SXMO is located at ~/.config/sxmo/. Hooks are at /usr/share/sxmo/default_hooks/.

Gestures are not working.

You may modify dwm source code to change default keybindings.

git clone [email protected]:~mil/sxmo-dwm
# Modify config.def.h then reinstall dwm

Uninstall sxmo-dwm package before installing your cutsom dwm.

Or you can just install vanilla dwm package and use default dwm keybindings.

References
#

Related

How to run Windows programs on Android with Box86 + Wine in Termux Proot
Categories   Smartphone Termux Tutorial
Tags   Box86 Box64 Wine Termux Raspberry Pi
How to use Termux X11 - The X server on Android phone
Categories   Smartphone Termux Tutorial
Tags   Termux
virglrenderer: Termux GPU hardware acceleration tutorial
Categories   Smartphone Termux Tutorial
Tags   Wine Termux

Leave a comment

Choose the comment system you like. Giscus for codes, Disqus for anonymous comments.

Please login to your Github account to leave a comment. You can post codes here for discussion. For images, please upload to Imgur and copy links. Your comments would be visible to everyone on Github Discussions.

This comment system is provided by Disqus, you may see forcing Disqus ADs on this page. Sometimes your comment may need to be reviewed, resulting in delayed display. Thank you for your understanding.