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 $ ./2_basesystem.sh |& 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 4_mksdcard.sh
script. Alternatively, 4_mkimg.sh
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 4_mksdcard.sh
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.
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.
« Previous 1 2 3 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
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.
News
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.