📜 ⬆️ ⬇️

Installing Archlinux on an Android phone in the second section of SD or just a subfolder of the system memory card

image

Hello to all. There was already an article on the topic of Botbrew, where in general it is described what it is and what it gives. In short:
The BotBrew project is designed to solve many problems with installing Linux software that a user may encounter, and prepare the Android system for accepting applications that are foreign to it.

The usual, classic Botbrew has its own repository, but there are few packages in it, which is sad. Those who really want to go crazy like Borbrew-Basil, which uses the emdebian debian repository. However, with him now, too, everything is sad, because
As of July 2014, updates to the Emdebian distributions ceased. There is no further updates.

It turns out that even those who once set themselves emdebian, now in the span. This post will be about how to put on a ruled Archlinux phone, but not as usual in a loop image, but on the native Android file system or the second SD partition. It is assumed that there is a rooted phone with installed busybox, 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. Option two - a folder on the / data section or a separate ext4 section of the memory card. In the second case, the partition will need to somehow be mounted into the main FS of the phone. You can do this for example using Link2SD . Further, I will proceed from the fact that the second section of the SD, mounted in / data / sdext2, is used, we will put in the folder / data / sdext2 / arch.
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 it was http://mirror.archlinuxarm.org/arm/ .

We connect the phone via USB, go to it via adb and rush.
')

We collect the minimum starting option


For a minimal installation, you will need the following packages (we run from root, versions of packages may eventually become newer):

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.xz 


Once everything is downloaded, unpack:
 cd /data/sdext2/arch tar xvf packages/*.pkg.xz 


We got something like the Archlinux minimal install. Now let's try to chroot into it by pre-mounting 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 be available. When I started any process, the system cursed that it could not find libsuc.so, described in LD_PRELOAD. In this case, simply clean the LD_PRELOAD:

 export LD_PRELOAD= 


Tidy up the packages


So, we are in chroot, pacman and bash work for us. First of all, let's put in order what is. Register the DNS and load the repositories:

 echo "nameserver 8.8.8.8" > /etc/resolv.conf pacman -Sy 


Now let's officially put what we just unpacked and add the rest of the minimally necessary packages for life and return the dns that the installation of the filesystem broke for 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 cores. Exit the chroot and unmount everything we have mounted:

 exit umount ./dev/pts umount ./dev/cpuctl umount ./proc umount ./sys umount ./tmp umount ./run 


We add automounting and other buns


To use what we got easily and easily, we will fix init from botbrew-basil. This is a utility that checks whether everything is mounted and chroot into our environment. I could not find how to download it from the botbrew repository, so for now I just put it on Yandex.Disk, link . Copy init to / data / sdext2 / arch and add the attribute for execution.

Go to the adb shell and type:
 /data/sdext2/init /bin/bash 


As a result, all that is needed is itself one time mounted and we will find ourselves in the newly established Arch. As a bonus, init will create the / storage, / mnt and / android folders at the root of chroot, where it will mount pieces of the original file system.

In order to enjoy linux not via USB wire, but directly from the phone, you can write / data / sdext2 / init / bin / bash as a shela in your favorite terminal. Then you can create users to taste, raise sshd, etc. But any archaver already knows how to do this, so I’m not going to write about it here.

Thank you for your attention, additions and corrections are welcome.

UPDATE: a small script that I run once after a 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 

Source: https://habr.com/ru/post/221543/


All Articles