User:Fugoes/Manual Bootstrap Gentoo Prefix for aarch64 Android

Overview
There is a helper script to aid bootstrapping Gentoo Prefix on different platforms. Please browse this wiki page to get this script. This  works for arm64 platform with some manual tuning, due to the absent of   profile. After this commit, it shall work smoothly. This script divides the whole process into three stages, namely stage1, stage2, and stage3. Stage1 and stage2 will bring you a tool chain in, as well as a   and its dependencies. Stage3 will using the tool chain in  to bootstrap a complete system.

Preparation
You need an native tool chain as well as other programs like  to run the script. There are ways to achieve these requirements.

Method 0: Using an aarch64 Gentoo prefix
Yes, Gentoo prefix on Linux(RAP) could bootstrap itself to a different prefix path. This method is less time consuming than the following two, since you could directly go to stage3 without doing stage1 &amp; 2 with an existing Gentoo prefix installed.

Method 1: Using a native GNU/Linux environment
You could choose any Linux Distro that support aarch64 and install it on some device(Raspberry Pi 3 is a option).

The problem with this method is that it is hard to find powerful aarch64 machine running GNU/Linux. Using  with an Android device, or   with an amd64 GNU/Linux are acceptable workaround. After  into an aarch64 GNU/Linux, you could easily obtain a working tool chain with the package manager. Note that, 's performance is not so good, though still acceptable. Generally speaking, a normal laptop's performance under  is worse than a recent Android phone. What's more,  doesn't support all system calls, I encountered some errors when trying to bootstrap a stage3 Gentoo prefix with , while stage1 &amp; stage2 compiles happily with  , and you could copy stage2 to you Android device and doing stage3 there.

Method 2: Cross compile an aarch64 tool chain
There is an outdated wiki. Note that, current cross  command ignores   in its environment, but offers an command line options   for it. I haven't succeeded with this method.

Stage1 &amp; 2
Before compiling everything, you might want to read this wiki page.

According to this wiki page(It worths reading):

If you are lucky enough, you shall run these commands without any errors. If you encounter some errors, try to fix it by reading build logs. You don't need to delete all files between two trail, the script will handle it correctly. You might want to do a snapshot between commands as checkpoint or change portage configuration during the process.

Some of the problems I encountered are:


 * 1) Wrong   for   on Android and   refuse to compile, to fix it:

  not found on Android(or something like that), you could fix it by doing a simple soft linking.   Some package failed to merge since trying to installed files outside of. I encountered this problem when forcing a stable keywords by adding  to. To fix it: 

Or you could just stick to the default unstable keywords which works fine.

  and   not found, to workaround it:

Then manually editing  if necessary.

  failed to download distfiles(e.g. due to   not found), just download it else where and put it under portage's   directory.

Stage3
If you use Method 0 and you still want to use the helper script to do stage3, you need to manually do necessary soft links under  and   for bash, python, etc. Then soft link the   directory in previous Gentoo prefix to the new one. Don't forget to include the previous Gentoo prefix in :

Note that, the sequence matters.

After copying stage2 to your Android device, you could use the helper script to bootstrap stage3:

You might encounter errors similar to what I listed in previous section, and the solutions are similar, too. Other than already listed errors, problems I encountered in this stage are:


 * 1) Failed to build   due to some C++ errors. Simply disable the   use flag for , this use flag is not needed to build.
 * 2) Wrong shebang, fix it by manual editing the shebang or doing soft linking.

Finishing
You shall do a  after finishing doing stage3. You could use  to make it less time consuming. And since you might encounter errors, while  will not remember which package you have already rebuild:

Then edit  to get a package list. Do not delete packages' version! Then:

Script to start prefix
You might want to use a script to start the prefix. It is a bit more tricky for Android. Please refer to this wiki page for more information.

SSH
The  script doesn't work well with prefix. You might want to run  manually.

Put your publickey in  and change sshd's configuration so that root user could login. If you are still not able to do ssh, try adding  to the configuration file and restart the deamon.