Skip to main content

Use a custom rootfs in Termux proot-distro to create a Linux container

·
Categories Smartphones Termux Tutorials
Tags Proot-Distro
Table of Contents

This article demonstrates how to add your preferred Linux distribution to the proot-distro tool in Android Termux.

Using Ubuntu as an example, we will install the older Ubunut 22.04 LTS proot Ubuntu.

1. proot vs proot-distro
#

proot is a userspace implementation of chroot, allowing chroot-like functionality without root privileges.

Some developers distribute Termux proot distributions by brute-forcing it with the proot command. For example, Box64Droid downloads a custom rootfs, then uses a long chain of commands to log in to the proot distribution.

But since we have the useful proot-distro script, why not make good use of it? It is a wrapper script for proot, integrating the processes of downloading, logging in to, and logging out of proot distributions, while also making it convenient to execute commands.

I explained its usage in proot-distro usage, but what if the distributions provided by the proot-distro maintainers do not meet your needs? For example:

  1. You need a rootfs for a specific Linux version, such as an LTS version of Ubuntu, but proot-distro’s Ubuntu is always the latest version.
  2. You need a rootfs for a specific architecture, such as 32-bit x86 Manjaro
  3. You want to run an x86_64 system on an ARM64 device

Fortunately, proot-distro allows us to “register” proot distributions. We can add our own rootfs and then operate it with the proot-disro command.

2. How to build a custom Linux rootfs
#

Most distributions have their own rootfs building tools. Note that packages like debootstrap included in Termux may have permission issues, so it is safer to create the rootfs on a Linux computer and then move it to the phone.

You can also refer to the proot-distro author’s scripts to understand how to create a custom rootfs.

3. Register a new Ubuntu proot-distro
#

  1. Open Termux and install proot-distro
pkg install proot-distro
  1. Go to Ubuntu daily builds and copy the Ubuntu base 22.04 URL. This is a minimal system.

  2. Temporarily download it to the Termux home directory

pkg install wget

wget https://cdimage.ubuntu.com/ubuntu-base/releases/22.04/release/ubuntu-base-22.04.3-base-arm64.tar.gz
  1. Calculate the SHA256 checksum, then remove it
pkg install coreutils

sha256sum ubuntu-base-22.04.3-base-arm64.tar.gz

rm ubuntu-base-22.04.3-base-arm64.tar.gz
  1. Switch to $PREFIX/etc/proot-distro, where proot scripts are stored, copy the sample script, and name it ubuntu22.04.sh
cd $PREFIX/etc/proot-distro
cp distro.sh.sample ubuntu22.04.sh
  1. Edit it
vim ubuntu22.04.sh
  1. Add the following content. I omitted the original comments.
# The architecture should match the phone processor architecture
DISTRO_ARCH=aarch64

# Display name of the distribution
DISTRO_NAME="Ubuntu 22.04 LTS"

# Comment
DISTRO_COMMENT="Ubuntu 22.04 LTS Jammy Jellyfish"

# Directory depth of the archive, default is 1, which ignores the root directory. But Ubuntu base extracts directly as the filesystem, so set 0 here
TARBALL_STRIP_OPT=0

# Each architecture in the array corresponds to a rootfs URL. You can also upload the rootfs to your own Github instead
TARBALL_URL['aarch64']="https://cdimage.ubuntu.com/ubuntu-base/releases/22.04/release/ubuntu-base-22.04.3-base-arm64.tar.gz"

# Fill in the archive's SHA256 checksum
TARBALL_SHA256['aarch64']="bdae94b05d0fca7decbe164010af2ac1b772a9dda21ed9fb5552b5674ad634a3"

# Commands to run after installation
distro_setup() {
        run_proot_cmd touch /etc/hello-world
}
  1. Try running proot-distro list; you can see that the Ubuntu 22.04 LTS we just added has appeared in the list

  2. Try installing Ubuntu 22.04 LTS. proot-distro will automatically fix permission issues

proot-distro install ubuntu22.04
  1. Log in
proot-distro login ubuntu22.04
  1. Check with cat /etc/os-release and confirm that the displayed version is Ubuntu 22.04. Then refer to the proot Ubuntu installation guide to install it as a complete system.

Related


Thank you for reading. Public comments are not available on this website. I write to explore ideas honestly, not to chase social engagement or traffic. I would be glad to hear your thoughts after reading the article with care. If you found any errors, technical issues, or would like to share feedback, feel free to contact me via the email listed on the About page.