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
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.