Building Linux from Scratch
Configuring the System
Chapter 9 is about configuring the network stack. If so desired, you can disable predictable network interface device names, which I will do (Listing 4). This means that LFS detects the first NIC in the system as the classic eth0
. DHCP gives you an IP address; then you move on to configure name resolution and assign a hostname.
Listing 4
Using Classic Interface Names
# ln -s /dev/null /etc/systemd/network/99-default.link
Minor configuration work on the system clock, the Linux console, and the settings for the system locales complete the system. If you are in doubt about the appropriate locales, check the files /usr/share/keymaps
and /usr/share/consolefonts
.
Making the System Bootable
It is now time to make LFS bootable. Chapter 10 starts by creating an /etc/fstab
file that points to the LFS partitions, sda1
(system) and sda2
(swap). Now build and install the Linux kernel. Because later extensions, such as in BLFS, always require reconfiguration of the kernel, do not delete the source code after the build. Grub-install puts the boot loader on the disc; you can then configure it with Grub-mkconfig.
Using make defconfig
in the code section, LFS configures the kernel without interaction and with meaningful default values. If necessary, you can change these settings and use the text-based kernel configuration variant via make menuconfig
to manually set the myriad parameters of the kernel. Important: The makers of Systemd strongly recommend the use of IPv6. You will want to switch the kernel features from Listing 5 on or off to match the network settings.
Listing 5
Important Kernel Features
General setup --> [ ] Auditing Support [CONFIG_AUDIT] [*] Control Group support [CONFIG_CGROUPS] [ ] Enable deprecated sysfs features to support old userspace tools [CONFIG_SYSFS_DEPRECATED] [*] Configure standard kernel features (expert users) [CONFIG_EXPERT] ---> [*] open by fhandle syscalls [CONFIG_FHANDLE] Processor type and features ---> [*] Enable seccomp to safely compute untrusted bytecode [CONFIG_SECCOMP] Firmware Drivers ---> [*] Export DMI identification via sysfs to userspace [CONFIG_DMIID] Networking support ---> Networking options ---> <*> The IPv6 protocol [CONFIG_IPV6] Device Drivers ---> Generic Driver Options ---> [ ] Support for uevent helper [CONFIG_UEVENT_HELPER] [*] Maintain a devtmpfs filesystem to mount at /dev [CONFIG_DEVTMPFS] Firmware Loader ---> [ ] Enable the firmware sysfs fallback mechanism [CONFIG_FW_LOADER_USER_HELPER] File systems ---> [*] Inotify support for userspace [CONFIG_INOTIFY_USER] Pseudo filesystems ---> [*] Tmpfs POSIX Access Control Lists [CONFIG_TMPFS_POSIX_ACL]
Conclusion and Reboot
You have now completely installed LFS and can immortalize your name in two files, /etc/lsb-release
and /etc/os-release
. Logout from the chroot, set a root password, and unmount $LFS
– nothing else stands in the way of a reboot. (If you run into any problems, see Table 1 for some troubleshooting tips.) If you selected the LFS disk as the primary boot medium in the build VM, your LFS will be up and running after a short time.
Table 1
Tips for Troubleshooting
Symptom | Cause | Remedy |
---|---|---|
Build action reports |
Caused by prefix parameters. |
Don't run anything and ignore the message. |
|
You may have rebooted the build host after step 7.3 and forgotten to remount the device nodes before the Chroot. |
Complete code sections 7.3 and 7.4 again. |
LFS simply freezes after the boot and outputs a |
The LFS disk was set up with BIOS/GPT. |
Swap |
When booting in LFS, the following message occurs in Grub |
This often happens if you create the |
If you specify the LFS disk, the second disk in the system, as the first boot medium, the file must have a |
|
It looks like there are some drivers missing for the medium you are using. |
If you are using VirtIO disks, add the drivers or move to SATA disks. |
As you wade through the details of the process described in this article, you will quickly see that building Linux from Scratch takes a lot of time, energy, and attention. The team around the LFS project leader, Gerard Beekmans, has several answers to the question of whether this effort is worthwhile.
The LFS project will provide you with hands-on practice with building your own distribution. You'll learn about all the necessary components and how they interact with each other. You'll also learn about the build process itself. If you want to, you can use LFS as a starting point for your own development contributions.
At the end of the process, LFS provides you with an up-to-date, working, and very compact Linux system that includes not much more than the kernel and some tools. Building a distribution yourself helps you stay extremely flexible. LFS gives you the shell of a house that you can customize to suit your own taste, from one-room apartment to luxury villa. LFS can be completely audited if required, and, perhaps even more importantly, you have complete control over all security patches. Last but not least: LFS is simply cool.
To dampen expectations a bit: LFS is not especially convenient for a production environment. An SSH daemon is missing, as are Sudo, Wget, and Parted. LVM is not available to manage the file system, and the network stack is anything but complete. BLFS helps you implement those features as advanced topics.
Be aware of the fact that you will need to keep your LFS system up-to-date by downloading and compiling security updates on a regular basis. For this, the Linux from Scratch documentation discusses a process for simplifying the package management process and defining a package user [15]. A package manager is not used in the entire LFS project, although it is possible to extend LFS by adding a manager such as Pacman or GNU Stow [14]. Your self-built Linux distribution also lacks features such as an active user community, QA-tested packages including errata, an extensive mirror network, contactable developers, and conveniences such as a wiki, IRC chat, mailing lists, forums, bug trackers, or an FAQ.
With LFS, Linux knowledge is not taught but assumed, so you'll need some background in Linux to get started. But if you're ready to roll up your sleeves and dive in, Linux from Scratch will help you build a deeper understanding of the Linux kernel and open source software.
Infos
- Linux From Scratch: http://www.linuxfromscratch.org/lfs
- Beyond Linux From Scratch: http://www.linuxfromscratch.org/blfs
- Yocto Project: https://www.yoctoproject.org
- Linux Target Image Builder: http://ltib.org
- OpenWrt: https://openwrt.org
- Scratchbox: http://www.scratchbox.org
- Posix: http://pubs.opengroup.org/onlinepubs/9699919799/
- File System Hierarchy Standard: http://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html
- Linux Standard Base: https://refspecs.linuxfoundation.org/lsb.shtml
- LFS with SysVinit: http://www.linuxfromscratch.org/lfs/view/stable
- LFS with Systemd: http://www.linuxfromscratch.org/lfs/view/stable-systemd
- Predictable Network Interface Names: https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/
- Bash Path Hashing: https://www.computerhope.com/unix/bash/hash.htm
- GNU Stow: https://www.gnu.org/software/stow
- Package-User approach: http://www.linuxfromscratch.org/hints/downloads/files/more_control_and_pkg_man.txt
« Previous 1 2 3 4
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
-
Zorin OS 17 Beta Available for Testing
The upcoming version of Zorin OS includes plenty of improvements to take your PC to a whole new level of user-friendliness.
-
Red Hat Migrates RHEL from Xorg to Wayland
If you've been wondering when Xorg will finally be a thing of the past, wonder no more, as Red Hat has made it clear.
-
PipeWire 1.0 Officially Released
PipeWire was created to take the place of the oft-troubled PulseAudio and has finally reached the 1.0 status as a major update with plenty of improvements and the usual bug fixes.
-
Rocky Linux 9.3 Available for Download
The latest version of the RHEL alternative is now available and brings back cloud and container images for ppc64le along with plenty of new features and fixes.
-
Ubuntu Budgie Shifts How to Tackle Wayland
Ubuntu Budgie has yet to make the switch to Wayland but with a change in approaches, they're finally on track to making it happen.
-
TUXEDO's New Ultraportable Linux Workstation Released
The TUXEDO Pulse 14 blends portability with power, thanks to the AMD Ryzen 7 7840HS CPU.
-
AlmaLinux Will No Longer Be "Just Another RHEL Clone"
With the release of AlmaLinux 9.3, the distribution will be built entirely from upstream sources.
-
elementary OS 8 Has a Big Surprise in Store
When elementary OS 8 finally arrives, it will not only be based on Ubuntu 24.04 but it will also default to Wayland for better performance and security.
-
OpenELA Releases Enterprise Linux Source Code
With Red Hat restricting the source for RHEL, it was only a matter of time before those who depended on that source struck out on their own.
-
StripedFly Malware Hiding in Plain Sight as a Cryptocurrency Miner
A rather deceptive piece of malware has infected 1 million Windows and Linux hosts since 2017.