Turn your Raspberry PI into an appliance

As anyone who’s regularly used a Pi in their projects knows, sooner or later either the power gets lost unexpectedly or you manage to lock it up playing fast and loose with low level coding… and you’re likely left with an SD card that’s corrupted. Equally with a finished project you don’t want to ssh into the PI just to close it down so you can switch it off, rather easier just to pull the power! While you can hack some off the shelf distro’s to run off a read only root, its usually not an ideal situation and a fair bit further hacking is probably required to slim down installed packages, and make sure there aren’t extra services running that could be a possible way to abuse your lovely installation.

I’d spotted the buildroot project some while ago and finally I had an excuse to use it. There are a number of advantages to using buildroot, for example by default root is mounted read only, and you have to explicitly select the option to mount it read write.

Buildroot comes with a bunch of default configs which can be found with:

make list-defconfigs

Happily there is one for the old Pi2 which I was repurposing and rescuing from a dusty death in my parts bin, and the config made a very good start indeed.

There is a very useful facility whereby you can have a hierarchy of files which are overlaid on the resulting image, this is ideal for settings and even an ssh host key, which is very convenient when testing.

Even better you can integrate your own code as a custom package, so your application can be built and included in your custom SD card image. While to be honest this is not surprisingly complex, I didn’t need to go much further than the rather excellent manual. This is definitely a case where you really do need to RTFM!

There are a wealth of options to choose, and I think the key here is to follow the KISS principle. Using the simplest possible init system and lightweight alternatives like dropbear for ssh, this way you have the simplest possible system, you’ll find configuration easier and there will be much less to go wrong, with as little as possible running in the background, hopefully meaning more ram for your application.

Given that buildroot is building its own cross compiler and tools and compiling and configuring a wide number of projects and the fact that it works (well!) its obvious that a great deal of work as gone in to making buildroot the quality project it self evidently is.

Leave a Reply

Your email address will not be published.