Ubuntu on Termux

Termux is my most favourite Terminal emulator on android. It provides you with a mini-linux and full openssh client and server. this means, your .ssh/config from your PC will just work on your android phone as well! having the real openssh ssh client you can do all the fun things you like on your destkop pc, so it is extremely useful to access remote systems even through jump hosts, tunnels etc.

such a capable system asks for more.. why not run a full fledged ubuntu in chroot? .. well we don't have root access to the phone, so that complicates things a little, but luckily there is proot and the termux modified version of proot that can help you get the job done.

install proot and while we are at it, let's uinstall proto-distro as well which is a little helper to get us started with the root filesystem:

pkg install proot proot-distro 

now we prepare the root filesystem. you can use

proot-distro list 

to get a list of available distros.

proot-distro install ubuntu-20.04

this will install ubuntu 20.04 LTS to /data/data/com.termux/files/usr/var/lib/proot-distro/installed-rootfs/ubuntu-20.04

you can create a symlink to that directory from within your home folder to make it accessible easily:

ln -s ../usr/var/lib/proot-distro/installed-rootfs/ubuntu-20.04

to start our ubuntu proot session we can simply use

proot-distro login ubuntu-20.04 

or we can run proot manually to give us some more customizability. for example:

unset LD_PRELOAD
distro=ubuntu-20.04; proot --link2symlink -0 -r $distro/ -b /dev -b /proc -b /sys -b $distro/tmp:/dev/shm -b /data/data/com.termux -b /:/host-rootfs -b /sdcard -b /storage -b /mnt /usr/bin/env -i HOME=/root PATH=/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/games:/usr/local/games TERM=\$TERM LANG=C.UTF-8 /bin/bash --login