Build a minimal Raspberry Pi OS from source

Linux Emerges

During the download, you specified the kernel version but not the variant that matches the hardware. Raspberry Pi models belong to three hardware categories. At the lower end are the Raspberry Pi 1, the Pi Zero variants, and Compute Module 1 (CM1). At the upper end are the Raspberry Pi 4 and 400. In between are the Raspberry Pi 2 and 3 and CM3.

The next script creates the kernel and the base system:

$ export target=pi2
$ ./ |& tee 2_basesystem.log

The first line provides the correct mapping. Depending on the variant, the script generates its own kernel image (kernel.img, kernel7.img, and kernel8.img) and corresponding modules. If the variable is missing, the script generates a kernel for the Raspberry Pi 2/3/CM3 hardware group.

If you set the branch with a variable at download time as described above, then the script completes without any further interaction and creates a kernel with the default configuration. However, if you copy a .config file to the detLFS directory, the script calls make oldconfig. Because the sources are usually more recent than when the kernel configuration and some drivers were added; you need to answer a handful of questions. The simplest (and usually most sensible) variant is to accept the default value by pressing Enter.

For full control of the kernel configuration, set the MENUCONFIG variable. The value does not matter, the main thing is that the variable is not empty. In this case, the script calls make menuconfig, after which the kernel can be customized to your liking.

People who go to the trouble of making their own kernel often also change the boot logo. To do this, copy an image to the logo/ folder in the root directory of the project. The name must be mylogo.<xxx>; for a common JPEG file, this would be mylogo.jpg. If the convert tool from the ImageMagick package and the tools from the Netpbm package are on the system, the call in the last script converts the logo to the format expected by the kernel.

On the Card

After running the script to create the base system, all the files reside in the Destination/ folder. The original project copies the files directly to an SD card with the script. Alternatively, creates an image file that differs from the usual Raspberry Pi images in terms of size and content only. You can then transfer these to an SD card with the usual tools. Both scripts need root privileges, so you will have to run them with sudo.

If you use the original script, you have to enter the correct device name of your SD card reader beforehand into the script with an editor and remove the premature abort built in for safety.

After this step comes the moment of truth. If successful, the system boots with your own logo (Figure 4). On the first and second consoles, which you select with Alt+F1 and Alt+F2, respectively, a login for the root user with password root appears.

Figure 4: If you stored your own logo, it accompanies the boot messages.

First Boot

When you boot, the fast startup process is immediately noticeable: After the kernel hands over control to /sbin/init, not much happens. The SysVinit system starts the few processes from /etc/inittab; besides the two consoles mentioned earlier, these processes include the /etc/rcS script, which just prints a hello world message.

At this point, you could have a control program that takes control of the Raspberry Pi's GPIOs, for example. The original project also includes a script that can be used to send a few additional packets to the Pi and turn the system into a WiFi repeater. Essentially, the LFS system provides only an extremely minimal basis on which you can build your own projects.

Thanks to the multifunction binary BusyBox software suite, the system comes up with a number of programs that have all the basic functions of the standard programs but do without all the options to save space. Although it was no problem to configure the Pi's Ethernet interface and open a connection to the Internet, I had to look up the commands and syntax in my cheat sheets from more than 20 years ago. The usual distributions offer the luxury of simple configuration files.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More