Gentoo on Banana Pi

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:

  1. Extract a stage 3 tarball to the medium that will be the rootfs
  2. 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.

Base files

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:

  • script.bin
  • u-boot-sunxi-with-spl.bin
  • uImage – the kernel
  • boot/uEnv.txt

uEnv.txt contain U-Boot configuration (something like grub.conf):

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

Root filesystem

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

Final hacks

Root password

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.

Portage

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:

/etc/fstab

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.

Rate this post