Circle Device


Quick Reference

Gentoo on Raspberry Pi

Gentoo on Raspberry Pi

Gentoo, being a source distribution, is not the best fit for a Raspberry Pi. Compiling all the packages takes a lot of time and is not the best for your SD Card. To counter this problem we can use distcc and crossdev but I would prefer to use crossdev and the binary packages option for my Pi.

Lets get started... I am going to create packages for nano, it is a relatively simple but has a few dependencies.

Setup crossdev and Custom Repository

Firsly emerge sys-devel/crossdev and create the required directories and files.

emerge sys-devel/crossdev
mkdir -p /usr/local/portage/crossdev/{profiles,metadata}
echo 'crossdev' > /usr/local/portage/crossdev/profiles/repo_name
echo 'masters = gentoo' > /usr/local/portage/crossdev/metadata/layout.conf
chown -R portage:portage /usr/local/portage/crossdev

Tell portage to use the gentoo repository and as the fallback and crossdev will create ebuilds in /usr/local/portage/crossdev for the generated packages. Below is /etc/portage/repos.conf/crossdev.conf (if you don't have /etc/portage/repos.conf/ you should create it):

priority = 9999
masters = gentoo
auto-sync = no
location = /usr/local/portage/crossdev

Initialise the repository:

crossdev -t armv7a-unknown-linux-gnueabihf --stable --init-target -oO /usr/local/portage/crossdev

Change the use flags to disable some use flags (I am not sure if this is required...):

echo "cross-armv7a-unknown-linux-gnueabihf/gcc -sanitize -vtv" >> /etc/portage/package.use/crossdev

Create the toolchain:

crossdev -t armv7a-unknown-linux-gnueabihf --stable -oO /usr/local/portage/crossdev

Cool! with that you should be able to compile a very simple hello world C programme with your ARM cross compiler. If you cannot then you should get this working before continuing. See Appendix A for how to do this.

Configure the make.profile and make.conf

Check in /usr/armv7a-hardfloat-linux-gnueabihf/etc/portage/make.conf and if I were you I would put buildpkg in your features line, it is probably already there, mine looks like this:

FEATURES="-collision-protect sandbox buildpkg noman noinfo nodoc"

You can build packages on a per emerge basis by specifying it at emerge time with --buildpkg but you might forget ;-).

These steps set the correct profile, by default you are probably using the embedded profile which will not work to emerge stuff for your Pi:

cd /usr/armv7a-unknown-linux-gnueabihf
ln -s /usr/portage/profiles/default/linux/arm/13.0/armv7a/ etc/portage/make.profile

Emerge nano

Now the fun part emerging nano:

armv7a-unknown-linux-gnueabihf-emerge app-editors/nano

This on my system portage pulled in 5 packages:


This may take some time, you can always make it faster by changing the MAKEOPTS="-j4" in /usr/armv7a-unknown-linux-gnueabihf/etc/portage/make.conf depending on your system.

Once complete the emerge should have installed executables and generated some binary packages in the packages directory:


Now you can install them on your Pi.

Installing a Binary Package

Now it is time to get the package on your Raspberry Pi. For this I would recommend configuring a binary package host.

I plan on configuring a public one some time soon hosted on this server to use it please look at my binary package host page. Configuring a binary package host is a little out of scope please see the Gentoo Wiki.

To get the packages on your Pi copy them from the armv7a-hardfloat-linux-gnueabi/packages/ directory to the /usr/portage/packages/ directory (or wherever you configured your PKGDIR). The structure is important!

Now you can try and emerge nano, make sure your portage tree is at least as up to date as the tree on the generating machine.

emerge -pv --usepkgonly app-editors/nano

The output looks like this (with pretty colours):

[binary     U ~] app-editors/nano-2.7.5::gentoo [2.5.3::gentoo] USE="magic ncurses nls spell unicode -debug -justify -minimal -slang -static" 0 KiB

The only thing I should say now is be careful of USE flags and KEYWORDS. Of course remove the -pv to actually install the package.

nano --version
GNU nano, version 2.5.3
(C) 1999..2016 Free Software Foundation, Inc.
Email:    Web:
Compiled options: --disable-justify --disable-wrapping-as-root --enable-utf8

After emerge:

GNU nano, version 2.7.5
(C) 1999..2016 Free Software Foundation, Inc.
(C) 2014..2017 the contributors to nano
Email:    Web:
Compiled options: --disable-justify --disable-wrapping-as-root --enable-utf8

I bet you were surprised weren't you!?

Use the Build Machine as your Binary Package Host

This is simple and really quite cool!

Setup your build machine's ssh account with the public key of your Raspberry Pi so that the Pi can download the binary packages over ssh. In my case the build machine is listening on port 2225. Below are the lines in make.conf:


And, provided the USE flags are the same on the build host and your Pi emerge should now check the binary package host before compiling packages.

emerge -pv media-video/raspberrypi-omxplayer

Appendix A

Writing and Compiling a simple programme for Raspberry Pi 2. Create main.c with the following content.

#include <stdio.h>

int main(int argc, char * argv[]) {
    fprintf(stdout, "Hello World!");

Then compile it like this:

armv7a-unknown-linux-gnueabihf-gcc -o main main.c

And try to execute the resulting file on your Raspberry Pi.


Quick Links: Techie Stuff | General | Personal | Quick Reference