Introduction

This document shows you how to install Alpine Linux on Android based devices in a userspace chroot called proot.

To be honest, I recommend to use PRoot Distro for setting things up fast!

I know there are other apps and scripts available in F-Droid and PlayStore (AnLinux, UserLAnd, etc.), but this document just wants to show you how easy it is to do it by yourself, only using Termux as Frontend/TUI.

Keep it simple! ;)

I have this running on two very different devices, a tablet and a phone. The tablet I am using is a Samsung SM-T585 (LTE/Wifi) with stock Android, also known as Samsung Galaxy Tab A 2016 (10.1, LTE). The phone I am using is a Google Pixel 5 with GrapheneOS installed.

This is a work in progress actually… but it works!

Installation

Requirements

  • A device with armv7 CPU support (aarch64 should work too but I have no device to test it)
  • The Termux App installed on your device and configured as descriped in the documentation

Open Termux!

Update Termux

Since this document always refer to the latest updates of Termux, I always recommend to update to the latest packages available.

$ pkg upgrade

Prepare Termux for the Alpine installation

$ apt install proot
$ mkdir alpine
$ cd alpine

Get Alpine Linux minirootfs and extract the archive

$ wget https://dl-cdn.alpinelinux.org/alpine/v3.20/releases/armv7/alpine-minirootfs-3.20.3-armv7.tar.gz
$ tar -xvf alpine-minirootfs-3.20.3-armv7.tar.gz

PRoot!

$ export PATH=/bin:/sbin:/usr/bin:/usr/sbin:$PATH
$ export TMPDIR=/tmp
$ unset LD_PRELOAD
$ HOME=/root proot -r ./ -0 -w / -b /dev -b /proc -b /sys /bin/sh

Configure the PRoot environment

# echo "nameserver 9.9.9.9" > /etc/resolv.conf
# echo "nameserver 149.112.112.112" >> /etc/resolv.conf

The nameservers are provided by Quad9. Just change them to your favorites…

You could step over to the “Where to go from here?” section as everything is ready to go. The next section is just to show you how I set up my environment properly to fit my needs. Since my preferred Shell is the Z shell (Zsh), I mostly set up my shell environment.

Get your personal configuration (optional)

This section is an example on how I configure my environment. It will not work for you, because you have no SSH access to my Git server. Just checking this out using an https URL to the Git repository will not work, because the submodules are still using SSH and updating them will fail!

Install and configure some addional packages

# apk add git openssh vim zsh zsh-completions zsh-vcs
# git config --global init.defaultBranch main
# ssh-keygen

Add the content of ~/.ssh/id_*.pub to Forgejo, GitHub, Gitea etc…

Get some configuration files from a Git repository

# cd ~
# git init .
# git remote add -t \* -f origin git@git.xw3.org:hanez/home.git
# git checkout master
# git submodule update --init --recursive
# touch .penv
# /bin/zsh

Edit /etc/passwd to set the default shell from /bin/sh to /bin/zsh for all users

# sed 's:/bin/sh:/bin/zsh:' -i /etc/passwd

Where to go from here?

Exit the environment and “proot” again…

Just hit Ctrl+D! If you have executed /bin/zsh during this setup, you need to hit Ctrl+D twice.

Usage

Open Termux!

In Termux

$ export PATH=/bin:/sbin:/usr/bin:/usr/sbin:$PATH
$ export TMPDIR=/tmp
$ export ZSH=/root/.zsh/oh-my-zsh # (optional)
$ unset LD_PRELOAD

PRoot!

$ HOME=/root proot -r ./alpine -0 -w / -b /dev -b /proc -b /sys /bin/sh

Or in my case (optional)

$ HOME=/root proot -r ./alpine -0 -w / -b /dev -b /proc -b /sys /bin/zsh

Inside the PRoot environment

Have fun! :)

Links

  • Alpine Linux - A security-oriented, lightweight Linux distribution based on musl libc and busybox
  • Android - A mobile operating system based on a modified version of the Linux kernel and other open-source software
  • AnLinux - Run Linux on Android without root access
  • F-Droid - An installable catalogue of FOSS (Free and Open Source Software) applications for the Android platform
  • GrapheneOS - The private and secure mobile operating system with Android app compatibility
  • PRoot - A user-space implementation of chroot, mount –bind, and binfmt_misc
  • PRoot Distro - A Bash script wrapper for utility proot for easy management of chroot-based Linux distribution installations
  • Quad9 - A free service that replaces your default ISP or enterprise Domain Name Server (DNS) configuration
  • Termux - An Android terminal emulator and Linux environment app that works directly with no rooting or setup required
  • UserLAnd - An easy way to run a Linux distribution or application on Android
  • Zsh - A shell designed for interactive use, although it is also a powerful scripting language

Comments