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
-
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.
-
Fedora 41 Released with New Features
If you're a Fedora fan or just looking for a Linux distribution to help you migrate from Windows, Fedora 41 might be just the ticket.
-
AlmaLinux OS Kitten 10 Gives Power Users a Sneak Preview
If you're looking to kick the tires of AlmaLinux's upstream version, the developers have a purrfect solution.
-
Gnome 47.1 Released with a Few Fixes
The latest release of the Gnome desktop is all about fixing a few nagging issues and not about bringing new features into the mix.
-
System76 Unveils an Ampere-Powered Thelio Desktop
If you're looking for a new desktop system for developing autonomous driving and software-defined vehicle solutions. System76 has you covered.
-
VirtualBox 7.1.4 Includes Initial Support for Linux kernel 6.12
The latest version of VirtualBox has arrived and it not only adds initial support for kernel 6.12 but another feature that will make using the virtual machine tool much easier.
-
New Slimbook EVO with Raw AMD Ryzen Power
If you're looking for serious power in a 14" ultrabook that is powered by Linux, Slimbook has just the thing for you.
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.