🇹🇼 中文版
Termux, a temrminal emulator, could be an good Linux Deploy alternative. You can manually install Ubuntu chroot environment on Android phone without using Linux Deploy .
Ubuntu 22.04 in chroot envrionment running on Android 12, Sony Xperia 5 II.

Install Fox’s Magisk Module Manager
Search “Magisk Builtin Busybox” and install the module.
Reboot.
Please install Termux first.
- Open Termux, install tsu and pulseaudio
1
2
| pkg update
pkg install tsu pulseaudio
|
- Create a directory at
/data/local/tmp
for chroot envrionment
1
2
3
| su
mkdir /data/local/tmp/chrootubuntu
cd /data/local/tmp/chrootubuntu
|
- Download latest Ubuntu base rootfs
1
| wget https://cdimage.ubuntu.com/ubuntu-base/releases/22.04/release/ubuntu-base-22.04-base-arm64.tar.gz
|
- Unzip the archive. And create a mountpoint for sdcard (internal storage)
1
2
3
| tar xpvf ubuntu-base-22.04-base-arm64.tar.gz --numeric-owner
mkdir sdcard
|
- Create a startup script.
- Type these:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| #!/bin/sh
# The path of Ubuntu rootfs
UBUNTUPATH="/data/local/tmp/chrootubuntu"
# Fix setuid issue
busybox mount -o remount,dev,suid /data
busybox mount --bind /dev $UBUNTUPATH/dev
busybox mount --bind /sys $UBUNTUPATH/sys
busybox mount --bind /proc $UBUNTUPATH/proc
busybox mount -t devpts devpts $UBUNTUPATH/dev/pts
# Mount sdcard
busybox mount --bind /sdcard $UBUNTUPATH/sdcard
# chroot into Ubuntu
busybox chroot $UBUNTUPATH /bin/su - root
# Umount everything after exit
busybox umount $UBUNTUPATH/dev/pts
busybox umount $UBUNTUPATH/dev
busybox umount $UBUNTUPATH/proc
|
- Make the script executable
- Start the script. Then you should see the prompt becomes
root@localhost
. To logout, type exit
.
- Before updating packages, execute the following commands to solve
apt cannot resolve host
errors
1
2
| echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "127.0.0.1 localhost" > /etc/hosts
|
- Then fix
Download is performed unsandboxed as root
warning:
1
2
3
4
5
| groupadd -g 3003 aid_inet
groupadd -g 3004 aid_net_raw
groupadd -g 1003 aid_graphics
usermod -g 3003 -G 3003,3004 -a _apt
usermod -G 3003 -a root
|
- Now you can update packages:
1
2
| apt update
apt upgrade
|
- Install common tools:
1
| apt install vim net-tools sudo git
|
- Install OpenSSH
1
| sudo apt install openssh-client openssh-server
|
- Change root password
- Start SSH services.
1
2
| mkdir /run/sshd
/usr/sbin/sshd -D &
|
You can check the IP address of the phone by executing ifconfig
. Then you can SSH into the phone from your PC.
- Install XFCE4 desktop environment:
1
2
| apt install xfce4 xfce4-goodies
update-alternatives --config x-terminal-emulator
|
- Install VNC server
1
| apt install tigervnc-standalone-server tigervnc-xorg-extension
|
- Setup password for VNC server
- Create a startup script for VNC server:
vim ~/.vnc/xstartup
1
2
3
4
5
| #!/bin/bash
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADRESS
export PULSE_SERVER=127.0.0.1 && pulseaudio --start --disable-shm=1 --exit-idle-time=-1
exec startxfce4
|
- Make it executable
1
| chmod +x ~/.vnc/xstartup
|
- Start VNC server. Then open AVNC and type
localhost:5901
to view the desktop enviromment.
1
| vncserver -localhost no
|
- If the terminal failed to launch, try to mount devpts
1
| mount -t devpts devpts /dev/pts
|
- Remember to stop VNC server after closing AVNC app:
Execute the following commands in Termux (not chroot. Swipe from left edge to open a new session)
1
2
| 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
|
- Setup the timezone to
Asia/Taipei
1
| ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime
|
- Add a new user named
user
1
2
3
4
| groupadd storage
groupadd wheel
useradd -m -g users -G wheel,audio,video,storage -s /bin/bash user
passwd user
|
- Execute:
vi sudoers
. Add user
to sudoers
To start vnc server as normal user. Create a vnc startup file at user’s home direcotry like you did before.
Now you can type su user
to switch to user
. And you can modify the scipt o starting chroot , change chroot . /bin/su - root
to chroot . /bin/su - user
.
When you type sudo apt install firefox
, Ubuntu will try to download snap version of Firefox. However, Snap will not work in chroot because there is no systemd on Android. Therefore, you should avoid installing snap packages.
For exmaple, you can add Mozilla’s ppa to install firefox-esr
instead of fireofx
:
1
2
3
| sudo add-apt-repository ppa:mozillateam/ppa
sudo apt-get update
sudo apt-get install firefox-esr
|
And you could disable Snap by doing this:
1
2
3
4
5
6
7
8
9
10
| apt-get autopurge snapd
cat <<EOF | sudo tee /etc/apt/preferences.d/nosnap.pref
# To prevent repository packages from triggering the installation of Snap,
# this file forbids snapd from being installed by APT.
# For more information: https://linuxmint-user-guide.readthedocs.io/en/latest/snap.html
Package: snapd
Pin: release a=*
Pin-Priority: -10
EOF
|