Build buildroot image for Raspberry Pi using docker

In this turtorial i will build a buildroot image for Raspberry Pi using docker on a Macbook. I have previously used buildroot but at that time I was using a linux machine and it was very easy to setup. However it is not as easy when your main machine is a macbook and that is where docker comes in as a rescue.

The plan is to build a buildroot image (Operating system) for Raspberry Pi which is smaller than the Raspbian and therefor has shorter startup time.

What you will need

If you have not setup your Raspberry Pi with an operating system this tutorial will show you how that is done.

Tutorial

Docker

If you have not installed docker on your machine go ahead and install the docker client. You can find it here.

When docker is installed you should be able to print the version

Build docker image

Since buildroot is not supporting to build images on mac we will use a docker image to build the image. I have created a generic Dockerfile which includes a Linux distro and all the dependencies for buildroot. It can be found here.

# docker build –tag rpi-buildroot:1.0 .

To view the newly created images you can type the following.

# docker images

Now that a docker image has been created we need to create a docker container for the image. We create the container with a “run” command and with the flag “-it” we land into its command line directly after the creation which is very convenient.

# docker run -it rpi-buildroot:1.0

Buildroot

As you probably noticed buildroot is already installed on the docker container and this is because it was included in the Dockerfile.

Buildroot has a lot of different preconfigured configurations for different boards and Raspberry Pi is one of them. To choose which configuration you want (it depends on the Raspberry Pi board you have) you simply type

# make {e.g. raspberry3_defconfig}

Different configurations for Raspberry Pi

Menuconfig

The big advantage of buildroot is the easy way to create your very own linux distro with just the applications and libraries you want. One way of doing this is through a terminal gui called menuconfig. Type “make menuconfig” and make the adaptions you want, e.g. do you want support for Java or Erlang, add it!

Build image

The final step is to build the image and it is even easier, all you type is “make”. This step will take a lot of time, don’t be surprised if it takes somewhere between 1-2 hours.

# make

When it is ready you will find an image file called “sdcard.img” in the directory “/buildroot/output/images”. This is the operating system that we will install onto the sdcard.

Copy image to Sd card

The build linux image is inside the container and therfor you need to copy the image file to your host before you can deploy it to an SD card.

# docker cp {container-id}:/buildroot/output/images/sdcard.img .

The only thing left now is to install the operating system on to the SD card and I suggest you follow the offical guide which can be found here.

Its alive!

Insert the SD card with its newly deployed operating system and it should boot up! Its alive 😀

It is alive! The login is “root” by the way.

Wifi

As you probably soon find out is that the Wifi is not working out of the box when creating a buildroot linux distro for Raspberry Pi. This is fixable but requires some more libraries. Type “make menuconfig” in the buildroot folder in your container and add the following packages.

  • Hardware Handling -> Firmware -> rpi-wifi-firmware
  • Networking applications -> wpa_supplicant
  • Networking applications -> wpa_supplicant – Enable 80211 support
Modify the file “/buildroot/output/target/etc/network/interfaces” to look like this
Modify the file “/buildroot/output/target/etc/wpa_supplicant.conf” to look like this.
The file “/buildroot/output/target/etc/inittag” should look like this. Insert loading of Wifi driver before running any rc scripts.

Summary

This tutorial has shown you how easy it is to build an operating system using buildroot for Raspberry Pi even on a macbook (with a little help of docker). I only showed how to build the standard Raspberry Pi build root linux distro, it is now up to you to modify the image the way you want it.

What’s next?

The goal for this project was to reduce the start up time for the Raspberry Pi and i did succeed with that. However it still takes quite some time to boot up. Next for me is to figure out what takes time in the boot process and strip things down even further.

I will also look into how to add SSH to the operating system.

What is next for you?