Rebuilding the RasPi Kernel

Building the Linux kernel takes awhile, for anyone who doesn't know or hasn't had the pleasure of having to do so. With the dawn of the Containerization Age, some people know that Docker is an incredible platform for development and production, but it also relies heavily on features available to the Linux kernel.

Those of you that want to play with Docker on your Raspberry Pi's are slightly in a tough place. Most, if not all, of the distros built for the Pi do not include the AUFS kernel module and patches.

To ease the burden of recompiling a kernel, I'm building a Docker container that abstracts away the entire build process. It even builds the kernel with AUFS patches and with the hard float (gnueabihf) version of GCC to take advantage of the float instructions on the Pi's ARM chip.

The Docker container is already pretty close to finished, I'm just putting the final few tweaks on the build scripts before I start the builds in the Docker registry. Until then, you can pull the repository off Github and build the container for yourself with this:

git clone
cd rpi-kernel-build
docker built -t maiome/rpi-kernel-build .

And that will give you a full, working copy of the container.
There are several environment variables that you can expose to the container to change the ways that builds happen:

  • AUFS_ENABLE -> adds the CONFIG_AUFS_FS=m to the kernel config if set to "YES"
    • Default: YES
  • PARALLEL_OPT -> sets the number of "job slots" Make should run at once. Should be related to the number of processors in your machine. (3 for dual-core, 6 for quad-core, so on and so forth...)
    • Default: 3
  • UPDATE_EXISTING -> only means anything if USE_EXISTING_SRC is also set. will pull new sources from the git repo on existing sources, if available.
    • Default: NO
  • USE_EXISTING_SRC -> will make the build system attempt to use existing sources first, if they are available. if any single source directory (AUFS, RPI-firmware, RPI-linux) is missing, all of them will be re-fetched.
    • Default: NO
  • USE_HARDFLOAT -> will tune the cross-compiler used when building the kernel (hardfp / gnueabihf vs. softfp / gnueabi)
    • Default: YES

To run the container, grab some popcorn and do:

docker run -it -v /path/to/kern/output:/kern -e PARALLEL_OPT=<whatever> maiome/rpi-kernel-build

Of course, adjust your PARALLEL_OPT and your /path/to/kern/output and whatever other variables you'd like.

After the build completes, your output folder will contain a few things:

  • /firmware -> new firmware files for boot
  • /linux -> folder containing:
    • /kernel.img -> newly compiled kernel
    • /rpi-config -> config used to build the kernel
    • /modules/ -> new set of modules from the build

Good luck on your adventures.
Also, stay tuned for some pi-docker goodness and some pre-built AUFS-enabled kernels ;)

EDIT (3/10/15): maiome/rpi-kernel-build will be available on the Docker Registry as an automated build as soon as the Docker team fixes their website... There are several kernel builds available for download here. The latest kernel build (kernel-bcmrpi-armhf-031015.tgz) contains CONFIG_AUFS_FS, CONFIG_DM_THIN_PROVISIONING, CONFIG_OVERLAY_FS, CONFIG_CPUSETS, and all the CONFIG_MEMCG_* and CONFIG_CGROUP_* that should be needed for lxc and docker! Enjoy!

EDIT (3/16/15): I did some playing with the Docker Registry to see if I could make the automated builds work and suddenly, after switching my Github account from read/write to read-only, everything started working again. Project builds are now available from the Docker hub and now it really is as simple as docker pull maiome/rpi-kernel-build!

Sean Johnson

Software developer, music enthusiast, college student, and cat lover. Currently enthralled by the world of networking, security, and cloud technology.

San Antonio, TX

Subscribe to Land of Weird Things

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!