I like to use Gentoo for most of my tasks (except the smallest systems that run OpenWrt). I also wanted to have it on the Banana Pi. I did not find any specific manual for Gentoo and the Banana, so I followed the standard, two-step installation manual for any architecture:
- Extract a stage 3 tarball to the medium that will be the rootfs
- Try booting the kernel into it
Of course getting a distribution, regarded as one of the least beginner-friendly, to work is not exactly a two-step process, but a kernel and a rootfs is enough to get started.
SD card partitioning
The card has to be split to at least two partitions:
- small /boot partition (20MB is enough)
- main / rootfs partition
Banana Pi’s bootloader is the common U-Boot. I first tried using vfat for /boot but U-Boot would not run, then I tried ext2 – success. Root filesystem is formatted with btrfs. I think that it is stable enough and is the easiest one to get running among flash-friendlies.
These files are specific to the Banana Pi, not Gentoo. I mostly followed the Bootable SD card HOWTO from linux-sunxi wiki.
The first partition must contain the following files:
- uImage – the kernel
uEnv.txt contain U-Boot configuration (something like grub.conf):
bootargs=earlyprintk console=ttyS0,115200 root=/dev/mmcblk0p2 rootfstype=btrfs elevator=deadline rootwait net.ifnames=0 sunxi_g2d_mem_reserve=0 sunxi_ve_mem_reserve=0 sunxi_no_mali_mem_reserve
aload_script=ext2load mmc 0 0x43000000 script.bin;
aload_kernel=ext2load mmc 0 0x48000000 uImage;bootm 0x48000000;
uenvcmd=run aload_script aload_kernel
I followed the Kernel page from linux-sunxi. I don’t need the latest features, so the “evil”, non-mainline kernel is enough for me. Of course a cross-toolchain for ARM is required to compile the kernel (as a Gentoo user you can simply get it via crossdev -t arm-unknown-linux-gnueabihf).
There is a stage3 tarball ready. Banana Pi is an arm7 architecture with hardware floating-point (hardfp). It is different from Raspberry Pi that is an arm6 architecture (I think arm6 binaries can run on arm7 but not the other way around). Tarballs can be found here: http://distfiles.gentoo.org/releases/arm/autobuilds/current-stage3-armv7a_hardfp/.
The file has to be extracted to the second SD card partition using tar -xjpf tarball-name.tar.bz2
There is no password set in the tarball stage, so you will not be able to log into the system. Banana Pi is a different architecture than a PC, so you can’t just chroot into the SD card because passwd inside will not work. I copied and pasted the hash from /etc/shadow of a known user from my PC.
A working Gentoo installation will need a complete /usr/portage directory. It contains lots of small files, so it would take a lot of time to create them on the SD card. My solution is to make a squashed portage tree on a PC and copy a single file onto the SD card. This requires squashfs-tools:
mksquashfs /usr/portage portage-20150624.squashfs -comp xz
Of course it has to be done for each update of the tree.
I want to keep temporary files in a RAM-disk, /etc/portage/make.conf requires some settings:
All temporary files belong in the RAM. 🙂 The size specified is the maximum size, if there are no files then RAM is free (they also do not have to add up to the total size of the RAM). The sizes might not be enough for compiling larger packages, you can temporarily create a swapfile on the memory card or an external HDD and add it to the memory pool via swapon.
/dev/mmcblk0p1 /boot ext2 noauto,noatime 1 2
/dev/ROOT / btrfs noatime 0 1
none /var/log tmpfs size=100M 0 0
none /var/run tmpfs size=100M 0 0
none /run tmpfs size=200M 0 0
none /tmp tmpfs size=600M 0 0
none /var/tmp tmpfs size=200M 0 0
/root/portage.squash /usr/portage squashfs noatime 1 2