Skip to content

Instantly share code, notes, and snippets.

@avoidik
Last active July 21, 2024 12:23
Show Gist options
  • Save avoidik/3147844c90bd7c1680599d4a70e15904 to your computer and use it in GitHub Desktop.
Save avoidik/3147844c90bd7c1680599d4a70e15904 to your computer and use it in GitHub Desktop.
XFCE4 on Termux

XFCE4 on Termux

In this short guide I will explain how to run Ubuntu with Xfce4 desktop environment on your Android smartphone by using Termux-X11 in an isolated environment without root privileges. With minor adjustments this guide should work for Debian too (just replace ubuntu by debian).

Note: Neither of options won't support systemd. Moreover, Firefox on Ubuntu is distributed as a snap package, which in turn does not work without systemd.

Host system

I am a user of an arm64 based Android smartphone. First of all let's install Termux application from Play Market.

Once Termux is installed we have to install some packages.

$ pkg update
$ pkg upgrade
$ pkg install x11-repo
$ pkg install termux-x11-nightly proot proot-distro pulseaudio

Additionally, we have to install Termux-X11 companion application for Android. We will use it to connect to Ubuntu desktop environment.

You should get it from the Termux-X11 repo at https://github.com/termux/termux-x11/releases

Now install the bare Ubuntu operating system

$ proot-distro install ubuntu

Configure pulseaudio to accept anonymous connections over the localhost by default

$ mkdir -p $PREFIX/etc/pulse/default.pa.d
$ cat <<'EOF' > $PREFIX/etc/pulse/default.pa.d/remote-local.pa
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1
EOF

Run pulseaudio as runit

$ mkdir -p $SVDIR/pulseaudio/log
$ cat <<'EOF' > $SVDIR/pulseaudio/run
#!/data/data/com.termux/files/usr/bin/sh
exec pulseaudio --daemonize=no --system=no --exit-idle-time=-1 --fail --disallow-exit 2>&1
EOF
$ cat <<'EOF' > $SVDIR/pulseaudio/log/run
#!/data/data/com.termux/files/usr/bin/sh
svlogger="/data/data/com.termux/files/usr/share/termux-services/svlogger"
exec "${svlogger}" "$@"
EOF
$ chmod u+x $SVDIR/pulseaudio/run
$ chmod u+x $SVDIR/pulseaudio/log/run
$ sv-enable pulseaudio

Run termux-x11 as runit

$ mkdir -p $SVDIR/termux-x11/log
$ cat <<'EOF' > $SVDIR/termux-x11/run
#!/data/data/com.termux/files/usr/bin/sh
exec termux-x11 2>&1
EOF
$ cat <<'EOF' > $SVDIR/termux-x11/log/run
#!/data/data/com.termux/files/usr/bin/sh
svlogger="/data/data/com.termux/files/usr/share/termux-services/svlogger"
exec "${svlogger}" "$@"
EOF
$ chmod u+x $SVDIR/termux-x11/run
$ chmod u+x $SVDIR/termux-x11/log/run
$ sv-enable termux-x11

Guest system

Run it first

$ proot-distro login --isolated --bind /dev/null:/proc/sys/kernel/cap_last_cap --shared-tmp ubuntu

Install required packages

$ apt update
$ apt install dialog pulseaudio apt-utils
$ echo 'default-server = localhost' > /etc/pulse/client.conf.d/remote-local.conf
$ pactl list sinks short
$ apt install --no-install-recommends xorg xfce4 dbus-x11 pavucontrol

Launch Ubuntu with XFCE4

$ DISPLAY=:0 dbus-launch --exit-with-session xfce4-session

To run it directly

$ proot-distro login --isolated --bind /dev/null:/proc/sys/kernel/cap_last_cap --shared-tmp ubuntu -- env DISPLAY=:0 dbus-launch --exit-with-session xfce4-session

Launch Termux-X11 companion app to connect to XFCE4 desktop environment

@avoidik
Copy link
Author

avoidik commented Jul 7, 2024

It's possible to use VNC instead of the Termux-X11 companion app.

$ pkg install x11vnc
$ x11vnc -storepasswd qwertypassword ~/.vncpass

Map VNC port over the SSH tunnel

$ ssh termux -L 5900:localhost:5900 x11vnc -display :0 -auth \$HOME/.Xauthority -rfbauth \$HOME/.vncpass -many -shared -loop -repeat -noxrecord -noxfixes -noxdamage -noshm -localhost -noipv6 -no6 -scale 1024x768

Connect to VNC at localhost::5900

@avoidik
Copy link
Author

avoidik commented Jul 21, 2024

dbus-daemon

$ whoami
u0_a672
$ tail -n 11 $PREFIX/share/dbus-1/system.d/pulseaudio-system.conf
<busconfig>

  <!-- System-wide PulseAudio runs as 'pulse' user. This fragment is
       not necessary for user PulseAudio instances. -->

  <policy user="u0_a672">
    <allow own="org.pulseaudio.Server"/>
    <allow own="org.PulseAudio1"/>
  </policy>

</busconfig>
$ grep '<user>' $PREFIX/share/dbus-1/system.conf
  <user>u0_a672</user>
$ cat $SVDIR/dbus-system/run
#!/data/data/com.termux/files/usr/bin/sh
exec dbus-daemon --nosyslog --nofork --system 2>&1

Export

$ cat $PREFIX/etc/profile.d/dbus.sh
DBUS_SESSION_BUS_ADDRESS='unix:path=/data/data/com.termux/files/usr/var/run/dbus/system_bus_socket'; export DBUS_SESSION_BUS_ADDRESS

When stuck

$ rm -f /data/data/com.termux/files/usr/var/run/dbus/pid
$ sv restart dbus-daemon
$ sv restart pulseaudio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment