On the DVD

Cross-Compiling

To minimize the influence of the build host's operating system, you need to make sure that the LFS system is independent of it. Chapters 5 and 6 help you create the software tools you'll need to build Linux From Scratch. You then deploy these tools in an isolated chroot environment only for the purpose of building LFS.

The build process is based on the principle of cross-compiling: A cross-compiler is typically used to compile code for other system architectures. On your build machine, a cross-compiler is theoretically not necessary because you are most likely building on x86_64 for x86_64. However, you will want LFS to be free of inlinked software from the build host, which a cross-compiler guarantees.

The LFS documentation assumes you have three hosts, each with a different architecture. Host A has a compiler for its own architecture. The host is slow and its capacity is limited. Host B does not have a compiler initially, but it is fast and well equipped. It will be producing the software for Host C. Host C, with yet another architecture, also has no compiler and is small and slow.

This scenario requires two cross compilers: Cross-Compiler A and Cross-Compiler B. On Host A, the compiler builds Cross-Compiler A, which in turn builds Cross-Compiler B. Cross-Compiler B is used on Host B to build Compiler C and all programs for Host C. However, they cannot be tested on Host B. Therefore, Compiler C rebuilds and tests itself on Host C.

For LFS, you need to use the cross-compiler to compile not only the C compiler but also the glibc and libstdc++ libraries. The problem is that, to be built, the C compiler relies internally on libgcc, which in turn has to be linked against glibc – which doesn't exist yet.

To work around these circular dependencies, first build a minimal version of the cross-compiler build host that is just about good enough to compile a full-fledged glibc, as well as a minimally functional libstdc++. The libstdc++ library will be built again later in the chroot environment, this time completely. See the Toolchain Technical Notes at the beginning of Part III of the LFS book for more on the LFS build environment.

Conclusion

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. If you have the time and inquisitiveness, 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 filesystem, and the network stack is anything but complete. BLFS, which is available at the Linux From Scratch website, 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 [5]. 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 [6]. 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.

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

    If you really want to learn about Linux, build it from scratch.

  • 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.

  • 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.

  • Appweb 3: Embedded Webserver with JavaScript Framework

    The embedded webserver Appweb is available in version 3.0. The new release improves performance, introduces a server-side JavaScript framework and runs on more operating systems than ever before.

comments powered by Disqus
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.

Learn More

News