Install Archlinux on an Android phone in the second SD partition or just a subfolder of the system memory card
- Tutorial

Hello everybody. There has already been an article on Botbrew, which generally describes what it is and what it gives. In short:
The BotBrew project is designed to solve many of the problems with installing Linux software that a user may encounter and prepare the Android system for accepting applications foreign to it.
The usual, classic Botbrew has its own repository, but it has few packages, which is sad. Those who really want to bespredelnichat enjoy Borbrew-Basil, which uses the Debian repository Emdebian . However, with him now, too, everything is sad, since
As of July 2014, updates to the Emdebian distributions ceased. There will be no further updates and no further stable releases.
It turns out that even those who once installed emdebian are now in flight. This post will be about how to put on a routed Archlinux phone , but not as usual in the loop image, but on the native Android file system or the second SD partition. It is assumed that there is a rooted phone with busybox installed, USB debugging enabled, and adb utility on the main computer.
Cooking device
The first thing we need is to create a folder where we will put our linux. There are two options - a folder on the / data section or a separate ext4 section of the memory card. In the second case, the section will need to be mounted somehow in the main FS of the phone. This can be done for example using Link2SD . Further, I will proceed from the fact that we are using the second SD partition mounted in / data / sdext2, we will put it in the / data / sdext2 / arch folder.
You also need to understand the repository for which processor architecture we will use. I have a Qumo Quest 454 with an armv7l processor and http://mirror.archlinuxarm.org/arm/ came up for it .
We connect the phone via USB, go to it via adb and rushed.
We collect the minimum starting option
For a minimal installation, you will need the following packages (run from root, package versions may become newer over time):
mkdir -p /data/sdext2/arch/packages
cd /data/sdext2/arch/packages
wget http://mirror.archlinuxarm.org/arm/core/acl-2.2.52-2-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/attr-2.4.47-1-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/bash-4.3.030-1-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/bzip2-1.0.6-5-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/curl-7.39.0-1-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/e2fsprogs-1.42.12-1-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/expat-2.1.0-4-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/filesystem-2014.10-3-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/gcc-libs-4.9.2-1-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/glibc-2.20-4-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/gpgme-1.5.2-1-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/keyutils-1.5.9-1-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/krb5-1.13-1-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/libarchive-3.1.2-8-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/libassuan-2.1.3-1-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/libgpg-error-1.17-1-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/libidn-1.29-1-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/libssh2-1.4.3-2-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/lzo-2.08-3.1-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/ncurses-5.9-6.1-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/openssl-1.0.1.j-1-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/pacman-4.1.2-7-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/pacman-mirrorlist-20141208-1-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/readline-6.3.006-1-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/util-linux-2.25.2-1-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/xz-5.0.7-1-arm.pkg.tar.xz
wget http://mirror.archlinuxarm.org/arm/core/zlib-1.2.8-3-arm.pkg.tar.xzAfter everything has downloaded, unpack it:
cd /data/sdext2/arch
tar xvf packages/*.pkg.xz
We got something like the minimal installation of Archlinux. Now let's try to make chroot into it, having previously mounted the system folders ():
busybox mount -t proc none ./proc
busybox mount -o rbind /dev ./dev
busybox mount -t sysfs none ./sys
busybox mount -t tmpfs none ./tmp
busybox mount -o size=10%,mode=0755 -t tmpfs none ./run
chroot . /bin/bash
If everything went well, bash will start from our minimal environment and pacman will become available. When I started any process, my system cursed that it could not find libsuc.so described in LD_PRELOAD. In this case, just clear LD_PRELOAD:
export LD_PRELOAD=
Putting packages in order
So, we are in chroot, pacman and bash are working for us. First of all, let's put in order what is. We will register the DNS and load the repositories:
echo "nameserver 8.8.8.8" > /etc/resolv.conf
pacman -Sy
Now we’ll officially install what we just unpacked and add the rest of the packages that are minimally necessary for life and return to the place of dns, which the installation of filesystem beat us:
pacman -S base --force --noconfirm
echo "nameserver 8.8.8.8" > /etc/resolv.conf
If everything went well, then we have a full-fledged minus systemd and Archlinux core. We exit chroot and unmount everything that we mounted:
exit
umount ./dev/pts
umount ./dev/cpuctl
umount ./proc
umount ./sys
umount ./tmp
umount ./run
Add auto-mount and other buns
To use what turned out to be easy and simple, we will screw init from botbrew-basil. This is a utility that checks to see if everything we need is mounted and does chroot in our environment. I could not find how to download it from the botbrew repository, so for now I just posted the link on Yandex.Disk . Copy init to / data / sdext2 / arch and add the attribute for execution.
We go into the adb shell and type:
/data/sdext2/init /bin/bash
As a result, all that is needed is mounted once and we find ourselves in a freshly placed Arch. As a bonus, init will create the / storage, / mnt and / android folders in the root of the chroot, where it will mount the pieces of the original file system.
To enjoy linux not via a USB cable, but directly from the phone, you can register / data / sdext2 / init / bin / bash as a shell in your favorite terminal. Further it is possible to create users to taste, to raise sshd, etc. But any archivod already knows how to do this, so I won’t write about it here.
Thank you for your attention, additions and corrections are welcome.
UPDATE: a small script that I run once after reboot
Initialization script
#!/bin/bash
if [[ `whoami` != "root" ]]
then
sudo bash $0 $@
exit $?
fi
chmod 777 /tmp
c=`ps afx | grep /usr/sbin/sshd | grep -cv grep`
if [[ "$c" != "1" ]]
then
echo Strating sshd
/usr/sbin/sshd
else
echo sshd already started
fi
if [[ ! -e /dev/fd ]]
then
echo Creating /dev/fd links
ln -s /proc/self/fd /dev/fd
ln -s /proc/self/fd/0 /dev/stdin
ln -s /proc/self/fd/1 /dev/stdout
ln -s /proc/self/fd/2 /dev/stderr
fi
if [[ ! -e /dev/net/tun ]]
then
echo Creating /dev/net/tun
mkdir /dev/net
ln -s /dev/tun /dev/net/tun
else
echo /dev/net/tun already exists
fi