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 libtool: warning: remember to run 'libtool --finish /usr/lib' (File-5.39)

Caused by prefix parameters.

Don't run anything and ignore the message.

The system has no more ptys. Ask your system administrator to create more.

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 Grub message.

The LFS disk was set up with BIOS/GPT.

Swap /boot out onto a separate partition.

When booting in LFS, the following message occurs in Grub error: hd1 cannot get C/H/S values.

This often happens if you create the /boot/grub/grub.cfg manually.

If you specify the LFS disk, the second disk in the system, as the first boot medium, the file must have a set root=(hd0,1) entry. As the second boot medium this is set root=(hd1,1).

Kernel Panic -- not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

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.

The Author

Markus Frei has been involved with server applications and the interaction of infrastructure and software development for over 25 years. He is the co-owner of Linuxfabrik in Zurich (https://www.linuxfabrik.ch/), which offers service and support for Linux and open source applications, as well as managed hosting.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Linux from Scratch 6.5 Available

    The Linux from Scratch (LFS) intensive training has been updated to version 6.5.

  • Linux From Scratch

    Linux From Scratch helps you create a custom Linux system with everything you need and nothing more. And as you build your system, you’ll get an insider’s look at how Linux really works.

  • Buildroot

    Whether you need a tiny OS for 1MB of flash memory or a complex Linux with a graphical stack, you can quickly set up a working operating system using Buildroot.

  • detLFS

    The detLFS project provides an ideal foundation for compiling Linux from source code, either to experience the fundamentals of how Linux works or to prepare an operating system for a project with very specific requirements.

  • Mozilla and Samsung Collaborate on New Browser Engine

    Mozilla is collaborating with Samsung on a new web browser engine called Servo.

comments powered by Disqus