I tried a lot of tools to install Linux on my Android device, but they all either didn’t work at all, or were too buggy. Fortunately, I use ArchLinux on a PC and after learning about the ArchLinux project, ARM decided to try it out. And not just install in chroot, but make it work without it.
We will need
- Straight arms
- Android device
- Root access
- Busybox
- Terminal emulator
- Free place
- ADB (for convenience)
All actions you perform at your own risk.
I used
- Android 4.2 device with 512MB of RAM, Linux 3.4.5 armv7l kernel
- ConnectBot terminal emulator
- SuperSU SuperSU Management
- BusyBox v1.20.0
Part 1: Preparation
1. Download the archive with ArchLinux ARM from the mirror:
wget http://mirror.yandex.ru/archlinux-arm/os/ArchLinuxARM-armv7-latest.tar.gz mv ArchLinuxARM-armv7-latest.tar.gz ArchLinuxARM.tar.gz adb push ArchLinuxARM.tar.gz /sdcard/
Further actions need to be done on an Android device.
2. Create a file for the future image using make_ext4fs.
')
If you have a separate section on the memory card, it is advisable to use it. In my case, the 16GB SD card was filled with important data and there was no possibility to move the main FAT partition.
Depending on the settings, / sdcard can be either an external or internal memory card.
cd sdcard make_ext4fs -l 3221225472 arch.img
3221225472 is 1024 * 1024 * 1024 * 3, hence the 3GB image will be created. The size of the image determine for yourself to taste. Remember that on FAT32 you can not create a file larger than 4GB
3. Mount the image and extract the ArchLinux ARM files
mount -o rw,remount / mkdir /arch busybox mount /sdcard/arch.img /arch tar -xvf ArchLinuxARM.tar.gz -C /arch/
4. In spite of the fact that our goal is to do without chroot, for basic configuration and testing the chroot still needs to be done. Otherwise, you will have to update, deliver the packages already on the combat system.
busybox mount -t proc none /arch/proc busybox mount -o rbind /dev /arch/dev busybox mount -t tmpfs none /arch/tmp busybox mount -o size=10%,mode=0755 -t tmpfs none /arch/run chroot /arch /bin/bash
Part 2: Find and Solve Problems
Problem 1: ping does not work
Try ping
ping 8.8.8.8 socket: Permission denied
We recall that Android has a serious system of differentiation of rights. And there is a perm on it in "Full access to the network." Without this perm, users cannot get full access to sockets. What you need.
Let's go back to the Android console and write the id command:
uid=2000(shell) gid=2000(shell) groups=1003(graphics),1004(input),1007(log),1009(mount),1011(adb),1015(sdcard_rw),1028(sdcard_r),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats)
You may have a different conclusion.
groupadd -g 3003 inet usermod -a -G inet root
But bad luck, chroot does not update the group. This “hack” will help:
su root
We try again:
ping 8.8.8.8 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=59 time=89.6 ms 64 bytes from 8.8.8.8: icmp_seq=2 ttl=59 time=88.6 ms
Problem 2: DNS does not work
Delete the symlink on systemd and write down normal DNS:
rm /etc/resolv.conf echo "nameserver 8.8.8.8" > /etc/resolv.conf
If you screwed up PATH
If it happens that simple commands like ls, cat, su do not work (cannot be seen) by the system, you can try to call them directly: / system / bin / ls, / system / bin / cat, / system / xbin / su.
Or reboot the device.
We put the necessary packages
pacman -S gcc htop iotop sudo openssh
Check gcc
cd /root nano main.cpp
#include <iostream> int main() { std::cout << "Hello World!\n"; return 0; }
g++ main.cpp ./a.out
Part 3: Getting started without chroot
The most important thing that allows ArchLinux to work without chroot next to android is the fact that ArchLinux and Android folders and files are different and do not interfere with each other.
If you are not sure that the files will not intersect, run these commands from the Android console:
ls /etc/ > /sdcard/ls.txt ls /arch/etc/ > /sdcard/ls2.txt busybox grep -F -f /sdcard/ls.txt /sdcard/ls2.txt
Shows the intersection of files. It looks like this to me:
dhcpcd.conf hosts security
Copy files from / etc / to / arch / etc / from Android:
cp -Ra /etc/* /arch/etc/ cp -a /sbin/adbd /arch/usr/bin/
The -a switch is required, as when using the usual -R rights will not be copied.
You need to take care of Root in advance.
Android applications require that the su command immediately gives access to the superuser and does not request a password.
passwd mv /usr/bin/su /usr/bin/su.r
Part 4: Let's go!
Create the necessary directories and use mount --bind to virtually replace the directory without changing it on disk.
mkdir /lib mkdir /bin mkdir /xbin mkdir /opt mkdir /usr mkdir /home mkdir /run mkdir /srv mkdir /tmp mkdir /var busybox mount --bind /arch/etc /etc busybox mount --bind /arch/opt /opt busybox mount --bind /arch/home /home busybox mount -o size=10%,mode=0755 -t tmpfs none /run busybox mount --bind /arch/srv /srv busybox mount -t tmpfs none /tmp busybox mount --bind /arch/sbin /sbin busybox mount --bind /arch/usr/ /usr busybox mount --bind /arch/var/ /var busybox mount --bind /arch/lib/ /lib busybox mount --bind /arch/usr/bin/ /bin /bin/bash
If something is done incorrectly, you can reboot the device and try again. The order of the mount is
important . If an error occurs with mounting, standard commands can be taken from ArchLinux before all directories are mounted.
What's next
As a result, we have almost full-fledged ArchLinux with the exception of systemd with fresh versions of packages.
You can install http, php, mysql. When properly configured to reduce memory consumption, even on my smartphone with 512 MB of RAM, they worked correctly.
You can install X-ray libraries and use Linux software with X server for Android. xterm earned correctly.
You can build any program (and, oh no, the kernel) for Linux without a PC.
You can install Java for ARM and use Java applications.
Afterword
The big problem remains systemd and its binding to PID 1. In order to save PID 1, you need to get into the android init and set the exec after the devices are initialized. This can be done by replacing the init android shell script, but then the question remains what to do with the original android init. Since the space on the boot disk is limited to a few megabytes, you will need to use switch_root in a pre-created image. I have not managed to get systemd in this way.
I am 16 and this is my first post. Constructive criticism is welcome.