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
-
The GNU Project Celebrates Its 40th Birthday
September 27 marks the 40th anniversary of the GNU Project, and it was celebrated with a hacker meeting in Biel/Bienne, Switzerland.
-
Linux Kernel Reducing Long-Term Support
LTS support for the Linux kernel is about to undergo some serious changes that will have a considerable impact on the future.
-
Fedora 39 Beta Now Available for Testing
For fans and users of Fedora Linux, the first beta of release 39 is now available, which is a minor upgrade but does include GNOME 45.
-
Fedora Linux 40 to Drop X11 for KDE Plasma
When Fedora 40 arrives in 2024, there will be a few big changes coming, especially for the KDE Plasma option.
-
Real-Time Ubuntu Available in AWS Marketplace
Anyone looking for a Linux distribution for real-time processing could do a whole lot worse than Real-Time Ubuntu.
-
KSMBD Finally Reaches a Stable State
For those who've been looking forward to the first release of KSMBD, after two years it's no longer considered experimental.
-
Nitrux 3.0.0 Has Been Released
The latest version of Nitrux brings plenty of innovation and fresh apps to the table.
-
Linux From Scratch 12.0 Now Available
If you're looking to roll your own Linux distribution, the latest version of Linux From Scratch is now available with plenty of updates.
-
Linux Kernel 6.5 Has Been Released
The newest Linux kernel, version 6.5, now includes initial support for two very exciting features.
-
UbuntuDDE 23.04 Now Available
A new version of the UbuntuDDE remix has finally arrived with all the updates from the Deepin desktop and everything that comes with the Ubuntu 23.04 base.