This repsitory shows how to use Buidroot to build your own Linux Kernel based OS for the Raspberry Pi. Build the entire OS on an x86 host - this takes around 10 minutes on my AMD ThreadRipper 12-core (24 hyperthreaded).
Up front - Buildroot doesn't include runtime package management - it's designed for building appliances really - build a fixed, known working system from a configuration file. So if you're wanting to build an OS where security patching is just a few commands away, Buildroot is not for you.
If you want to build a lightweight OS for the Raspberry Pi that performs a specific function, then Buildroot could well be for you - but again - no security patching. You'd have to manage this yourself if you wanted to go that route.
Firstly, get the buildroot code: git clone git://git.buildroot.net/buildroot
Now we can go ahead and build one of the default raspberry pi Buildroot targets to test that it works OK.
Let's build a 64-bit OS for the Raspberry 3...
make raspberrypi3_64_defconfig
NOTE: To see all options you can see what configurations exist
ls configs/ | grep raspberry
The make config
command above makes a configuration file suitable for building the target system and includes all of the options required to build a complete OS.
Build the OS:
make
NOTE: Do not use the parallel make flag here because Buildroot takes care of that later on in the build process for you (based on the number of cores your machine has)
Drink Tea, etc.
When the build finishes (Takes about 10 minutes) - there will be an SD Card image under output/images
called
sdcard.img
- we write this to the SD Card and boot the RPi:
NOTE: MAKE SURE YOU GET THE WRITE DEVICE, AS OTHERWISE YOU RISK TRASHING YOUR HOST MACHINE!
cat output/images/sdcard.img > /dev/sda && sync && eject /dev/sda
There you have it - a new OS that you built from scratch!
Of course - what we've done is get a bog standard install. The entire SD Card image is 159M - it's pretty compact.
The next thing we're going to want to do is to make some changes. After the make raspberrypi3_64_defconfig
above we
can choose to make change through the menu configuration system. It's the same as is used to configure the Linux
Kernel when building that. We can make changes like so:
make menuconfig
The menuconfig starts configuring the .config
file that was generated by make *_defconfig
Within the menu system you can navigate around and make changes as you see fit. For example under the
Toolchain -> C library
option you can select the C Library to use for your system. There are a few options,
including uc
and glibc
as well as musl
.
Under the Kernel menu you can select wthe kernel source code you'd like to use for your OS.
Under Target Packages
you can select all of the things you want to include in your OS.
If you're not sure what an option means you can press ?
with the option selected to get further help.
Press ESC
to come out of the menu driven configuration tool. Eventually you'll be asked to save the configuration
you've modified. Just answer Yes
and this will save you a new .config
file which you can then build using make
.
Once you're happy with your build, you can take a copy of the .config
file as a complete OS configuration to be
able to build again in the future.