Start with Scratch: Learn Linux by rolling your own distro

Linux From Scratch teaches you how to bake a complete Linux system, minus cutting-edge details like Docker -- although for those allergic to systemd, you can leave that out too

If you want to learn learn Linux from top to bottom, what better way to learn than by rolling your own mini distribution?

Linux From Scratch, a combination software project and book, now in a newly released 8.0 revision, provides a step-by-step guide to building an entire functional Linux system from the ground up. It's a valuable and revealing project, though it doesn't directly cover the cutting edge of the Linux world.

Bake your own Linux right at home

Most Linux tutorials focus on working with an existing Linux distribution with some name-brand recognition: Red Hat/Fedora, Ubuntu, Suse, and so on. LFS assumes that the user doesn't simply want to learn how things work from the outside, but to understand the internals of Linux system design and create their own distribution for specific projects.

The core LFS project begins with an existing Linux distribution as a development environment, such as one of the aforementioned Linuxes. There, the user creates a dedicated partition where the new Linux lives, downloads the needed packages, and assembles the toolchain needed to build them. Everything in the new distribution, from the kernel to the userland packages, is built from source, with the book providing guidance along the way as to how all the pieces fit together.

Other LFS projects expand on the original concept. Beyond Linux From Scratch discusses adding software packages for many common use cases: GUIs and display managers, servers, multimedia, networking utilities, and so on. Automated Linux From Scratch provides tools for automating the LFS build process, Cross Linux From Scratch deals with cross-compilation (such as building a LFS system for ARM processors on x86), and Hardened Linux From Scratch provides instructions for setting up an LFS system with heightened security.

The most recent revision of Linux From Scratch doesn't modify this formula a great deal. The release notes say version 8's big change is "the removal of the symbolic link from /lib to /lib64 and the complete removal of /usr/lib64." The rest of it is simply bringing commonly used packages up to date, such as the standard GNU C library glibc and the gcc C compiler.

Some ingredients optional

LFS also covers a recent change to Linux that's been tremendously divisive: the systemd initialization system. There are two distinct versions of LFS, one with systemd and the other without. Most every major Linux distribution has embraced systemd at this point, but for learning purposes, it's wise to keep alive detailed discussion of how a non-systemd Linux system is composed for comparison.

The LFS approach leaves out everything that doesn't absolutely need to be there, so LFS distributions tend to be highly compact, which helps when building an embedded distribution, especially when combined with the techniques found in Hardened Linux From Scratch. The unikernel approach could make it easier to embed a single application, where the app in question and its supporting libraries are baked into a custom Linux kernel. But existing Linux hands may find the LFS approach more familiar and easier to understand.

Of course, LFS doesn't cover all aspects of modern Linux distributions. Package management, for instance, isn't a native part of any LFS-created distribution. The book provides discussion of the various package management approaches, but it doesn't recommend a particular one or provide detailed integration instructions. Also, while Docker and containers generally are based on native Linux kernel services, LFS doesn't explicitly discuss them, as they're not used as part of the default LFS toolchain. That said, there's nothing stopping you from adding Docker to an LFS distribution and learning more on your own about how it's used.