User:Dr41nU/PinePhone

I started installing Gentoo on my pine phone after booting the PostmarketOS with Sxmo from the multiboot image from Megi.

For this guide, let's assume we have:
 * / (root) on emmc of 16Go
 * /var of 32Go (Firefox needs almost 16Go of tmp space in order to compile, and, if you use flatpak, you will need a lot of space too) on sdcard
 * /var/tmp on zram
 * /tmp on zram
 * /home on the remaining space (on sdcard)

I choose to install the root filesystem on the emmc and to have /home and /var on sdcard. Indeed, I think it can be a good practice to create partition for /var of /tmp in the SDCARD because they are likely to have a lot of read/write cycle, particularly on Gentoo since Gentoo use tmp dirs in /var during compiling process. So you will preserve your EMMC memory.

Moreover, I will use zram (for ram, /var/tmp - to handle small packages -, and /tmp).

A the moment, I use bingch overlay to install kernel sources and Phosh. For sway for exemple, you can have a look on this git repo : https://github.com/Dejvino/pinephone-sway-poc I use p-boot for the boot process.

Finally, depending on your needs, I can suggest to install tar (the Sxmo version is limited), screen and btrfs-progs

Here are my installation steps.

prepare disks
For this steps the amd64 handbook helps : https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Disks

Prepare Chroot
https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Stage

https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html#ARM-Options https://wiki.gentoo.org/wiki/Safe_CFLAGS#ARM

TODO : list make.conf flags

Without systemd
See https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/System#Networking_information for the network configuration

With Systemd
https://wiki.gentoo.org/wiki/Systemd

Prepare network for reboot on Gentoo
Create file /etc/systemd/network/50-dhcp.network :

Distcc setup
Since it can take a while to compile the entire system onboard, I should advice to use distcc.

The use of docker images makes it easy to configure on every systems.

As fas as I am concerned, I used the ksmanis Gentoo distcc image here: https://hub.docker.com/r/ksmanis/gentoo-distcc

Ksmanis provides a lot of different images that should suits your needs (for me: ksmanis/gentoo-distcc:arm64-tcp).

So once installed on every participating machines, you just have to follow theses simple steps:


 * configure distcc for participating hosts:

https://wiki.gentoo.org/wiki/Distcc#Specifying_participating_hosts


 * adapt the make.conf file to indicates that the emerge process now have to use distcc

https://wiki.gentoo.org/wiki/Distcc#Configure_portage

Please note that you should not use -march=native or -mtune=native in the CFLAGS or CXXFLAGS variables of make.conf when compiling with distcc.

If you are running your participating host inside your own network, I think there is no need to configure ssh connection or ever compression.

Compile and install kernel
https://github.com/umiddelb/armhf/wiki/How-To-compile-a-custom-Linux-kernel-for-your-ARM-device

Or if you have cross build environment installed on your amd64 host, you can cross compile the kernel on your amd64 host much quicker, on my i5 laptop it takes about 10 mins. I use wrapper like this $ cat /usr/local/bin/xmake exec make ARCH="arm64" CROSS_COMPILE="aarch64-unknown-linux-gnu-" INSTALL_MOD_PATH="${SYSROOT}" "$@"
 * 1) !/bin/sh

Then run the xmake as you would use make for compiling the kernel for pinephone

$ ebuild /var/db/repos/bingch/sys-kernel/pinephone-sources/pinephone-sources-5.10.12.ebuild prepare $ cd /path/to/portage_build_folder/portage/sys-kernel/pinephone-sources-5.10.12/work/linux-5.10.12/ $ cp arch/arm64/configs/pinephone_defconfig .config # or you can use the config files in sys-kernel/pinephone-sources/files/ $ xmake oldconfig; xmake menuconfig $ xmake -j9 Image modules # adjust j number as needed $ xmake DTC_FLAGS="-@" dtbs $ mkdir /tmp/boot $ xmake INSTALL_DTBS_PATH=/tmp/boot dtbs_install $ xmake INSTALL_MOD_PATH=/tmp/boot modules_install $ cp arch/arm64/boot/Image /tmp/boot $ rsync -avP /tmp/boot pinephone_ip:/tmp # copy kernel files to pinephone

Then on pinephone move files /tmp/boot to /boot and /lib/modules folders and re-configure new kernel

Using p-boot
Follow the p-boot README to install p-boot binary and other files into pinephone's /boot folder. $ ls -l /boot/ -rw-r--r-- 1 root root 15806472 Jan 31 10:42 Image-5.10.12 -rw-r--r-- 1 root root    1697 Jan 31 09:09 boot.conf drwxr-xr-x 3 root root    3488 Jan 31 09:03 dtbs-5.10.12 drwxr-xr-x 2 root root    3488 Jan 15 20:51 files -rwxr-xr-x 1 root root   61304 Sep 30 20:10 fw.bin -rw--- 1 root root 23844428 Jan 31 10:45 initramfs-5.10.12.img -rwxr-xr-x 1 root root  522128 Dec 31 17:30 p-boot-conf -rwxr-xr-x 1 root root  509840 Dec 31 17:45 p-boot-select -rwxr-xr-x 1 root root   66336 Dec 31 17:46 p-boot-start32 -rwxr-xr-x 1 root root     132 Dec 31 17:46 p-boot-start32.bin -rw-r--r-- 1 root root   32768 Dec 31 17:19 p-boot.bin You need the first partition of the boot media formatted as linux (83) partition, with enough space for kernel and other files, here's my SD card config /dev/mmcblk0p1      62500   500000   437501 213.6M 83 Linux Then write the p-boot.bin to boot media $ sudo dd if=p-boot.bin of=/dev/mmcblk0 bs=1024 seek=8 Here's the boot config $ cat /boot/boot.conf device_id = pp3 (PP 1.2a) no         = 0 name     = 5.10.12 (EMMC) atf      = fw.bin dtb      = dtbs-5.10.12/allwinner/sun50i-a64-pinephone-1.2.dtb linux    = Image-5.10.12 initramfs = initramfs-5.10.12.img bootargs = console=tty1 console=ttyS0,115200 root=/dev/mmcblk2p4 rootfstype=f2fs rootflags=fastboot rw rootwait quiet splash   = files/xnux.argb Command to write boot kernel and other files to boot partition $ cd /boot $ sudo ./p-boot-config. /dev/mmcblk0p1

Initial configuration for systemd
As a matter of fact, some steps can't be done on chrooted environment

At this point, I installed screen one again to gain confort for last steps

Enable zram
https://wiki.gentoo.org/wiki/Zram

and modify startup command as follows:

This will reserve a 1Go swap space. Please note that -d0 is unnecessary since by default the zram-init script will use slot #0.

And the same for zram_tmp

add

By this command you will mount a drive on /tmp of 124Mo in the ZRAM slot #1

add

This command mount a drive on /var/tmp of 1Go in the ZRAM slot #2. Then mask tmp.mount as it is replaced by zram_tmp

And finaly, enable the units

Emerge stuff
At this time, compilation process can be very long. A usefull tip, if the compilation process is halted, is to continue by submitting

Final configuration
Start Squeekboard at session startup

Enable screen keyboard (if necessary)

Add various services