zotero/storage/9NU6XPJG/.zotero-ft-cache

2395 lines
206 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Linux From Scratch
Version 12.1 Published March 1st, 2024
Created by Gerard Beekmans Managing Editor: Bruce Dubbs
Linux From Scratch: Version 12.1: Published March 1st, 2024
by Created by Gerard Beekmans and Managing Editor: Bruce Dubbs Copyright © 1999-2024 Gerard Beekmans
Copyright © 1999-2024, Gerard Beekmans All rights reserved. This book is licensed under a Creative Commons License. Computer instructions may be extracted from the book under the MIT License. Linux® is a registered trademark of Linus Torvalds.
Linux From Scratch - Version 12.1
Table of Contents
Preface ......................................................................................................................................................................... viii i. Foreword ............................................................................................................................................................ viii ii. Audience ........................................................................................................................................................... viii iii. LFS Target Architectures .................................................................................................................................. ix iv. Prerequisites ........................................................................................................................................................ x v. LFS and Standards .............................................................................................................................................. x vi. Rationale for Packages in the Book ................................................................................................................. xi vii. Typography .................................................................................................................................................... xvii viii. Structure ...................................................................................................................................................... xviii ix. Errata and Security Advisories ....................................................................................................................... xix
I. Introduction ................................................................................................................................................................. 1 1. Introduction .......................................................................................................................................................... 2 1.1. How to Build an LFS System .................................................................................................................... 2 1.2. What's new since the last release ............................................................................................................... 2 1.3. Changelog ................................................................................................................................................... 4 1.4. Resources .................................................................................................................................................... 9 1.5. Help ........................................................................................................................................................... 10
II. Preparing for the Build ........................................................................................................................................... 12 2. Preparing the Host System ................................................................................................................................ 13 2.1. Introduction ............................................................................................................................................... 13 2.2. Host System Requirements ....................................................................................................................... 13 2.3. Building LFS in Stages ............................................................................................................................ 16 2.4. Creating a New Partition .......................................................................................................................... 16 2.5. Creating a File System on the Partition ................................................................................................... 18 2.6. Setting The $LFS Variable ....................................................................................................................... 19 2.7. Mounting the New Partition ..................................................................................................................... 20 3. Packages and Patches ........................................................................................................................................ 22 3.1. Introduction ............................................................................................................................................... 22 3.2. All Packages ............................................................................................................................................. 23 3.3. Needed Patches ......................................................................................................................................... 32 4. Final Preparations .............................................................................................................................................. 33 4.1. Introduction ............................................................................................................................................... 33 4.2. Creating a Limited Directory Layout in the LFS Filesystem .................................................................. 33 4.3. Adding the LFS User ............................................................................................................................... 33 4.4. Setting Up the Environment ..................................................................................................................... 34 4.5. About SBUs .............................................................................................................................................. 37 4.6. About the Test Suites ............................................................................................................................... 37
III. Building the LFS Cross Toolchain and Temporary Tools .................................................................................... 39 Important Preliminary Material ............................................................................................................................. 40 i. Introduction ................................................................................................................................................... 40 ii. Toolchain Technical Notes .......................................................................................................................... 40 iii. General Compilation Instructions .............................................................................................................. 45 5. Compiling a Cross-Toolchain ............................................................................................................................ 47 5.1. Introduction ............................................................................................................................................... 47 5.2. Binutils-2.42 - Pass 1 ............................................................................................................................... 48
iii
Linux From Scratch - Version 12.1
5.3. GCC-13.2.0 - Pass 1 ................................................................................................................................. 50 5.4. Linux-6.7.4 API Headers .......................................................................................................................... 53 5.5. Glibc-2.39 ................................................................................................................................................. 54 5.6. Libstdc++ from GCC-13.2.0 .................................................................................................................... 57 6. Cross Compiling Temporary Tools ................................................................................................................... 59 6.1. Introduction ............................................................................................................................................... 59 6.2. M4-1.4.19 .................................................................................................................................................. 60 6.3. Ncurses-6.4-20230520 .............................................................................................................................. 61 6.4. Bash-5.2.21 ............................................................................................................................................... 63 6.5. Coreutils-9.4 .............................................................................................................................................. 64 6.6. Diffutils-3.10 ............................................................................................................................................. 65 6.7. File-5.45 .................................................................................................................................................... 66 6.8. Findutils-4.9.0 ........................................................................................................................................... 67 6.9. Gawk-5.3.0 ................................................................................................................................................ 68 6.10. Grep-3.11 ................................................................................................................................................ 69 6.11. Gzip-1.13 ................................................................................................................................................. 70 6.12. Make-4.4.1 .............................................................................................................................................. 71 6.13. Patch-2.7.6 ............................................................................................................................................... 72 6.14. Sed-4.9 .................................................................................................................................................... 73 6.15. Tar-1.35 ................................................................................................................................................... 74 6.16. Xz-5.4.6 ................................................................................................................................................... 75 6.17. Binutils-2.42 - Pass 2 ............................................................................................................................. 76 6.18. GCC-13.2.0 - Pass 2 ............................................................................................................................... 77 7. Entering Chroot and Building Additional Temporary Tools ............................................................................ 79 7.1. Introduction ............................................................................................................................................... 79 7.2. Changing Ownership ................................................................................................................................ 79 7.3. Preparing Virtual Kernel File Systems .................................................................................................... 79 7.4. Entering the Chroot Environment ............................................................................................................ 80 7.5. Creating Directories .................................................................................................................................. 81 7.6. Creating Essential Files and Symlinks ..................................................................................................... 82 7.7. Gettext-0.22.4 ............................................................................................................................................ 85 7.8. Bison-3.8.2 ................................................................................................................................................ 86 7.9. Perl-5.38.2 ................................................................................................................................................. 87 7.10. Python-3.12.2 .......................................................................................................................................... 88 7.11. Texinfo-7.1 .............................................................................................................................................. 89 7.12. Util-linux-2.39.3 ...................................................................................................................................... 90 7.13. Cleaning up and Saving the Temporary System .................................................................................... 91 IV. Building the LFS System ...................................................................................................................................... 93 8. Installing Basic System Software ...................................................................................................................... 94 8.1. Introduction ............................................................................................................................................... 94 8.2. Package Management ............................................................................................................................... 95 8.3. Man-pages-6.06 ......................................................................................................................................... 99 8.4. Iana-Etc-20240125 .................................................................................................................................. 100 8.5. Glibc-2.39 ............................................................................................................................................... 101 8.6. Zlib-1.3.1 ................................................................................................................................................. 109 8.7. Bzip2-1.0.8 .............................................................................................................................................. 110 8.8. Xz-5.4.6 ................................................................................................................................................... 112
iv
Linux From Scratch - Version 12.1
8.9. Zstd-1.5.5 ................................................................................................................................................ 114 8.10. File-5.45 ................................................................................................................................................ 115 8.11. Readline-8.2 .......................................................................................................................................... 116 8.12. M4-1.4.19 .............................................................................................................................................. 118 8.13. Bc-6.7.5 ................................................................................................................................................. 119 8.14. Flex-2.6.4 .............................................................................................................................................. 120 8.15. Tcl-8.6.13 .............................................................................................................................................. 121 8.16. Expect-5.45.4 ........................................................................................................................................ 123 8.17. DejaGNU-1.6.3 ..................................................................................................................................... 125 8.18. Pkgconf-2.1.1 ........................................................................................................................................ 126 8.19. Binutils-2.42 .......................................................................................................................................... 127 8.20. GMP-6.3.0 ............................................................................................................................................. 130 8.21. MPFR-4.2.1 ........................................................................................................................................... 132 8.22. MPC-1.3.1 ............................................................................................................................................. 133 8.23. Attr-2.5.2 ............................................................................................................................................... 134 8.24. Acl-2.3.2 ................................................................................................................................................ 135 8.25. Libcap-2.69 ........................................................................................................................................... 136 8.26. Libxcrypt-4.4.36 .................................................................................................................................... 137 8.27. Shadow-4.14.5 ....................................................................................................................................... 139 8.28. GCC-13.2.0 ........................................................................................................................................... 143 8.29. Ncurses-6.4-20230520 .......................................................................................................................... 148 8.30. Sed-4.9 .................................................................................................................................................. 151 8.31. Psmisc-23.6 ........................................................................................................................................... 152 8.32. Gettext-0.22.4 ........................................................................................................................................ 153 8.33. Bison-3.8.2 ............................................................................................................................................ 155 8.34. Grep-3.11 .............................................................................................................................................. 156 8.35. Bash-5.2.21 ........................................................................................................................................... 157 8.36. Libtool-2.4.7 .......................................................................................................................................... 159 8.37. GDBM-1.23 .......................................................................................................................................... 160 8.38. Gperf-3.1 ............................................................................................................................................... 161 8.39. Expat-2.6.0 ............................................................................................................................................ 162 8.40. Inetutils-2.5 ........................................................................................................................................... 163 8.41. Less-643 ................................................................................................................................................ 165 8.42. Perl-5.38.2 ............................................................................................................................................. 166 8.43. XML::Parser-2.47 ................................................................................................................................. 169 8.44. Intltool-0.51.0 ........................................................................................................................................ 170 8.45. Autoconf-2.72 ....................................................................................................................................... 171 8.46. Automake-1.16.5 ................................................................................................................................... 172 8.47. OpenSSL-3.2.1 ...................................................................................................................................... 173 8.48. Kmod-31 ............................................................................................................................................... 175 8.49. Libelf from Elfutils-0.190 .................................................................................................................... 177 8.50. Libffi-3.4.4 ............................................................................................................................................ 178 8.51. Python-3.12.2 ........................................................................................................................................ 179 8.52. Flit-Core-3.9.0 ....................................................................................................................................... 181 8.53. Wheel-0.42.0 ......................................................................................................................................... 182 8.54. Setuptools-69.1.0 ................................................................................................................................... 183 8.55. Ninja-1.11.1 ........................................................................................................................................... 184
v
Linux From Scratch - Version 12.1
8.56. Meson-1.3.2 ........................................................................................................................................... 185 8.57. Coreutils-9.4 .......................................................................................................................................... 186 8.58. Check-0.15.2 ......................................................................................................................................... 191 8.59. Diffutils-3.10 ......................................................................................................................................... 192 8.60. Gawk-5.3.0 ............................................................................................................................................ 193 8.61. Findutils-4.9.0 ....................................................................................................................................... 194 8.62. Groff-1.23.0 ........................................................................................................................................... 195 8.63. GRUB-2.12 ........................................................................................................................................... 198 8.64. Gzip-1.13 ............................................................................................................................................... 200 8.65. IPRoute2-6.7.0 ...................................................................................................................................... 201 8.66. Kbd-2.6.4 ............................................................................................................................................... 203 8.67. Libpipeline-1.5.7 ................................................................................................................................... 205 8.68. Make-4.4.1 ............................................................................................................................................ 206 8.69. Patch-2.7.6 ............................................................................................................................................. 207 8.70. Tar-1.35 ................................................................................................................................................. 208 8.71. Texinfo-7.1 ............................................................................................................................................ 209 8.72. Vim-9.1.0041 ........................................................................................................................................ 211 8.73. MarkupSafe-2.1.5 .................................................................................................................................. 214 8.74. Jinja2-3.1.3 ............................................................................................................................................ 215 8.75. Udev from Systemd-255 ....................................................................................................................... 216 8.76. Man-DB-2.12.0 ..................................................................................................................................... 219 8.77. Procps-ng-4.0.4 ..................................................................................................................................... 222 8.78. Util-linux-2.39.3 .................................................................................................................................... 224 8.79. E2fsprogs-1.47.0 ................................................................................................................................... 229 8.80. Sysklogd-1.5.1 ....................................................................................................................................... 232 8.81. Sysvinit-3.08 ......................................................................................................................................... 233 8.82. About Debugging Symbols .................................................................................................................. 234 8.83. Stripping ................................................................................................................................................ 234 8.84. Cleaning Up .......................................................................................................................................... 236 9. System Configuration ...................................................................................................................................... 237 9.1. Introduction ............................................................................................................................................. 237 9.2. LFS-Bootscripts-20230728 ..................................................................................................................... 238 9.3. Overview of Device and Module Handling ........................................................................................... 240 9.4. Managing Devices .................................................................................................................................. 243 9.5. General Network Configuration ............................................................................................................. 246 9.6. System V Bootscript Usage and Configuration ..................................................................................... 248 9.7. Configuring the System Locale .............................................................................................................. 256 9.8. Creating the /etc/inputrc File .................................................................................................................. 258 9.9. Creating the /etc/shells File .................................................................................................................... 259 10. Making the LFS System Bootable ................................................................................................................ 261 10.1. Introduction ........................................................................................................................................... 261 10.2. Creating the /etc/fstab File .................................................................................................................... 261 10.3. Linux-6.7.4 ............................................................................................................................................ 263 10.4. Using GRUB to Set Up the Boot Process ........................................................................................... 269 11. The End .......................................................................................................................................................... 272 11.1. The End ................................................................................................................................................. 272 11.2. Get Counted .......................................................................................................................................... 272
vi
Linux From Scratch - Version 12.1
11.3. Rebooting the System ........................................................................................................................... 272 11.4. Additional Resources ............................................................................................................................ 273 11.5. Getting Started After LFS .................................................................................................................... 274 V. Appendices ............................................................................................................................................................ 277 A. Acronyms and Terms ..................................................................................................................................... 278 B. Acknowledgments ........................................................................................................................................... 281 C. Dependencies ................................................................................................................................................... 284 D. Boot and sysconfig scripts version-20230728 ............................................................................................... 298 D.1. /etc/rc.d/init.d/rc ...................................................................................................................................... 298 D.2. /lib/lsb/init-functions .............................................................................................................................. 301 D.3. /etc/rc.d/init.d/mountvirtfs ...................................................................................................................... 314 D.4. /etc/rc.d/init.d/modules ........................................................................................................................... 316 D.5. /etc/rc.d/init.d/udev ................................................................................................................................. 317 D.6. /etc/rc.d/init.d/swap ................................................................................................................................ 319 D.7. /etc/rc.d/init.d/setclock ............................................................................................................................ 320 D.8. /etc/rc.d/init.d/checkfs ............................................................................................................................ 321 D.9. /etc/rc.d/init.d/mountfs ............................................................................................................................ 323 D.10. /etc/rc.d/init.d/udev_retry ..................................................................................................................... 325 D.11. /etc/rc.d/init.d/cleanfs ........................................................................................................................... 326 D.12. /etc/rc.d/init.d/console .......................................................................................................................... 328 D.13. /etc/rc.d/init.d/localnet .......................................................................................................................... 330 D.14. /etc/rc.d/init.d/sysctl .............................................................................................................................. 331 D.15. /etc/rc.d/init.d/sysklogd ........................................................................................................................ 332 D.16. /etc/rc.d/init.d/network .......................................................................................................................... 333 D.17. /etc/rc.d/init.d/sendsignals .................................................................................................................... 335 D.18. /etc/rc.d/init.d/reboot ............................................................................................................................ 336 D.19. /etc/rc.d/init.d/halt ................................................................................................................................. 337 D.20. /etc/rc.d/init.d/template ......................................................................................................................... 337 D.21. /etc/sysconfig/modules ......................................................................................................................... 338 D.22. /etc/sysconfig/createfiles ...................................................................................................................... 339 D.23. /etc/sysconfig/udev-retry ...................................................................................................................... 339 D.24. /sbin/ifup ............................................................................................................................................... 340 D.25. /sbin/ifdown .......................................................................................................................................... 342 D.26. /lib/services/ipv4-static ......................................................................................................................... 344 D.27. /lib/services/ipv4-static-route ............................................................................................................... 345 E. Udev configuration rules ................................................................................................................................. 348 E.1. 55-lfs.rules .............................................................................................................................................. 348 F. LFS Licenses ................................................................................................................................................... 349 F.1. Creative Commons License ................................................................................................................... 349 F.2. The MIT License .................................................................................................................................... 353 Index ........................................................................................................................................................................... 354
vii
Linux From Scratch - Version 12.1
Preface
Foreword
My journey to learn and better understand Linux began back in 1998. I had just installed my first Linux distribution and had quickly become intrigued with the whole concept and philosophy behind Linux.
There are always many ways to accomplish a single task. The same can be said about Linux distributions. A great many have existed over the years. Some still exist, some have morphed into something else, yet others have been relegated to our memories. They all do things differently to suit the needs of their target audience. Because so many different ways to accomplish the same end goal exist, I began to realize I no longer had to be limited by any one implementation. Prior to discovering Linux, we simply put up with issues in other Operating Systems as you had no choice. It was what it was, whether you liked it or not. With Linux, the concept of choice began to emerge. If you didn't like something, you were free, even encouraged, to change it.
I tried a number of distributions and could not decide on any one. They were great systems in their own right. It wasn't a matter of right and wrong anymore. It had become a matter of personal taste. With all that choice available, it became apparent that there would not be a single system that would be perfect for me. So I set out to create my own Linux system that would fully conform to my personal preferences.
To truly make it my own system, I resolved to compile everything from source code instead of using pre-compiled binary packages. This “perfect” Linux system would have the strengths of various systems without their perceived weaknesses. At first, the idea was rather daunting. I remained committed to the idea that such a system could be built.
After sorting through issues such as circular dependencies and compile-time errors, I finally built a custom-built Linux system. It was fully operational and perfectly usable like any of the other Linux systems out there at the time. But it was my own creation. It was very satisfying to have put together such a system myself. The only thing better would have been to create each piece of software myself. This was the next best thing.
As I shared my goals and experiences with other members of the Linux community, it became apparent that there was a sustained interest in these ideas. It quickly became plain that such custom-built Linux systems serve not only to meet user specific requirements, but also serve as an ideal learning opportunity for programmers and system administrators to enhance their (existing) Linux skills. Out of this broadened interest, the Linux From Scratch Project was born.
This Linux From Scratch book is the central core around that project. It provides the background and instructions necessary for you to design and build your own system. While this book provides a template that will result in a correctly working system, you are free to alter the instructions to suit yourself, which is, in part, an important part of this project. You remain in control; we just lend a helping hand to get you started on your own journey.
I sincerely hope you will have a great time working on your own Linux From Scratch system and enjoy the numerous benefits of having a system that is truly your own.
-Gerard Beekmans gerard@linuxfromscratch.org
Audience
There are many reasons why you would want to read this book. One of the questions many people raise is, “why go through all the hassle of manually building a Linux system from scratch when you can just download and install an existing one?”
viii
Linux From Scratch - Version 12.1
One important reason for this project's existence is to help you learn how a Linux system works from the inside out. Building an LFS system helps demonstrate what makes Linux tick, and how things work together and depend on each other. One of the best things this learning experience can provide is the ability to customize a Linux system to suit your own unique needs.
Another key benefit of LFS is that it gives you control of the system without relying on someone else's Linux implementation. With LFS, you are in the driver's seat. You dictate every aspect of your system.
LFS allows you to create very compact Linux systems. With other distributions you are often forced to install a great many programs you neither use nor understand. These programs waste resources. You may argue that with today's hard drives and CPUs, wasted resources are no longer a consideration. Sometimes, however, you are still constrained by the system's size, if nothing else. Think about bootable CDs, USB sticks, and embedded systems. Those are areas where LFS can be beneficial.
Another advantage of a custom built Linux system is security. By compiling the entire system from source code, you are empowered to audit everything and apply all the security patches you want. You don't have to wait for somebody else to compile binary packages that fix a security hole. Unless you examine the patch and implement it yourself, you have no guarantee that the new binary package was built correctly and adequately fixes the problem.
The goal of Linux From Scratch is to build a complete and usable foundation-level system. If you do not wish to build your own Linux system from scratch, you may nevertheless benefit from the information in this book.
There are too many good reasons to build your own LFS system to list them all here. In the end, education is by far the most important reason. As you continue your LFS experience, you will discover the power that information and knowledge can bring.
LFS Target Architectures
The primary target architectures of LFS are the AMD/Intel x86 (32-bit) and x86_64 (64-bit) CPUs. On the other hand, the instructions in this book are also known to work, with some modifications, with the Power PC and ARM CPUs. To build a system that utilizes one of these alternative CPUs, the main prerequisite, in addition to those on the next page, is an existing Linux system such as an earlier LFS installation, Ubuntu, Red Hat/Fedora, SuSE, or some other distribution that targets that architecture. (Note that a 32-bit distribution can be installed and used as a host system on a 64-bit AMD/Intel computer.)
The gain from building on a 64-bit system, as compared to a 32-bit system, is minimal. For example, in a test build of LFS-9.1 on a Core i7-4790 CPU based system, using 4 cores, the following statistics were measured:
Architecture Build Time
Build Size
32-bit
239.9 minutes 3.6 GB
64-bit
233.2 minutes 4.4 GB
As you can see, on the same hardware, the 64-bit build is only 3% faster (and 22% larger) than the 32-bit build. If you plan to use LFS as a LAMP server, or a firewall, a 32-bit CPU may be good enough. On the other hand, several packages in BLFS now need more than 4 GB of RAM to be built and/or to run; if you plan to use LFS as a desktop, the LFS authors recommend building a 64-bit system.
The default 64-bit build that results from LFS is a “pure” 64-bit system. That is, it supports 64-bit executables only. Building a “multi-lib” system requires compiling many applications twice, once for a 32-bit system and once for a 64bit system. This is not directly supported in LFS because it would interfere with the educational objective of providing the minimal instructions needed for a basic Linux system. Some of the LFS/BLFS editors maintain a multilib fork of LFS, accessible at https://www.linuxfromscratch.org/~thomas/multilib/index.html. But that's an advanced topic.
ix
Linux From Scratch - Version 12.1
Prerequisites
Building an LFS system is not a simple task. It requires a certain level of existing knowledge of Unix system administration in order to resolve problems and correctly execute the commands listed. In particular, as an absolute minimum, you should already know how to use the command line (shell) to copy or move files and directories, list directory and file contents, and change the current directory. It is also expected that you know how to use and install Linux software.
Because the LFS book assumes at least this basic level of skill, the various LFS support forums are unlikely to provide you with much assistance in these areas. You will find that your questions regarding such basic knowledge will likely go unanswered (or you will simply be referred to the LFS essential pre-reading list).
Before building an LFS system, we urge you to read these articles:
• Software-Building-HOWTO https://tldp.org/HOWTO/Software-Building-HOWTO.html
This is a comprehensive guide to building and installing “generic” Unix software packages under Linux. Although it was written some time ago, it still provides a good summary of the basic techniques used to build and install software. • Beginner's Guide to Installing from Source https://moi.vonos.net/linux/beginners-installing-from-source/
This guide provides a good summary of the basic skills and techniques needed to build software from source code.
LFS and Standards
The structure of LFS follows Linux standards as closely as possible. The primary standards are:
• POSIX.1-2008. • Filesystem Hierarchy Standard (FHS) Version 3.0 • Linux Standard Base (LSB) Version 5.0 (2015)
The LSB has four separate specifications: Core, Desktop, Runtime Languages, and Imaging. Some parts of Core and Desktop specifications are architecture specific. There are also two trial specifications: Gtk3 and Graphics. LFS attempts to conform to the LSB specifications for the IA32 (32-bit x86) or AMD64 (x86_64) architectures discussed in the previous section.
Note
Many people do not agree with these requirements. The main purpose of the LSB is to ensure that proprietary software can be installed and run on a compliant system. Since LFS is source based, the user has complete control over what packages are desired; you may choose not to install some packages that are specified by the LSB.
While it is possible to create a complete system that will pass the LSB certification tests “from scratch,” this can't be done without many additional packages that are beyond the scope of the LFS book. Installation instructions for these additional packages can be found in BLFS.
Packages supplied by LFS needed to satisfy the LSB Requirements
LSB Core:
Bash, Bc, Binutils, Coreutils, Diffutils, File, Findutils, Gawk, Grep, Gzip, M4, Man-DB, Ncurses, Procps, Psmisc, Sed, Shadow, Tar, Util-linux, Zlib
x
Linux From Scratch - Version 12.1
LSB Desktop: LSB Runtime Languages: LSB Imaging: LSB Gtk3 and LSB Graphics (Trial Use):
None Perl, Python None None
Packages supplied by BLFS needed to satisfy the LSB Requirements
LSB Core: LSB Desktop:
LSB Runtime Languages: LSB Imaging: LSB Gtk3 and LSB Graphics (Trial Use):
At, Batch (a part of At), Cpio, Ed, Fcrontab, LSB-Tools, NSPR, NSS, PAM, Pax, Sendmail (or Postfix or Exim), time
Alsa, ATK, Cairo, Desktop-file-utils, Freetype, Fontconfig, Gdk-pixbuf, Glib2, GTK+2, Icon-naming-utils, Libjpeg-turbo, Libpng, Libtiff, Libxml2, MesaLib, Pango, Xdg-utils, Xorg
Libxml2, Libxslt
CUPS, Cups-filters, Ghostscript, SANE
GTK+3
Packages not supplied by LFS or BLFS needed to satisfy the LSB Requirements
LSB Core:
None
LSB Desktop: LSB Runtime Languages: LSB Imaging:
Qt4 (but Qt5 is provided) None None
LSB Gtk3 and LSB Graphics (Trial Use):
None
Rationale for Packages in the Book
The goal of LFS is to build a complete and usable foundation-level system—including all the packages needed to replicate itself—and providing a relatively minimal base from which to customize a more complete system based on the user's choices. This does not mean that LFS is the smallest system possible. Several important packages are included that are not, strictly speaking, required. The list below documents the reasons each package in the book has been included.
• Acl
This package contains utilities to administer Access Control Lists, which are used to define fine-grained discretionary access rights for files and directories. • Attr
This package contains programs for managing extended attributes on file system objects. • Autoconf
This package supplies programs for producing shell scripts that can automatically configure source code from a developer's template. It is often needed to rebuild a package after the build procedure has been updated. • Automake
This package contains programs for generating Make files from a template. It is often needed to rebuild a package after the build procedure has been updated. • Bash
xi
Linux From Scratch - Version 12.1
This package satisfies an LSB core requirement to provide a Bourne Shell interface to the system. It was chosen over other shell packages because of its common usage and extensive capabilities. • Bc
This package provides an arbitrary precision numeric processing language. It satisfies a requirement for building the Linux kernel. • Binutils
This package supplies a linker, an assembler, and other tools for handling object files. The programs in this package are needed to compile most of the packages in an LFS system. • Bison
This package contains the GNU version of yacc (Yet Another Compiler Compiler) needed to build several of the LFS programs. • Bzip2
This package contains programs for compressing and decompressing files. It is required to decompress many LFS packages. • Check
This package provides a test harness for other programs. • Coreutils
This package contains a number of essential programs for viewing and manipulating files and directories. These programs are needed for command line file management, and are necessary for the installation procedures of every package in LFS. • DejaGNU
This package supplies a framework for testing other programs. • Diffutils
This package contains programs that show the differences between files or directories. These programs can be used to create patches, and are also used in many packages' build procedures. • E2fsprogs
This package supplies utilities for handling the ext2, ext3 and ext4 file systems. These are the most common and thoroughly tested file systems that Linux supports. • Expat
This package yields a relatively small XML parsing library. It is required by the XML::Parser Perl module. • Expect
This package contains a program for carrying out scripted dialogues with other interactive programs. It is commonly used for testing other packages. • File
This package contains a utility for determining the type of a given file or files. A few packages need it in their build scripts. • Findutils
xii
Linux From Scratch - Version 12.1
This package provides programs to find files in a file system. It is used in many packages' build scripts. • Flex
This package contains a utility for generating programs that recognize patterns in text. It is the GNU version of the lex (lexical analyzer) program. It is required to build several LFS packages. • Gawk This package supplies programs for manipulating text files. It is the GNU version of awk (Aho-WeinbergKernighan). It is used in many other packages' build scripts. • GCC This is the Gnu Compiler Collection. It contains the C and C++ compilers as well as several others not built by LFS. • GDBM This package contains the GNU Database Manager library. It is used by one other LFS package, Man-DB. • Gettext This package provides utilities and libraries for the internationalization and localization of many packages. • Glibc This package contains the main C library. Linux programs will not run without it. • GMP This package supplies math libraries that provide useful functions for arbitrary precision arithmetic. It is needed to build GCC. • Gperf This package produces a program that generates a perfect hash function from a set of keys. It is required by Udev . • Grep This package contains programs for searching through files. These programs are used by most packages' build scripts. • Groff This package contributes programs for processing and formatting text. One important function of these programs is to format man pages. • GRUB This is the Grand Unified Boot Loader. It is the most flexible of several boot loaders available. • Gzip This package contains programs for compressing and decompressing files. It is needed to decompress many packages in LFS. • Iana-etc This package provides data for network services and protocols. It is needed to enable proper networking capabilities. • Inetutils
xiii
Linux From Scratch - Version 12.1
This package supplies programs for basic network administration. • Intltool
This package contributes tools for extracting translatable strings from source files. • IProute2
This package contains programs for basic and advanced IPv4 and IPv6 networking. It was chosen over the other common network tools package (net-tools) for its IPv6 capabilities. • Kbd This package produces key-table files, keyboard utilities for non-US keyboards, and a number of console fonts. • Kmod This package supplies programs needed to administer Linux kernel modules. • Less This package contains a very nice text file viewer that allows scrolling up or down when viewing a file. Many packages use it for paging the output. • Libcap This package implements the userspace interfaces to the POSIX 1003.1e capabilities available in Linux kernels. • Libelf The elfutils project provides libraries and tools for ELF files and DWARF data. Most utilities in this package are available in other packages, but the library is needed to build the Linux kernel using the default (and most efficient) configuration. • Libffi This package implements a portable, high level programming interface to various calling conventions. Some programs may not know at the time of compilation what arguments are to be passed to a function. For instance, an interpreter may be told at run-time about the number and types of arguments used to call a given function. Libffi can be used in such programs to provide a bridge from the interpreter program to compiled code. • Libpipeline The Libpipeline package supplies a library for manipulating pipelines of subprocesses in a flexible and convenient way. It is required by the Man-DB package. • Libtool This package contains the GNU generic library support script. It wraps the complexity of using shared libraries into a consistent, portable interface. It is needed by the test suites in other LFS packages. • Libxcrypt This package provides the libcrypt library needed by various packages (notably, Shadow) for hashing passwords. It replaces the obsolete libcrypt implementation in Glibc. • Linux Kernel This package is the Operating System. It is the Linux in the GNU/Linux environment. • M4 This package provides a general text macro processor useful as a build tool for other programs.
xiv
Linux From Scratch - Version 12.1
• Make This package contains a program for directing the building of packages. It is required by almost every package in LFS.
• Man-DB This package contains programs for finding and viewing man pages. It was chosen instead of the man package because of its superior internationalization capabilities. It supplies the man program.
• Man-pages This package provides the actual contents of the basic Linux man pages.
• Meson This package provides a software tool for automating the building of software. The main goal of Meson is to minimize the amount of time that software developers need to spend configuring a build system. It's required to build Systemd, as well as many BLFS packages.
• MPC This package supplies arithmetic functions for complex numbers. It is required by GCC.
• MPFR This package contains functions for multiple precision arithmetic. It is required by GCC.
• Ninja This package furnishes a small build system with a focus on speed. It is designed to have its input files generated by a higher-level build system, and to run builds as fast as possible. This package is required by Meson.
• Ncurses This package contains libraries for terminal-independent handling of character screens. It is often used to provide cursor control for a menuing system. It is needed by a number of the packages in LFS.
• Openssl This package provides management tools and libraries relating to cryptography. These supply cryptographic functions to other packages, including the Linux kernel.
• Patch This package contains a program for modifying or creating files by applying a patch file typically created by the diff program. It is needed by the build procedure for several LFS packages.
• Perl This package is an interpreter for the runtime language PERL. It is needed for the installation and test suites of several LFS packages.
• Pkgconf This package contains a program which helps to configure compiler and linker flags for development libraries. The program can be used as a drop-in replacement of pkg-config, which is needed by the building system of many packages. It's maintained more actively and slightly faster than the original Pkg-config package.
• Procps-NG This package contains programs for monitoring processes. These programs are useful for system administration, and are also used by the LFS Bootscripts.
xv
Linux From Scratch - Version 12.1
• Psmisc This package produces programs for displaying information about running processes. These programs are useful for system administration.
• Python 3 This package provides an interpreted language that has a design philosophy emphasizing code readability.
• Readline This package is a set of libraries that offer command-line editing and history capabilities. It is used by Bash.
• Sed This package allows editing of text without opening it in a text editor. It is also needed by many LFS packages' configure scripts.
• Shadow This package contains programs for handling passwords securely.
• Sysklogd This package supplies programs for logging system messages, such as those emitted by the kernel or daemon processes when unusual events occur.
• Sysvinit This package provides the init program, the parent of all the other processes on a running Linux system.
• Udev This package is a device manager. It dynamically controls the ownership, permissions, names, and symbolic links of device nodes in the /dev directory when devices are added to or removed from the system.
• Tar This package provides archiving and extraction capabilities of virtually all the packages used in LFS.
• Tcl This package contains the Tool Command Language used in many test suites.
• Texinfo This package supplies programs for reading, writing, and converting info pages. It is used in the installation procedures of many LFS packages.
• Util-linux This package contains miscellaneous utility programs. Among them are utilities for handling file systems, consoles, partitions, and messages.
• Vim This package provides an editor. It was chosen because of its compatibility with the classic vi editor and its huge number of powerful capabilities. An editor is a very personal choice for many users. Any other editor can be substituted, if you wish.
• Wheel This package supplies a Python module that is the reference implementation of the Python wheel packaging standard.
xvi
Linux From Scratch - Version 12.1
• XML::Parser This package is a Perl module that interfaces with Expat.
• XZ Utils This package contains programs for compressing and decompressing files. It provides the highest compression generally available and is useful for decompressing packages in XZ or LZMA format.
• Zlib This package contains compression and decompression routines used by some programs.
• Zstd This package supplies compression and decompression routines used by some programs. It provides high compression ratios and a very wide range of compression / speed trade-offs.
Typography
To make things easier to follow, there are a few typographical conventions used throughout this book. This section contains some examples of the typographical format found throughout Linux From Scratch.
./configure --prefix=/usr
This form of text is designed to be typed exactly as seen unless otherwise noted in the surrounding text. It is also used in the explanation sections to identify which of the commands is being referenced. In some cases, a logical line is extended to two or more physical lines with a backslash at the end of the line.
CC="gcc -B/usr/bin/" ../binutils-2.18/configure \ --prefix=/tools --disable-nls --disable-werror
Note that the backslash must be followed by an immediate return. Other whitespace characters like spaces or tab characters will create incorrect results.
install-info: unknown option '--dir-file=/mnt/lfs/usr/info/dir'
This form of text (fixed-width text) shows screen output, usually as the result of commands issued. This format is also used to show filenames, such as /etc/ld.so.conf.
Note
Please configure your browser to display fixed-width text with a good monospace" font-size="9ptd font, with which you can distinguish the glyphs of Il1 or O0 clearly.
Emphasis This form of text is used for several purposes in the book. Its main purpose is to emphasize important points or items. https://www.linuxfromscratch.org/ This format is used for hyperlinks both within the LFS community and to external pages. It includes HOWTOs, download locations, and websites.
cat > $LFS/etc/group << "EOF" root:x:0: bin:x:1: ...... EOF
xvii
Linux From Scratch - Version 12.1
This format is used when creating configuration files. The first command tells the system to create the file $LFS/etc/ group from whatever is typed on the following lines until the sequence End Of File (EOF) is encountered. Therefore, this entire section is generally typed as seen.
<REPLACED TEXT>
This format is used to encapsulate text that is not to be typed as seen or for copy-and-paste operations.
[OPTIONAL TEXT]
This format is used to encapsulate text that is optional. passwd(5) This format is used to refer to a specific manual (man) page. The number inside parentheses indicates a specific section inside the manuals. For example, passwd has two man pages. Per LFS installation instructions, those two man pages will be located at /usr/share/man/man1/passwd.1 and /usr/share/man/man5/passwd.5. When the book uses passwd(5) it is specifically referring to /usr/share/man/man5/passwd.5. man passwd will print the first man page it finds that matches “passwd,” which will be /usr/share/man/man1/passwd.1. For this example, you will need to run man 5 passwd in order to read the page being specified. Note that most man pages do not have duplicate page names in different sections. Therefore, man <program name> is generally sufficient. In the LFS book these references to man pages are also hyperlinks, so clicking on such a reference will open the man page rendered in HTML from Arch Linux manual pages.
Structure
This book is divided into the following parts.
Part I - Introduction
Part I explains a few important notes on how to proceed with the LFS installation. This section also provides metainformation about the book.
Part II - Preparing for the Build
Part II describes how to prepare for the building process—making a partition, downloading the packages, and compiling temporary tools.
Part III - Building the LFS Cross Toolchain and Temporary Tools
Part III provides instructions for building the tools needed for constructing the final LFS system.
Part IV - Building the LFS System
Part IV guides the reader through the building of the LFS system—compiling and installing all the packages one by one, setting up the boot scripts, and installing the kernel. The resulting Linux system is the foundation on which other software can be built to expand the system as desired. At the end of this book, there is an easy to use reference listing all of the programs, libraries, and important files that have been installed.
Part V - Appendices
Part V provides information about the book itself including acronyms and terms, acknowledgments, package dependencies, a listing of LFS boot scripts, licenses for the distribution of the book, and a comprehensive index of packages, programs, libraries, and scripts.
xviii
Linux From Scratch - Version 12.1
Errata and Security Advisories
The software used to create an LFS system is constantly being updated and enhanced. Security warnings and bug fixes may become available after the LFS book has been released. To check whether the package versions or instructions in this release of LFS need any modifications—to repair security vulnerabilities or to fix other bugs—please visit https:// www.linuxfromscratch.org/lfs/errata/12.1/ before proceeding with your build. You should note any changes shown and apply them to the relevant sections of the book as you build the LFS system. In addition, the Linux From Scratch editors maintain a list of security vulnerabilities discovered after a book has been released. To read the list, please visit https://www.linuxfromscratch.org/lfs/advisories/ before proceeding with your build. You should apply the changes suggested by the advisories to the relevant sections of the book as you build the LFS system. And, if you will use the LFS system as a real desktop or server system, you should continue to consult the advisories and fix any security vulnerabilities, even when the LFS system has been completely constructed.
xix
Linux From Scratch - Version 12.1
Part I. Introduction
Linux From Scratch - Version 12.1
Chapter 1. Introduction
1.1. How to Build an LFS System
The LFS system will be built by using an already installed Linux distribution (such as Debian, OpenMandriva, Fedora, or openSUSE). This existing Linux system (the host) will be used as a starting point to provide necessary programs, including a compiler, linker, and shell, to build the new system. Select the “development” option during the distribution installation to include these tools.
Note
There are many ways to install a Linux distribution and the defaults are usually not optimal for building an LFS system. For suggestions on setting up a commercial distribution see: https://www.linuxfromscratch.org/ hints/downloads/files/partitioning-for-lfs.txt.
As an alternative to installing a separate distribution on your machine, you may wish to use a LiveCD from a commercial distribution.
Chapter 2 of this book describes how to create a new Linux native partition and file system, where the new LFS system will be compiled and installed. Chapter 3 explains which packages and patches must be downloaded to build an LFS system, and how to store them on the new file system. Chapter 4 discusses the setup of an appropriate working environment. Please read Chapter 4 carefully as it explains several important issues you should be aware of before you begin to work your way through Chapter 5 and beyond.
Chapter 5 explains the installation of the initial tool chain, (binutils, gcc, and glibc) using cross-compilation techniques to isolate the new tools from the host system.
Chapter 6 shows you how to cross-compile basic utilities using the just built cross-toolchain.
Chapter 7 then enters a "chroot" environment, where we use the new tools to build all the rest of the tools needed to create the LFS system.
This effort to isolate the new system from the host distribution may seem excessive. A full technical explanation as to why this is done is provided in Toolchain Technical Notes.
In Chapter 8 the full-blown LFS system is built. Another advantage provided by the chroot environment is that it allows you to continue using the host system while LFS is being built. While waiting for package compilations to complete, you can continue using your computer as usual.
To finish the installation, the basic system configuration is set up in Chapter 9, and the kernel and boot loader are created in Chapter 10. Chapter 11 contains information on continuing the LFS experience beyond this book. After the steps in this chapter have been implemented, the computer is ready to boot into the new LFS system.
This is the process in a nutshell. Detailed information on each step is presented in the following chapters. Items that seem complicated now will be clarified, and everything will fall into place as you commence your LFS adventure.
1.2. What's new since the last release
Here is a list of the packages updated since the previous release of LFS.
Upgraded to:
2
• Acl-2.3.2 • Attr-2.5.2 • Autoconf-2.72 • Bash-5.2.21 • Bc-6.7.5 • Binutils-2.42 • Coreutils-9.4 • Expat-2.6.0 • Gawk-5.3.0 • Gettext-0.22.4 • Glibc-2.39 • GRUB-2.12 • Gzip-1.13 • Iana-Etc-20240125 • Inetutils-2.5 • IPRoute2-6.7.0 • Jinja2-3.1.3 • Kbd-2.6.4 • Kmod-31 • Libelf from Elfutils-0.190 • Linux-6.7.4 • Man-DB-2.12.0 • Man-pages-6.06 • MarkupSafe-2.1.5 • Meson-1.3.2 • MPFR-4.2.1 • Ncurses-6.4-20230520 • OpenSSL-3.2.1 • Perl-5.38.2 • Pkgconf-2.1.1 • Procps-ng-4.0.4 • Python-3.12.2 • Setuptools-69.1.0
Linux From Scratch - Version 12.1 3
Linux From Scratch - Version 12.1
• Shadow-4.14.5 • SysVinit-3.08 • Texinfo-7.1 • Tzdata-2024a • Util-linux-2.39.3 • Vim-9.1.0041 • Wheel-0.42.0 • XML::Parser-2.47 • Xz-5.4.6 • Zlib-1.3.1
Added:
• • bash-5.2.21-upstream_fixes-1.patch • readline-8.2-upstream_fixes-3.patch • setuptools-69.1.0 • systemd-255-upstream_fixes-1.patch
Removed:
• • glibc-2.38-memalign_fix-1.patch • grub-2.06-upstream_fixes-1.patch • readline-8.2-upstream_fix-1.patch
1.3. Changelog
This is version 12.1 of the Linux From Scratch book, dated March 1st, 2024. If this book is more than six months old, a newer and better version is probably already available. To find out, please check one of the mirrors via https://www. linuxfromscratch.org/mirrors.html. Below is a list of changes made since the previous release of the book.
Changelog Entries:
• 2024-03-01 • [bdubbs] - LFS-12.1 released.
• 2024-02-14 • [bdubbs] - Update to meson-1.3.2. Fixes #5442.
• 2024-02-12
4
Linux From Scratch - Version 12.1
• [bdubbs] - Update to shadow-4.14.5. Fixes #5437. • [bdubbs] - Update to setuptools-69.1.0 (Python module). Fixes #5439. • [bdubbs] - Update to python-3.12.2. Fixes #5434. • [bdubbs] - Update to pkgconf-2.1.1. Fixes #5432. • [bdubbs] - Update to MarkupSafe-2.1.5 (Python module). Fixes #5431. • [bdubbs] - Update to man-pages-6.06. Fixes #5438. • [bdubbs] - Update to expat-2.6.0. Fixes #5435. • [bdubbs] - Update to linux-6.7.4. Fixes #5433. • 2024-02-02 • [xry111] - Update to tzdata-2024a. Fixes #5428. • [xry111] - Update to glibc-2.39 (security fix). Fixes #5426. • [xry111] - Update to linux-6.7.3. Fixes #5427. • 2024-02-01 • [bdubbs] - Update to openssl-3.2.1 (security fix). Fixes #5425. • [bdubbs] - Update to zlib-1.3.1. Fixes #5419. • [bdubbs] - Update to xz-5.4.6. Fixes #5423. • [bdubbs] - Update to linux-6.7.2. Fixes #5422. • [bdubbs] - Update to iana-etc-20240125. Addresses #5006. • [bdubbs] - Update to binutils-2.42. Fixes #5424. • [bdubbs] - Update to acl-2.3.2. Fixes #5421. • [bdubbs] - Update upstream fixes for readline-8.2. Fixes #5420. • [bdubbs] - Apply upstream fix for bash-5.2.21. Fixes #5420. • 2024-01-21 • [xry111] - Apply upstream fix for pkgconf-2.1.0 regression. Fixes #5414. • [xry111] - Update to jinja2-3.1.3 (security fix). Fixes #5411. • [xry111] - Update to bc-6.7.5. Fixes #5408. • [xry111] - Update to attr-2.5.2. Fixes #5412. • [xry111] - Update to ncurses-6.4-20230520 (security fix). Fixes #5416. • [xry111] - Update to markupsafe-2.1.4. Fixes #5418. • [xry111] - Update to linux-6.7.1. Fixes #5406. • [xry111] - Update to iproute2-6.7.0. Fixes #5410. • [xry111] - Update to vim-9.1.0041. Addresses #4500. • [xry111] - Update to iana-etc-20240117. Addresses #5006. • [xry111] - Update to shadow-4.14.3. Fixes #5413. • [xry111] - Fix CVE-2024-0684 for coreutils-9.4. Fixes #5417. • 2024-01-18
5
Linux From Scratch - Version 12.1
• [xry111] - Edit a ncurses header to always use the wide-character ABI compatible with libncursesw.so because we are faking the 8-bit libncurses.so with it. Fixes #5415.
• 2024-01-09 • [renodr] - Fix the definition of the C.UTF-8 locale. Fixes #5409.
• 2023-12-31 • [xry111] - Add --enable-default-hash-style=gnu configuring binutils. Fixes #5401. • [xry111] - Fix CVE-2023-7008 for systemd-255. Fixes #5405. • [xry111] - Update to iana-etc-20231205. Addresses #5006. • [xry111] - Update to tzdata-2023d. Fixes #5399. • [xry111] - Update to linux-6.6.8. Fixes #5397. • [xry111] - Update to meson-1.3.1. Fixes #5402. • [xry111] - Update to grub-2.12. Fixes #5396. • [xry111] - Update to inetutils-2.5. Fixes #5404. • [xry111] - Update to setuptools-69.0.3. Fixes #5400. • [xry111] - Update to xml-parser-2.47. Fixes #5403. • [xry111] - Update to vim-9.0.2189. Addresses #4500. • [xry111] - Update to autoconf-2.72. Fixes #5398.
• 2023-12-16 • [xry111] - Update to udev from systemd-255. Fixes #5390.
• 2023-12-14 • [bdubbs] - Update to util-linux v2.39.3. Fixes #5388. • [bdubbs] - Update to python3-3.12.1. Fixes #5392. • [bdubbs] - Update to linux-6.6.7. Fixes #5387. • [bdubbs] - Update to kbd-2.6.4. Fixes #5393. • [bdubbs] - Update to bc-6.7.4. Fixes #5389. • [bdubbs] - Reformat util-linux configure parameters. Fixes #5395.
• 2023-12-04 • [thomas] - Modify commands for install Python docs to avoid too restrictive permissions on the files and dirs.
• 2023-12-01 • [xry111] - Restore NIC naming based on physical system characteristics. Fixes #5386.
• 2023-11-30 • [bdubbs] - Update to vim-9.0.2136. Addresses #4500. • [bdubbs] - Update to iana-etc-20231117. Addresses #5006. • [bdubbs] - Update to bc-6.7.3. Fixes #5385. • [bdubbs] - Update to wheel-0.42.0 (Python Module). Fixes #5384. • [bdubbs] - Update to perl-5.38.2. Fixes #5383.
6
• [bdubbs] - Update to pkgconf-2.1.0. Fixes #5382. • [bdubbs] - Update to readline patches 002 through 007. Fixes #5381. • [bdubbs] - Update to openssl-3.2.0. Fixes #5380. • [bdubbs] - Update to setuptools-69.0.2. Fixes #5379. • [bdubbs] - Update to linux-6.6.3. Fixes #5378. • [bdubbs] - Update to meson-1.3.0. Fixes #5377. • [bdubbs] - Update to gettext-0.22.4. Fixes #5376. • 2023-11-13 • [xry111] - Update to elfutils-0.190. Fixes #5373. • [xry111] - Update to vim-9.0.2103. Addresses #4500. • [xry111] - Update to linux-6.6.1. Fixes #5369. • [xry111] - Update to xz-5.4.5. Fixes #5371. • [xry111] - Update to iana-etc-20231107. Addresses #5006. • [xry111] - Update to gawk-5.3.0. Fixes #5372. • [xry111] - Update to bash-5.2.21. Fixes #5375. • [xry111] - Update to iproute2-6.6.0. Fixes #5374. • 2023-11-01 • [bdubbs] - Update to iana-etc-20231019. Addresses #5006. • [bdubbs] - Update to wheel-0.41.3. Fixes #5370. • [bdubbs] - Update to shadow-4.14.2. Fixes #5368. • [bdubbs] - Update to openssl-3.1.4. Fixes #5367. • [bdubbs] - Update to texinfo-7.1. Fixes #5364. • [bdubbs] - Update to meson-1.2.3. Fixes #5366. • [bdubbs] - Update to bc-6.7.2. Fixes #5363. • [bdubbs] - Update to linux-6.5.9. Fixes #5365. • [bdubbs] - Update to Python-3.12.0. Fixes #5357. • [bdubbs] - Add setuptools-68.2.2. Fixes #5358. • 2023-10-15 • [bdubbs] - Update to linux-6.5.7. Fixes #5362. • [bdubbs] - Update to shadow-4.14.1. Fixes #5361. • [bdubbs] - Update to gettext-0.22.3. Fixes #5359. • 2023-10-03 • [xry111] - Update Glibc upstream fixes patch to fix CVE-2023-4911. • 2023-10-01 • [bdubbs] - Disable building nscd in glibc. Fixes #5349. • [bdubbs] - Update to iana-etc-20230929. Addresses #5006.
Linux From Scratch - Version 12.1
7
Linux From Scratch - Version 12.1
• [bdubbs] - Update to vim-9.0.1968. Addresses #4500. • [bdubbs] - Update to openssl-3.1.3. Fixes #5350. • [bdubbs] - Update to meson-1.2.2. Fixes #5356. • [bdubbs] - Update to man-db-2.12.0. Fixes #5354. • [bdubbs] - Update to linux-6.5.5. Fixes #5352. • [bdubbs] - Update to kmod-31. Fixes #5355. • [bdubbs] - Update to kbd-2.6.3. Fixes #5361. • [bdubbs] - Update to gettext-0.22.2. Fixes #5348. • [bdubbs] - Update to bc-6.7.0. Fixes #5353. • 2023-09-24 • [xry111] - Update Glibc upstream fixes patch to plug a memory leak introduced by the security fix. • 2023-09-17 • [xry111] - Update to linux-6.5.3. Fixes #5343. • [xry111] - Update to iana-etc-20230912. Addresses #5006. • [xry111] - Update to iproute2-6.5.0. Fixes #5342. • 2023-09-13 • [xry111] - Fix CVE-2023-4806 for Glibc-2.38. Fixes #5347. • 2023-09-12 • [xry111] - Fix CVE-2023-4527 for Glibc-2.38. Fixes #5346. • 2023-09-07 • [xry111] - Fix an issue in pkgconf-2.0.3 causing BLFS packages fail to build. Fixes #5341. • 2023-09-05 • [xry111] - Move pkgconf before binutils for binutils building system to detect zstd properly. Fixes #5340. • [xry111] - Update to linux-6.5.1. Fixes #5332. • [xry111] - Update to pkgconf-2.0.3. Fixes #5339. • [xry111] - Update to dbus-1.14.10. Fixes #5337. • 2023-09-04 • [bdubbs] - Move caution regarding building by mixing different version of LFS to General Compilation
Instructions. Fixes #5338. • 2023-09-02
• [xry111] - Add --no-cache-dir option for pip3 wheel commands. Addresses BLFS #18466. • [bdubbs] - Update to vim-9.0.1837. Addresses #4500. • [bdubbs] - Update to zlib-1.3. Fixes #5324. • [bdubbs] - Update to wheel-0.41.2 (Python Module). Fixes #5328. • [bdubbs] - Update to util-linux-2.39.2. Fixes #5322. • [bdubbs] - Update to sysvinit-3.08. Fixes #5321.
8
Linux From Scratch - Version 12.1
• [bdubbs] - Update to shadow-4.14.0. Fixes #5319. • [bdubbs] - Update to Python-3.11.5. Fixes #5330. • [bdubbs] - Update to procps-ng-4.0.4 (security fix for 32-bit systems). Fixes #5335. • [bdubbs] - Update to pkgconf-2.0.2. Fixes #5323. • [bdubbs] - Update to mpfr-4.2.1. Fixes #5326. • [bdubbs] - Update to kbd-2.6.2. Fixes #5318. • [bdubbs] - Update to gzip-1.13. Fixes #5325. • [bdubbs] - Update to coreutils-9.4. Fixes #5334. • [bdubbs] - Remove unused usb group. Fixes #5331. • 2023-09-01 • [bdubbs] - LFS-12.0 released.
1.4. Resources
1.4.1. FAQ
If during the building of the LFS system you encounter any errors, have any questions, or think there is a typo in the book, please start by consulting the list of Frequently Asked Questions (FAQ), located at https://www.linuxfromscratch. org/faq/.
1.4.2. Mailing Lists
The linuxfromscratch.org server hosts a number of mailing lists used for the development of the LFS project. These lists include the main development and support lists, among others. If you cannot find an answer to your problem on the FAQ page, the next step would be to search the mailing lists at https://www.linuxfromscratch.org/search.html. For information on the different lists, how to subscribe, archive locations, and additional information, visit https://www. linuxfromscratch.org/mail.html.
1.4.3. IRC
Several members of the LFS community offer assistance via Internet Relay Chat (IRC). Before using this support, please make sure your question is not already answered in the LFS FAQ or the mailing list archives. You can find the IRC network at irc.libera.chat. The support channel is named #lfs-support.
1.4.4. Mirror Sites
The LFS project has a number of world-wide mirrors to make accessing the website and downloading the required packages more convenient. Please visit the LFS website at https://www.linuxfromscratch.org/mirrors.html for a list of current mirrors.
1.4.5. Contact Information
Please direct all your questions and comments to one of the LFS mailing lists (see above). 9
Linux From Scratch - Version 12.1
1.5. Help
Note
In case you've hit an issue building one package with the LFS instruction, we strongly discourage posting the issue directly onto the upstream support channel before discussing via a LFS support channel listed in Section 1.4, “Resources”. Doing so is often quite inefficient because the upstream maintainers are rarely familiar with LFS building procedure. Even if you've really hit an upstream issue, the LFS community can still help to isolate the information wanted by the upstream maintainers and make a proper report. If you must ask a question directly via an upstream support channel, you shall at least note that many upstream projects have the support channels separated from the bug tracker. The “bug” reports for asking questions are considered invalid and may annoy upstream developers for these projects.
If an issue or a question is encountered while working through this book, please check the FAQ page at https://www. linuxfromscratch.org/faq/#generalfaq. Questions are often already answered there. If your question is not answered on that page, try to find the source of the problem. The following hint will give you some guidance for troubleshooting: https://www.linuxfromscratch.org/hints/downloads/files/errors.txt. If you cannot find your problem listed in the FAQ, search the mailing lists at https://www.linuxfromscratch.org/search. html. We also have a wonderful LFS community that is willing to offer assistance through the mailing lists and IRC (see the Section 1.4, “Resources” section of this book). However, we get several support questions every day, and many of them could have been easily answered by going to the FAQ or by searching the mailing lists first. So, for us to offer the best assistance possible, you should first do some research on your own. That allows us to focus on the more unusual support needs. If your searches do not produce a solution, please include all the relevant information (mentioned below) in your request for help.
1.5.1. Things to Mention
Apart from a brief explanation of the problem being experienced, any request for help should include these essential things: • The version of the book being used (in this case 12.1) • The host distribution and version being used to create LFS • The output from the Host System Requirements script • The package or section the problem was encountered in • The exact error message, or a clear description of the problem • Note whether you have deviated from the book at all
Note
Deviating from this book does not mean that we will not help you. After all, LFS is about personal preference. Being up-front about any changes to the established procedure helps us evaluate and determine possible causes of your problem.
1.5.2. Configure Script Problems
If something goes wrong while running the configure script, review the config.log file. This file may contain errors encountered during configure which were not printed to the screen. Include the relevant lines if you need to ask for help.
10
Linux From Scratch - Version 12.1
1.5.3. Compilation Problems
Both the screen output and the contents of various files are useful in determining the cause of compilation problems. The screen output from the configure script and the make run can be helpful. It is not necessary to include the entire output, but do include all of the relevant information. Here is an example of the type of information to include from the make screen output.
gcc -DALIASPATH=\"/mnt/lfs/usr/share/locale:.\" -DLOCALEDIR=\"/mnt/lfs/usr/share/locale\" -DLIBDIR=\"/mnt/lfs/usr/lib\" -DINCLUDEDIR=\"/mnt/lfs/usr/include\" -DHAVE_CONFIG_H -I. -I. -g -O2 -c getopt1.c gcc -g -O2 -static -o make ar.o arscan.o commands.o dir.o expand.o file.o function.o getopt.o implicit.o job.o main.o misc.o read.o remake.o rule.o signame.o variable.o vpath.o default.o remote-stub.o version.o opt1.o -lutil job.o: In function `load_too_high': /lfs/tmp/make-3.79.1/job.c:1565: undefined reference to `getloadavg' collect2: ld returned 1 exit status make[2]: *** [make] Error 1 make[2]: Leaving directory `/lfs/tmp/make-3.79.1' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/lfs/tmp/make-3.79.1' make: *** [all-recursive-am] Error 2
In this case, many people would just include the bottom section:
make [2]: *** [make] Error 1
This is not enough information to diagnose the problem, because it only notes that something went wrong, not what went wrong. The entire section, as in the example above, is what should be saved because it includes the command that was executed and all the associated error messages. An excellent article about asking for help on the Internet is available online at http://catb.org/~esr/faqs/smart-questions. html. Read this document, and follow the hints. Doing so will increase the likelihood of getting the help you need.
11
Linux From Scratch - Version 12.1
Part II. Preparing for the Build
Linux From Scratch - Version 12.1
Chapter 2. Preparing the Host System
2.1. Introduction
In this chapter, the host tools needed for building LFS are checked and, if necessary, installed. Then a partition which will host the LFS system is prepared. We will create the partition itself, create a file system on it, and mount it.
2.2. Host System Requirements
2.2.1. Hardware
The LFS editors recommend that the system CPU have at least four cores and that the system have at least 8 GB of memory. Older systems that do not meet these requirements will still work, but the time to build packages will be significantly longer than documented.
2.2.2. Software
Your host system should have the following software with the minimum versions indicated. This should not be an issue for most modern Linux distributions. Also note that many distributions will place software headers into separate packages, often in the form of <package-name>-devel or <package-name>-dev. Be sure to install those if your distribution provides them.
Earlier versions of the listed software packages may work, but have not been tested.
• Bash-3.2 (/bin/sh should be a symbolic or hard link to bash) • Binutils-2.13.1 (Versions greater than 2.42 are not recommended as they have not been tested) • Bison-2.7 (/usr/bin/yacc should be a link to bison or a small script that executes bison) • Coreutils-8.1 • Diffutils-2.8.1 • Findutils-4.2.31 • Gawk-4.0.1 (/usr/bin/awk should be a link to gawk) • GCC-5.2 including the C++ compiler, g++ (Versions greater than 13.2.0 are not recommended as they have not
been tested). C and C++ standard libraries (with headers) must also be present so the C++ compiler can build hosted programs • Grep-2.5.1a • Gzip-1.3.12 • Linux Kernel-4.19
The reason for the kernel version requirement is that we specify that version when building glibc in Chapter 5 and Chapter 8, so the workarounds for older kernels are not enabled and the compiled glibc is slightly faster and smaller. As at Feb 2024, 4.19 is the oldest kernel release still supported by the kernel developers. Some kernel releases older than 4.19 may be still supported by third-party teams, but they are not considered official upstream kernel releases; read https://kernel.org/category/releases.html for the details.
If the host kernel is earlier than 4.19 you will need to replace the kernel with a more up-to-date version. There are two ways you can go about this. First, see if your Linux vendor provides a 4.19 or later kernel package. If so, you may wish to install it. If your vendor doesn't offer an acceptable kernel package, or you would prefer not to install it, you can compile a kernel yourself. Instructions for compiling the kernel and configuring the boot loader (assuming the host uses GRUB) are located in Chapter 10.
13
Linux From Scratch - Version 12.1
We require the host kernel to support UNIX 98 pseudo terminal (PTY). It should be enabled on all desktop or server distros shipping Linux 4.19 or a newer kernel. If you are building a custom host kernel, ensure CONFIG_ UNIX98_PTYS is set to y in the kernel configuration. • M4-1.4.10 • Make-4.0 • Patch-2.5.4 • Perl-5.8.8 • Python-3.4 • Sed-4.1.5 • Tar-1.22 • Texinfo-5.0 • Xz-5.0.0
Important
Note that the symlinks mentioned above are required to build an LFS system using the instructions contained within this book. Symlinks that point to other software (such as dash, mawk, etc.) may work, but are not tested or supported by the LFS development team, and may require either deviation from the instructions or additional patches to some packages.
To see whether your host system has all the appropriate versions, and the ability to compile programs, run the following commands:
cat > version-check.sh << "EOF" #!/bin/bash # A script to list version numbers of critical development tools
# If you have tools installed in other directories, adjust PATH here AND # in ~lfs/.bashrc (section 4.4) as well.
LC_ALL=C PATH=/usr/bin:/bin
bail() { echo "FATAL: $1"; exit 1; } grep --version > /dev/null 2> /dev/null || bail "grep does not work" sed '' /dev/null || bail "sed does not work" sort /dev/null || bail "sort does not work"
ver_check() {
if ! type -p $2 &>/dev/null then
echo "ERROR: Cannot find $2 ($1)"; return 1; fi v=$($2 --version 2>&1 | grep -E -o '[0-9]+\.[0-9\.]+[a-z]*' | head -n1) if printf '%s\n' $3 $v | sort --version-sort --check &>/dev/null then
printf "OK: %-9s %-6s >= $3\n" "$1" "$v"; return 0; else
printf "ERROR: %-9s is TOO OLD ($3 or later required)\n" "$1"; return 1; fi }
ver_kernel() {
14
Linux From Scratch - Version 12.1
kver=$(uname -r | grep -E -o '^[0-9\.]+') if printf '%s\n' $1 $kver | sort --version-sort --check &>/dev/null then
printf "OK: Linux Kernel $kver >= $1\n"; return 0; else
printf "ERROR: Linux Kernel ($kver) is TOO OLD ($1 or later required)\n" "$kver"; return 1; fi }
# Coreutils first because --version-sort needs Coreutils >= 7.0
ver_check Coreutils
sort
8.1 || bail "Coreutils too old, stop"
ver_check Bash
bash
3.2
ver_check Binutils
ld
2.13.1
ver_check Bison
bison 2.7
ver_check Diffutils
diff
2.8.1
ver_check Findutils
find
4.2.31
ver_check Gawk
gawk
4.0.1
ver_check GCC
gcc
5.2
ver_check "GCC (C++)" g++
5.2
ver_check Grep
grep
2.5.1a
ver_check Gzip
gzip
1.3.12
ver_check M4
m4
1.4.10
ver_check Make
make
4.0
ver_check Patch
patch 2.5.4
ver_check Perl
perl
5.8.8
ver_check Python
python3 3.4
ver_check Sed
sed
4.1.5
ver_check Tar
tar
1.22
ver_check Texinfo
texi2any 5.0
ver_check Xz
xz
5.0.0
ver_kernel 4.19
if mount | grep -q 'devpts on /dev/pts' && [ -e /dev/ptmx ] then echo "OK: Linux Kernel supports UNIX 98 PTY"; else echo "ERROR: Linux Kernel does NOT support UNIX 98 PTY"; fi
alias_check() { if $1 --version 2>&1 | grep -qi $2 then printf "OK: %-4s is $2\n" "$1"; else printf "ERROR: %-4s is NOT $2\n" "$1"; fi
} echo "Aliases:" alias_check awk GNU alias_check yacc Bison alias_check sh Bash
echo "Compiler check:" if printf "int main(){}" | g++ -x c++ then echo "OK: g++ works"; else echo "ERROR: g++ does NOT work"; fi rm -f a.out
if [ "$(nproc)" = "" ]; then echo "ERROR: nproc is not available or it produces empty output"
else echo "OK: nproc reports $(nproc) logical cores are available"
fi EOF
bash version-check.sh
15
Linux From Scratch - Version 12.1
2.3. Building LFS in Stages
LFS is designed to be built in one session. That is, the instructions assume that the system will not be shut down during the process. This does not mean that the system has to be built in one sitting. The issue is that certain procedures must be repeated after a reboot when resuming LFS at different points.
2.3.1. Chapters 14
These chapters run commands on the host system. When restarting, be certain of one thing:
• Procedures performed as the root user after Section 2.4 must have the LFS environment variable set FOR THE ROOT USER.
2.3.2. Chapters 56
• The /mnt/lfs partition must be mounted. • These two chapters must be done as user lfs. A su - lfs command must be issued before performing any task in
these chapters. If you don't do that, you are at risk of installing packages to the host, and potentially rendering it unusable. • The procedures in General Compilation Instructions are critical. If there is any doubt a package has been installed correctly, ensure the previously expanded tarball has been removed, then re-extract the package, and complete all the instructions in that section.
2.3.3. Chapters 710
• The /mnt/lfs partition must be mounted. • A few operations, from “Changing Ownership” to “Entering the Chroot Environment,” must be done as the root
user, with the LFS environment variable set for the root user. • When entering chroot, the LFS environment variable must be set for root. The LFS variable is not used after the
chroot environment has been entered. • The virtual file systems must be mounted. This can be done before or after entering chroot by changing to a
host virtual terminal and, as root, running the commands in Section 7.3.1, “Mounting and Populating /dev” and Section 7.3.2, “Mounting Virtual Kernel File Systems”.
2.4. Creating a New Partition
Like most other operating systems, LFS is usually installed on a dedicated partition. The recommended approach to building an LFS system is to use an available empty partition or, if you have enough unpartitioned space, to create one.
A minimal system requires a partition of around 10 gigabytes (GB). This is enough to store all the source tarballs and compile the packages. However, if the LFS system is intended to be the primary Linux system, additional software will probably be installed which will require additional space. A 30 GB partition is a reasonable size to provide for growth. The LFS system itself will not take up this much room. A large portion of this requirement is to provide sufficient free temporary storage as well as for adding additional capabilities after LFS is complete. Additionally, compiling packages can require a lot of disk space which will be reclaimed after the package is installed.
Because there is not always enough Random Access Memory (RAM) available for compilation processes, it is a good idea to use a small disk partition as swap space. This is used by the kernel to store seldom-used data and leave more memory available for active processes. The swap partition for an LFS system can be the same as the one used by the host system, in which case it is not necessary to create another one.
16
Linux From Scratch - Version 12.1
Start a disk partitioning program such as cfdisk or fdisk with a command line option naming the hard disk on which the new partition will be created—for example /dev/sda for the primary disk drive. Create a Linux native partition and a swap partition, if needed. Please refer to cfdisk(8) or fdisk(8) if you do not yet know how to use the programs.
Note
For experienced users, other partitioning schemes are possible. The new LFS system can be on a software RAID array or an LVM logical volume. However, some of these options require an initramfs, which is an advanced topic. These partitioning methodologies are not recommended for first time LFS users.
Remember the designation of the new partition (e.g., sda5). This book will refer to this as the LFS partition. Also remember the designation of the swap partition. These names will be needed later for the /etc/fstab file.
2.4.1. Other Partition Issues
Requests for advice on system partitioning are often posted on the LFS mailing lists. This is a highly subjective topic. The default for most distributions is to use the entire drive with the exception of one small swap partition. This is not optimal for LFS for several reasons. It reduces flexibility, makes sharing of data across multiple distributions or LFS builds more difficult, makes backups more time consuming, and can waste disk space through inefficient allocation of file system structures.
2.4.1.1. The Root Partition
A root LFS partition (not to be confused with the /root directory) of twenty gigabytes is a good compromise for most systems. It provides enough space to build LFS and most of BLFS, but is small enough so that multiple partitions can be easily created for experimentation.
2.4.1.2. The Swap Partition
Most distributions automatically create a swap partition. Generally the recommended size of the swap partition is about twice the amount of physical RAM, however this is rarely needed. If disk space is limited, hold the swap partition to two gigabytes and monitor the amount of disk swapping.
If you want to use the hibernation feature (suspend-to-disk) of Linux, it writes out the contents of RAM to the swap partition before turning off the machine. In this case the size of the swap partition should be at least as large as the system's installed RAM.
Swapping is never good. For mechanical hard drives you can generally tell if a system is swapping by just listening to disk activity and observing how the system reacts to commands. With an SSD you will not be able to hear swapping, but you can tell how much swap space is being used by running the top or free programs. Use of an SSD for a swap partition should be avoided if possible. The first reaction to swapping should be to check for an unreasonable command such as trying to edit a five gigabyte file. If swapping becomes a normal occurrence, the best solution is to purchase more RAM for your system.
2.4.1.3. The Grub Bios Partition
If the boot disk has been partitioned with a GUID Partition Table (GPT), then a small, typically 1 MB, partition must be created if it does not already exist. This partition is not formatted, but must be available for GRUB to use during installation of the boot loader. This partition will normally be labeled 'BIOS Boot' if using fdisk or have a code of EF02 if using the gdisk command.
17
Linux From Scratch - Version 12.1
Note
The Grub Bios partition must be on the drive that the BIOS uses to boot the system. This is not necessarily the drive that holds the LFS root partition. The disks on a system may use different partition table types. The necessity of the Grub Bios partition depends only on the partition table type of the boot disk.
2.4.1.4. Convenience Partitions
There are several other partitions that are not required, but should be considered when designing a disk layout. The following list is not comprehensive, but is meant as a guide.
• /boot Highly recommended. Use this partition to store kernels and other booting information. To minimize potential boot problems with larger disks, make this the first physical partition on your first disk drive. A partition size of 200 megabytes is adequate.
• /boot/efi The EFI System Partition, which is needed for booting the system with UEFI. Read the BLFS page for details.
• /home Highly recommended. Share your home directory and user customization across multiple distributions or LFS builds. The size is generally fairly large and depends on available disk space.
• /usr In LFS, /bin, /lib, and /sbin are symlinks to their counterparts in /usr. So /usr contains all the binaries needed for the system to run. For LFS a separate partition for /usr is normally not needed. If you create it anyway, you should make a partition large enough to fit all the programs and libraries in the system. The root partition can be very small (maybe just one gigabyte) in this configuration, so it's suitable for a thin client or diskless workstation (where /usr is mounted from a remote server). However, you should be aware that an initramfs (not covered by LFS) will be needed to boot a system with a separate /usr partition.
• /opt This directory is most useful for BLFS, where multiple large packages like KDE or Texlive can be installed without embedding the files in the /usr hierarchy. If used, 5 to 10 gigabytes is generally adequate.
• /tmp A separate /tmp partition is rare, but useful if configuring a thin client. This partition, if used, will usually not need to exceed a couple of gigabytes. If you have enough RAM, you can mount a tmpfs on /tmp to make access to temporary files faster.
• /usr/src This partition is very useful for providing a location to store BLFS source files and share them across LFS builds. It can also be used as a location for building BLFS packages. A reasonably large partition of 30-50 gigabytes provides plenty of room.
Any separate partition that you want automatically mounted when the system starts must be specified in the /etc/fstab file. Details about how to specify partitions will be discussed in Section 10.2, “Creating the /etc/fstab File”.
2.5. Creating a File System on the Partition
A partition is just a range of sectors on a disk drive, delimited by boundaries set in a partition table. Before the operating system can use a partition to store any files, the partition must be formatted to contain a file system, typically consisting of a label, directory blocks, data blocks, and an indexing scheme to locate a particular file on demand. The file system also helps the OS keep track of free space on the partition, reserve the needed sectors when a new file is created or an existing file is extended, and recycle the free data segments created when files are deleted. It may also provide support for data redundancy, and for error recovery.
LFS can use any file system recognized by the Linux kernel, but the most common types are ext3 and ext4. The choice of the right file system can be complex; it depends on the characteristics of the files and the size of the partition. For example:
18
Linux From Scratch - Version 12.1
ext2 is suitable for small partitions that are updated infrequently such as /boot.
ext3 is an upgrade to ext2 that includes a journal to help recover the partition's status in the case of an unclean shutdown. It is commonly used as a general purpose file system.
ext4 is the latest version of the ext family of file systems. It provides several new capabilities including nano-second timestamps, creation and use of very large files (up to 16 TB), and speed improvements.
Other file systems, including FAT32, NTFS, ReiserFS, JFS, and XFS are useful for specialized purposes. More information about these file systems, and many others, can be found at https://en.wikipedia.org/wiki/Comparison_of_ file_systems.
LFS assumes that the root file system (/) is of type ext4. To create an ext4 file system on the LFS partition, issue the following command:
mkfs -v -t ext4 /dev/<xxx>
Replace <xxx> with the name of the LFS partition.
If you are using an existing swap partition, there is no need to format it. If a new swap partition was created, it will need to be initialized with this command:
mkswap /dev/<yyy>
Replace <yyy> with the name of the swap partition.
2.6. Setting The $LFS Variable
Throughout this book, the environment variable LFS will be used several times. You should ensure that this variable is always defined throughout the LFS build process. It should be set to the name of the directory where you will be building your LFS system - we will use /mnt/lfs as an example, but you may choose any directory name you want. If you are building LFS on a separate partition, this directory will be the mount point for the partition. Choose a directory location and set the variable with the following command:
export LFS=/mnt/lfs
Having this variable set is beneficial in that commands such as mkdir -v $LFS/tools can be typed literally. The shell will automatically replace “$LFS” with “/mnt/lfs” (or whatever value the variable was set to) when it processes the command line.
Caution
Do not forget to check that LFS is set whenever you leave and reenter the current working environment (such as when doing a su to root or another user). Check that the LFS variable is set up properly with:
echo $LFS
Make sure the output shows the path to your LFS system's build location, which is /mnt/lfs if the provided example was followed. If the output is incorrect, use the command given earlier on this page to set $LFS to the correct directory name.
19
Linux From Scratch - Version 12.1
Note
One way to ensure that the LFS variable is always set is to edit the .bash_profile file in both your personal home directory and in /root/.bash_profile and enter the export command above. In addition, the shell specified in the /etc/passwd file for all users that need the LFS variable must be bash to ensure that the /root/ .bash_profile file is incorporated as a part of the login process.
Another consideration is the method that is used to log into the host system. If logging in through a graphical display manager, the user's .bash_profile is not normally used when a virtual terminal is started. In this case, add the export command to the .bashrc file for the user and root. In addition, some distributions use an "if" test, and do not run the remaining .bashrc instructions for a non-interactive bash invocation. Be sure to place the export command ahead of the test for non-interactive use.
2.7. Mounting the New Partition
Now that a file system has been created, the partition must be mounted so the host system can access it. This book assumes that the file system is mounted at the directory specified by the LFS environment variable described in the previous section.
Strictly speaking, one cannot “mount a partition.” One mounts the file system embedded in that partition. But since a single partition can't contain more than one file system, people often speak of the partition and the associated file system as if they were one and the same.
Create the mount point and mount the LFS file system with these commands:
mkdir -pv $LFS mount -v -t ext4 /dev/<xxx> $LFS
Replace <xxx> with the name of the LFS partition.
If you are using multiple partitions for LFS (e.g., one for / and another for /home), mount them like this:
mkdir -pv $LFS mount -v -t ext4 /dev/<xxx> $LFS mkdir -v $LFS/home mount -v -t ext4 /dev/<yyy> $LFS/home
Replace <xxx> and <yyy> with the appropriate partition names.
Ensure that this new partition is not mounted with permissions that are too restrictive (such as the nosuid or nodev options). Run the mount command without any parameters to see what options are set for the mounted LFS partition. If nosuid and/or nodev are set, the partition must be remounted.
Warning
The above instructions assume that you will not restart your computer throughout the LFS process. If you shut down your system, you will either need to remount the LFS partition each time you restart the build process, or modify the host system's /etc/fstab file to automatically remount it when you reboot. For example, you might add this line to your /etc/fstab file:
/dev/<xxx> /mnt/lfs ext4 defaults
1
1
If you use additional optional partitions, be sure to add them also.
20
Linux From Scratch - Version 12.1 If you are using a swap partition, ensure that it is enabled using the swapon command:
/sbin/swapon -v /dev/<zzz>
Replace <zzz> with the name of the swap partition. Now that the new LFS partition is open for business, it's time to download the packages.
21
Linux From Scratch - Version 12.1
Chapter 3. Packages and Patches
3.1. Introduction
This chapter includes a list of packages that need to be downloaded in order to build a basic Linux system. The listed version numbers correspond to versions of the software that are known to work, and this book is based on their use. We highly recommend against using different versions, because the build commands for one version may not work with a different version, unless the different version is specified by an LFS erratum or security advisory. The newest package versions may also have problems that require work-arounds. These work-arounds will be developed and stabilized in the development version of the book.
For some packages, the release tarball and the (Git or SVN) repository snapshot tarball for that release may be published with similar file names. A release tarball contains generated files (for example, a configure script generated by autoconf), in addition to the contents of the corresponding repository snapshot. The book uses release tarballs whenever possible. Using a repository snapshot instead of a release tarball specified by the book will cause problems.
Download locations may not always be accessible. If a download location has changed since this book was published, Google (https://www.google.com/) provides a useful search engine for most packages. If this search is unsuccessful, try one of the alternative means of downloading at https://www.linuxfromscratch.org/lfs/mirrors.html#files.
Downloaded packages and patches will need to be stored somewhere that is conveniently available throughout the entire build. A working directory is also required to unpack the sources and build them. $LFS/sources can be used both as the place to store the tarballs and patches and as a working directory. By using this directory, the required elements will be located on the LFS partition and will be available during all stages of the building process.
To create this directory, execute the following command, as user root, before starting the download session:
mkdir -v $LFS/sources
Make this directory writable and sticky. “Sticky” means that even if multiple users have write permission on a directory, only the owner of a file can delete the file within a sticky directory. The following command will enable the write and sticky modes:
chmod -v a+wt $LFS/sources
There are several ways to obtain all the necessary packages and patches to build LFS:
• The files can be downloaded individually as described in the next two sections. • For stable versions of the book, a tarball of all the needed files can be downloaded from one of the mirror sites
listed at https://www.linuxfromscratch.org/mirrors.html#files. • The files can be downloaded using wget and a wget-list as described below.
To download all of the packages and patches by using wget-list-sysv as an input to the wget command, use:
wget --input-file=wget-list-sysv --continue --directory-prefix=$LFS/sources
Additionally, starting with LFS-7.0, there is a separate file, md5sums, which can be used to verify that all the correct packages are available before proceeding. Place that file in $LFS/sources and run:
pushd $LFS/sources md5sum -c md5sums
popd
This check can be used after retrieving the needed files with any of the methods listed above.
22
Linux From Scratch - Version 12.1
If the packages and patches are downloaded as a non-root user, these files will be owned by the user. The file system records the owner by its UID, and the UID of a normal user in the host distro is not assigned in LFS. So the files will be left owned by an unnamed UID in the final LFS system. If you won't assign the same UID for your user in the LFS system, change the owners of these files to root now to avoid this issue:
chown root:root $LFS/sources/*
3.2. All Packages
Note
Read the security advisories before downloading packages to figure out if a newer version of any package should be used to avoid security vulnerabilities.
The upstream sources may remove old releases, especially when those releases contain a security vulnerability. If one URL below is not reachable, you should read the security advisories first to figure out if a newer version (with the vulnerability fixed) should be used. If not, try to download the removed package from a mirror. Although it's possible to download an old release from a mirror even if this release has been removed because of a vulnerability, it's not a good idea to use a release known to be vulnerable when building your system.
Download or otherwise obtain the following packages:
• Acl (2.3.2) - 363 KB: Home page: https://savannah.nongnu.org/projects/acl Download: https://download.savannah.gnu.org/releases/acl/acl-2.3.2.tar.xz MD5 sum: 590765dee95907dbc3c856f7255bd669 • Attr (2.5.2) - 484 KB: Home page: https://savannah.nongnu.org/projects/attr Download: https://download.savannah.gnu.org/releases/attr/attr-2.5.2.tar.gz MD5 sum: 227043ec2f6ca03c0948df5517f9c927 • Autoconf (2.72) - 1,360 KB: Home page: https://www.gnu.org/software/autoconf/ Download: https://ftp.gnu.org/gnu/autoconf/autoconf-2.72.tar.xz MD5 sum: 1be79f7106ab6767f18391c5e22be701 • Automake (1.16.5) - 1,565 KB: Home page: https://www.gnu.org/software/automake/ Download: https://ftp.gnu.org/gnu/automake/automake-1.16.5.tar.xz MD5 sum: 4017e96f89fca45ca946f1c5db6be714 • Bash (5.2.21) - 10,696 KB: Home page: https://www.gnu.org/software/bash/ Download: https://ftp.gnu.org/gnu/bash/bash-5.2.21.tar.gz MD5 sum: ad5b38410e3bf0e9bcc20e2765f5e3f9 • Bc (6.7.5) - 460 KB: Home page: https://git.gavinhoward.com/gavin/bc Download: https://github.com/gavinhoward/bc/releases/download/6.7.5/bc-6.7.5.tar.xz MD5 sum: e249b1f86f886d6fb71c15f72b65dd3d
23
Linux From Scratch - Version 12.1
• Binutils (2.42) - 26,922 KB: Home page: https://www.gnu.org/software/binutils/ Download: https://sourceware.org/pub/binutils/releases/binutils-2.42.tar.xz MD5 sum: a075178a9646551379bfb64040487715
• Bison (3.8.2) - 2,752 KB: Home page: https://www.gnu.org/software/bison/ Download: https://ftp.gnu.org/gnu/bison/bison-3.8.2.tar.xz MD5 sum: c28f119f405a2304ff0a7ccdcc629713
• Bzip2 (1.0.8) - 792 KB: Download: https://www.sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz MD5 sum: 67e051268d0c475ea773822f7500d0e5
• Check (0.15.2) - 760 KB: Home page: https://libcheck.github.io/check Download: https://github.com/libcheck/check/releases/download/0.15.2/check-0.15.2.tar.gz MD5 sum: 50fcafcecde5a380415b12e9c574e0b2
• Coreutils (9.4) - 5,840 KB: Home page: https://www.gnu.org/software/coreutils/ Download: https://ftp.gnu.org/gnu/coreutils/coreutils-9.4.tar.xz MD5 sum: 459e9546074db2834eefe5421f250025
• DejaGNU (1.6.3) - 608 KB: Home page: https://www.gnu.org/software/dejagnu/ Download: https://ftp.gnu.org/gnu/dejagnu/dejagnu-1.6.3.tar.gz MD5 sum: 68c5208c58236eba447d7d6d1326b821
• Diffutils (3.10) - 1,587 KB: Home page: https://www.gnu.org/software/diffutils/ Download: https://ftp.gnu.org/gnu/diffutils/diffutils-3.10.tar.xz MD5 sum: 2745c50f6f4e395e7b7d52f902d075bf
• E2fsprogs (1.47.0) - 9,412 KB: Home page: http://e2fsprogs.sourceforge.net/ Download: https://downloads.sourceforge.net/project/e2fsprogs/e2fsprogs/v1.47.0/e2fsprogs-1.47.0.tar.gz MD5 sum: 6b4f18a33873623041857b4963641ee9
• Elfutils (0.190) - 8,949 KB: Home page: https://sourceware.org/elfutils/ Download: https://sourceware.org/ftp/elfutils/0.190/elfutils-0.190.tar.bz2 MD5 sum: 79ad698e61a052bea79e77df6a08bc4b
• Expat (2.6.0) - 473 KB: Home page: https://libexpat.github.io/ Download: https://prdownloads.sourceforge.net/expat/expat-2.6.0.tar.xz MD5 sum: bd169cb11f4b9bdfddadf9e88a5c4d4b
• Expect (5.45.4) - 618 KB: Home page: https://core.tcl.tk/expect/ Download: https://prdownloads.sourceforge.net/expect/expect5.45.4.tar.gz MD5 sum: 00fce8de158422f5ccd2666512329bd2
24
Linux From Scratch - Version 12.1
• File (5.45) - 1,218 KB: Home page: https://www.darwinsys.com/file/ Download: https://astron.com/pub/file/file-5.45.tar.gz MD5 sum: 26b2a96d4e3a8938827a1e572afd527a
• Findutils (4.9.0) - 1,999 KB: Home page: https://www.gnu.org/software/findutils/ Download: https://ftp.gnu.org/gnu/findutils/findutils-4.9.0.tar.xz MD5 sum: 4a4a547e888a944b2f3af31d789a1137
• Flex (2.6.4) - 1,386 KB: Home page: https://github.com/westes/flex Download: https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz MD5 sum: 2882e3179748cc9f9c23ec593d6adc8d
• Flit-core (3.9.0) - 41 KB: Home page: https://pypi.org/project/flit-core/ Download: https://pypi.org/packages/source/f/flit-core/flit_core-3.9.0.tar.gz MD5 sum: 3bc52f1952b9a78361114147da63c35b
• Gawk (5.3.0) - 3,356 KB: Home page: https://www.gnu.org/software/gawk/ Download: https://ftp.gnu.org/gnu/gawk/gawk-5.3.0.tar.xz MD5 sum: 97c5a7d83f91a7e1b2035ebbe6ac7abd
• GCC (13.2.0) - 85,800 KB: Home page: https://gcc.gnu.org/ Download: https://ftp.gnu.org/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.xz MD5 sum: e0e48554cc6e4f261d55ddee9ab69075
• GDBM (1.23) - 1,092 KB: Home page: https://www.gnu.org/software/gdbm/ Download: https://ftp.gnu.org/gnu/gdbm/gdbm-1.23.tar.gz MD5 sum: 8551961e36bf8c70b7500d255d3658ec
• Gettext (0.22.4) - 10,016 KB: Home page: https://www.gnu.org/software/gettext/ Download: https://ftp.gnu.org/gnu/gettext/gettext-0.22.4.tar.xz MD5 sum: 2d8507d003ef3ddd1c172707ffa97ed8
• Glibc (2.39) - 18,092 KB: Home page: https://www.gnu.org/software/libc/ Download: https://ftp.gnu.org/gnu/glibc/glibc-2.39.tar.xz MD5 sum: be81e87f72b5ea2c0ffe2bedfeb680c6
Note
The Glibc developers maintain a Git branch containing patches considered worthy for Glibc-2.39 but unfortunately developed after Glibc-2.39 release. The LFS editors will issue a security advisory if any security fix is added into the branch, but no actions will be taken for other newly added patches. You may review the patches yourself and incorporate some patches if you consider them important.
25
Linux From Scratch - Version 12.1
• GMP (6.3.0) - 2,046 KB: Home page: https://www.gnu.org/software/gmp/ Download: https://ftp.gnu.org/gnu/gmp/gmp-6.3.0.tar.xz MD5 sum: 956dc04e864001a9c22429f761f2c283
• Gperf (3.1) - 1,188 KB: Home page: https://www.gnu.org/software/gperf/ Download: https://ftp.gnu.org/gnu/gperf/gperf-3.1.tar.gz MD5 sum: 9e251c0a618ad0824b51117d5d9db87e
• Grep (3.11) - 1,664 KB: Home page: https://www.gnu.org/software/grep/ Download: https://ftp.gnu.org/gnu/grep/grep-3.11.tar.xz MD5 sum: 7c9bbd74492131245f7cdb291fa142c0
• Groff (1.23.0) - 7,259 KB: Home page: https://www.gnu.org/software/groff/ Download: https://ftp.gnu.org/gnu/groff/groff-1.23.0.tar.gz MD5 sum: 5e4f40315a22bb8a158748e7d5094c7d
• GRUB (2.12) - 6,524 KB: Home page: https://www.gnu.org/software/grub/ Download: https://ftp.gnu.org/gnu/grub/grub-2.12.tar.xz MD5 sum: 60c564b1bdc39d8e43b3aab4bc0fb140
• Gzip (1.13) - 819 KB: Home page: https://www.gnu.org/software/gzip/ Download: https://ftp.gnu.org/gnu/gzip/gzip-1.13.tar.xz MD5 sum: d5c9fc9441288817a4a0be2da0249e29
• Iana-Etc (20240125) - 589 KB: Home page: https://www.iana.org/protocols Download: https://github.com/Mic92/iana-etc/releases/download/20240125/iana-etc-20240125.tar.gz MD5 sum: aed66d04de615d76c70890233081e584
• Inetutils (2.5) - 1,632 KB: Home page: https://www.gnu.org/software/inetutils/ Download: https://ftp.gnu.org/gnu/inetutils/inetutils-2.5.tar.xz MD5 sum: 9e5a6dfd2d794dc056a770e8ad4a9263
• Intltool (0.51.0) - 159 KB: Home page: https://freedesktop.org/wiki/Software/intltool Download: https://launchpad.net/intltool/trunk/0.51.0/+download/intltool-0.51.0.tar.gz MD5 sum: 12e517cac2b57a0121cda351570f1e63
• IPRoute2 (6.7.0) - 900 KB: Home page: https://www.kernel.org/pub/linux/utils/net/iproute2/ Download: https://www.kernel.org/pub/linux/utils/net/iproute2/iproute2-6.7.0.tar.xz MD5 sum: 35d8277d1469596b7edc07a51470a033
26
Linux From Scratch - Version 12.1
• Jinja2 (3.1.3) - 264 KB: Home page: https://jinja.palletsprojects.com/en/3.1.x/ Download: https://pypi.org/packages/source/J/Jinja2/Jinja2-3.1.3.tar.gz MD5 sum: caf5418c851eac59e70a78d9730d4cea
• Kbd (2.6.4) - 1,470 KB: Home page: https://kbd-project.org/ Download: https://www.kernel.org/pub/linux/utils/kbd/kbd-2.6.4.tar.xz MD5 sum: e2fd7adccf6b1e98eb1ae8d5a1ce5762
• Kmod (31) - 558 KB: Home page: https://github.com/kmod-project/kmod Download: https://www.kernel.org/pub/linux/utils/kernel/kmod/kmod-31.tar.xz MD5 sum: 6165867e1836d51795a11ea4762ff66a
• Less (643) - 579 KB: Home page: https://www.greenwoodsoftware.com/less/ Download: https://www.greenwoodsoftware.com/less/less-643.tar.gz MD5 sum: cf05e2546a3729492b944b4874dd43dd
• LFS-Bootscripts (20230728) - 33 KB: Download: https://www.linuxfromscratch.org/lfs/downloads/12.1/lfs-bootscripts-20230728.tar.xz MD5 sum: a236eaa9a1f699bc3fb6ab2acd7e7b6c
• Libcap (2.69) - 185 KB: Home page: https://sites.google.com/site/fullycapable/ Download: https://www.kernel.org/pub/linux/libs/security/linux-privs/libcap2/libcap-2.69.tar.xz MD5 sum: 4667bacb837f9ac4adb4a1a0266f4b65
• Libffi (3.4.4) - 1,331 KB: Home page: https://sourceware.org/libffi/ Download: https://github.com/libffi/libffi/releases/download/v3.4.4/libffi-3.4.4.tar.gz MD5 sum: 0da1a5ed7786ac12dcbaf0d499d8a049
• Libpipeline (1.5.7) - 956 KB: Home page: https://libpipeline.nongnu.org/ Download: https://download.savannah.gnu.org/releases/libpipeline/libpipeline-1.5.7.tar.gz MD5 sum: 1a48b5771b9f6c790fb4efdb1ac71342
• Libtool (2.4.7) - 996 KB: Home page: https://www.gnu.org/software/libtool/ Download: https://ftp.gnu.org/gnu/libtool/libtool-2.4.7.tar.xz MD5 sum: 2fc0b6ddcd66a89ed6e45db28fa44232
• Libxcrypt (4.4.36) - 610 KB: Home page: https://github.com/besser82/libxcrypt/ Download: https://github.com/besser82/libxcrypt/releases/download/v4.4.36/libxcrypt-4.4.36.tar.xz MD5 sum: b84cd4104e08c975063ec6c4d0372446
27
Linux From Scratch - Version 12.1
• Linux (6.7.4) - 138,130 KB: Home page: https://www.kernel.org/ Download: https://www.kernel.org/pub/linux/kernel/v6.x/linux-6.7.4.tar.xz MD5 sum: 370e1b6155ae63133380e421146619e0
Note
The Linux kernel is updated quite frequently, many times due to discoveries of security vulnerabilities. The latest available stable kernel version may be used, unless the errata page says otherwise. For users with limited speed or expensive bandwidth who wish to update the Linux kernel, a baseline version of the package and patches can be downloaded separately. This may save some time or cost for a subsequent patch level upgrade within a minor release.
• M4 (1.4.19) - 1,617 KB: Home page: https://www.gnu.org/software/m4/ Download: https://ftp.gnu.org/gnu/m4/m4-1.4.19.tar.xz MD5 sum: 0d90823e1426f1da2fd872df0311298d
• Make (4.4.1) - 2,300 KB: Home page: https://www.gnu.org/software/make/ Download: https://ftp.gnu.org/gnu/make/make-4.4.1.tar.gz MD5 sum: c8469a3713cbbe04d955d4ae4be23eeb
• Man-DB (2.12.0) - 1,941 KB: Home page: https://www.nongnu.org/man-db/ Download: https://download.savannah.gnu.org/releases/man-db/man-db-2.12.0.tar.xz MD5 sum: 67e0052fa200901b314fad7b68c9db27
• Man-pages (6.06) - 2,116 KB: Home page: https://www.kernel.org/doc/man-pages/ Download: https://www.kernel.org/pub/linux/docs/man-pages/man-pages-6.06.tar.xz MD5 sum: 26b39e38248144156d437e1e10cb20bf
• MarkupSafe (2.1.5) - 19 KB: Home page: https://palletsprojects.com/p/markupsafe/ Download: https://pypi.org/packages/source/M/MarkupSafe/MarkupSafe-2.1.5.tar.gz MD5 sum: 8fe7227653f2fb9b1ffe7f9f2058998a
• Meson (1.3.2) - 2,172 KB: Home page: https://mesonbuild.com Download: https://github.com/mesonbuild/meson/releases/download/1.3.2/meson-1.3.2.tar.gz MD5 sum: 2d0ebd3a24249617b1c4d30026380cf8
• MPC (1.3.1) - 756 KB: Home page: https://www.multiprecision.org/ Download: https://ftp.gnu.org/gnu/mpc/mpc-1.3.1.tar.gz MD5 sum: 5c9bc658c9fd0f940e8e3e0f09530c62
• MPFR (4.2.1) - 1,459 KB: Home page: https://www.mpfr.org/ Download: https://ftp.gnu.org/gnu/mpfr/mpfr-4.2.1.tar.xz MD5 sum: 523c50c6318dde6f9dc523bc0244690a
28
Linux From Scratch - Version 12.1
• Ncurses (6.4-20230520) - 2,156 KB: Home page: https://www.gnu.org/software/ncurses/ Download: https://anduin.linuxfromscratch.org/LFS/ncurses-6.4-20230520.tar.xz MD5 sum: c5367e829b6d9f3f97b280bb3e6bfbc3
• Ninja (1.11.1) - 225 KB: Home page: https://ninja-build.org/ Download: https://github.com/ninja-build/ninja/archive/v1.11.1/ninja-1.11.1.tar.gz MD5 sum: 32151c08211d7ca3c1d832064f6939b0
• OpenSSL (3.2.1) - 17,318 KB: Home page: https://www.openssl.org/ Download: https://www.openssl.org/source/openssl-3.2.1.tar.gz MD5 sum: c239213887804ba00654884918b37441
• Patch (2.7.6) - 766 KB: Home page: https://savannah.gnu.org/projects/patch/ Download: https://ftp.gnu.org/gnu/patch/patch-2.7.6.tar.xz MD5 sum: 78ad9937e4caadcba1526ef1853730d5
• Perl (5.38.2) - 13,359 KB: Home page: https://www.perl.org/ Download: https://www.cpan.org/src/5.0/perl-5.38.2.tar.xz MD5 sum: d3957d75042918a23ec0abac4a2b7e0a
• Pkgconf (2.1.1) - 305 KB: Home page: http://pkgconf.org/ Download: https://distfiles.ariadne.space/pkgconf/pkgconf-2.1.1.tar.xz MD5 sum: bc29d74c2483197deb9f1f3b414b7918
• Procps (4.0.4) - 1,369 KB: Home page: https://gitlab.com/procps-ng/procps/ Download: https://sourceforge.net/projects/procps-ng/files/Production/procps-ng-4.0.4.tar.xz MD5 sum: 2f747fc7df8ccf402d03e375c565cf96
• Psmisc (23.6) - 415 KB: Home page: https://gitlab.com/psmisc/psmisc Download: https://sourceforge.net/projects/psmisc/files/psmisc/psmisc-23.6.tar.xz MD5 sum: ed3206da1184ce9e82d607dc56c52633
• Python (3.12.2) - 20,109 KB: Home page: https://www.python.org/ Download: https://www.python.org/ftp/python/3.12.2/Python-3.12.2.tar.xz MD5 sum: e7c178b97bf8f7ccd677b94d614f7b3c
• Python Documentation (3.12.2) - 8,065 KB: Download: https://www.python.org/ftp/python/doc/3.12.2/python-3.12.2-docs-html.tar.bz2 MD5 sum: 8a6310f6288e7f60c3565277ec3b5279
• Readline (8.2) - 2,973 KB: Home page: https://tiswww.case.edu/php/chet/readline/rltop.html Download: https://ftp.gnu.org/gnu/readline/readline-8.2.tar.gz MD5 sum: 4aa1b31be779e6b84f9a96cb66bc50f6
29
Linux From Scratch - Version 12.1
• Sed (4.9) - 1,365 KB: Home page: https://www.gnu.org/software/sed/ Download: https://ftp.gnu.org/gnu/sed/sed-4.9.tar.xz MD5 sum: 6aac9b2dbafcd5b7a67a8a9bcb8036c3 • Setuptools (69.1.0) - 2,168 KB: Home page: https://pypi.org/project/setuptools/ Download: https://pypi.org/packages/source/s/setuptools/setuptools-69.1.0.tar.gz MD5 sum: 6f6eb780ce12c90d81ce243747ed7ab0 • Shadow (4.14.5) - 1,765 KB: Home page: https://github.com/shadow-maint/shadow/ Download: https://github.com/shadow-maint/shadow/releases/download/4.14.5/shadow-4.14.5.tar.xz MD5 sum: 452b0e59f08bf618482228ba3732d0ae • Sysklogd (1.5.1) - 88 KB: Home page: https://www.infodrom.org/projects/sysklogd/ Download: https://www.infodrom.org/projects/sysklogd/download/sysklogd-1.5.1.tar.gz MD5 sum: c70599ab0d037fde724f7210c2c8d7f8 • Systemd (255) - 14,516 KB: Home page: https://www.freedesktop.org/wiki/Software/systemd/ Download: https://github.com/systemd/systemd/archive/v255/systemd-255.tar.gz MD5 sum: 521cda27409a9edf0370c128fae3e690 • Systemd Man Pages(255) - 652 KB: Home page: https://www.freedesktop.org/wiki/Software/systemd/ Download: https://anduin.linuxfromscratch.org/LFS/systemd-man-pages-255.tar.xz MD5 sum: 1ebe54d7a80f9abf8f2d14ddfeb2432d
Note
The Linux From Scratch team generates its own tarball of the man pages using the systemd source. This is done in order to avoid unnecessary dependencies.
• Sysvinit (3.08) - 263 KB: Home page: https://savannah.nongnu.org/projects/sysvinit Download: https://github.com/slicer69/sysvinit/releases/download/3.08/sysvinit-3.08.tar.xz MD5 sum: 81a05f28d7b67533cfc778fcadea168c • Tar (1.35) - 2,263 KB: Home page: https://www.gnu.org/software/tar/ Download: https://ftp.gnu.org/gnu/tar/tar-1.35.tar.xz MD5 sum: a2d8042658cfd8ea939e6d911eaf4152 • Tcl (8.6.13) - 10,581 KB: Home page: http://tcl.sourceforge.net/ Download: https://downloads.sourceforge.net/tcl/tcl8.6.13-src.tar.gz MD5 sum: 0e4358aade2f5db8a8b6f2f6d9481ec2 • Tcl Documentation (8.6.13) - 1,165 KB: Download: https://downloads.sourceforge.net/tcl/tcl8.6.13-html.tar.gz MD5 sum: 4452f2f6d557f5598cca17b786d6eb68
30
Linux From Scratch - Version 12.1
• Texinfo (7.1) - 5,416 KB: Home page: https://www.gnu.org/software/texinfo/ Download: https://ftp.gnu.org/gnu/texinfo/texinfo-7.1.tar.xz MD5 sum: edd9928b4a3f82674bcc3551616eef3b • Time Zone Data (2024a) - 444 KB: Home page: https://www.iana.org/time-zones Download: https://www.iana.org/time-zones/repository/releases/tzdata2024a.tar.gz MD5 sum: 2349edd8335245525cc082f2755d5bf4 • Udev-lfs Tarball (udev-lfs-20230818) - 10 KB: Download: https://anduin.linuxfromscratch.org/LFS/udev-lfs-20230818.tar.xz MD5 sum: acd4360d8a5c3ef320b9db88d275dae6 • Util-linux (2.39.3) - 8,327 KB: Home page: https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/ Download: https://www.kernel.org/pub/linux/utils/util-linux/v2.39/util-linux-2.39.3.tar.xz MD5 sum: f3591e6970c017bb4bcd24ae762a98f5 • Vim (9.1.0041) - 17,224 KB: Home page: https://www.vim.org Download: https://github.com/vim/vim/archive/v9.1.0041/vim-9.1.0041.tar.gz MD5 sum: 79dfe62be5d347b1325cbd5ce2a1f9b3
Note
The version of vim changes daily. To get the latest version, go to https://github.com/vim/vim/tags.
• Wheel (0.42.0) - 97 KB: Home page: https://pypi.org/project/wheel/ Download: https://pypi.org/packages/source/w/wheel/wheel-0.42.0.tar.gz MD5 sum: 802ad6e5f9336fcb1c76b7593f0cd22d • XML::Parser (2.47) - 276 KB: Home page: https://github.com/chorny/XML-Parser Download: https://cpan.metacpan.org/authors/id/T/TO/TODDR/XML-Parser-2.47.tar.gz MD5 sum: 89a8e82cfd2ad948b349c0a69c494463 • Xz Utils (5.4.6) - 1,645 KB: Home page: https://tukaani.org/xz Download: https://github.com/tukaani-project/xz/releases/download/v5.4.6/xz-5.4.6.tar.xz MD5 sum: 7ade7bd1181a731328f875bec62a9377 • Zlib (1.3.1) - 1,478 KB: Home page: https://zlib.net/ Download: https://zlib.net/fossils/zlib-1.3.1.tar.gz MD5 sum: 9855b6d802d7fe5b7bd5b196a2271655 • Zstd (1.5.5) - 2,314 KB: Home page: https://facebook.github.io/zstd/ Download: https://github.com/facebook/zstd/releases/download/v1.5.5/zstd-1.5.5.tar.gz MD5 sum: 63251602329a106220e0a5ad26ba656f
31
Linux From Scratch - Version 12.1
Total size of these packages: about 504 MB
3.3. Needed Patches
In addition to the packages, several patches are also required. These patches correct any mistakes in the packages that should be fixed by the maintainer. The patches also make small modifications to make the packages easier to work with. The following patches will be needed to build an LFS system: • Bash Upstream Fixes Patch - 5.9 KB: Download: https://www.linuxfromscratch.org/patches/lfs/12.1/bash-5.2.21-upstream_fixes-1.patch MD5 sum: 2d1691a629c558e894dbb78ee6bf34ef • Bzip2 Documentation Patch - 1.6 KB: Download: https://www.linuxfromscratch.org/patches/lfs/12.1/bzip2-1.0.8-install_docs-1.patch MD5 sum: 6a5ac7e89b791aae556de0f745916f7f • Coreutils Internationalization Fixes Patch - 166 KB: Download: https://www.linuxfromscratch.org/patches/lfs/12.1/coreutils-9.4-i18n-1.patch MD5 sum: cca7dc8c73147444e77bc45d210229bb • Glibc FHS Patch - 2.8 KB: Download: https://www.linuxfromscratch.org/patches/lfs/12.1/glibc-2.39-fhs-1.patch MD5 sum: 9a5997c3452909b1769918c759eff8a2 • Kbd Backspace/Delete Fix Patch - 12 KB: Download: https://www.linuxfromscratch.org/patches/lfs/12.1/kbd-2.6.4-backspace-1.patch MD5 sum: f75cca16a38da6caa7d52151f7136895 • Readline Upstream Fix Patch - 13 KB: Download: https://www.linuxfromscratch.org/patches/lfs/12.1/readline-8.2-upstream_fixes-3.patch MD5 sum: 9ed497b6cb8adcb8dbda9dee9ebce791 • Sysvinit Consolidated Patch - 2.5 KB: Download: https://www.linuxfromscratch.org/patches/lfs/12.1/sysvinit-3.08-consolidated-1.patch MD5 sum: 17ffccbb8e18c39e8cedc32046f3a475 Total size of these patches: about 203.8 KB In addition to the above required patches, there exist a number of optional patches created by the LFS community. These optional patches solve minor problems or enable functionality that is not enabled by default. Feel free to peruse the patches database located at https://www.linuxfromscratch.org/patches/downloads/ and acquire any additional patches to suit your system needs.
32
Linux From Scratch - Version 12.1
Chapter 4. Final Preparations
4.1. Introduction
In this chapter, we will perform a few additional tasks to prepare for building the temporary system. We will create a set of directories in $LFS (in which we will install the temporary tools), add an unprivileged user, and create an appropriate build environment for that user. We will also explain the units of time (“SBUs”) we use to measure how long it takes to build LFS packages, and provide some information about package test suites.
4.2. Creating a Limited Directory Layout in the LFS Filesystem
In this section, we begin populating the LFS filesystem with the pieces that will constitute the final Linux system. The first step is to create a limited directory hierarchy, so that the programs compiled in Chapter 6 (as well as glibc and libstdc++ in Chapter 5) can be installed in their final location. We do this so those temporary programs will be overwritten when the final versions are built in Chapter 8. Create the required directory layout by issuing the following commands as root:
mkdir -pv $LFS/{etc,var} $LFS/usr/{bin,lib,sbin}
for i in bin lib sbin; do ln -sv usr/$i $LFS/$i
done
case $(uname -m) in x86_64) mkdir -pv $LFS/lib64 ;;
esac
Programs in Chapter 6 will be compiled with a cross-compiler (more details can be found in section Toolchain Technical Notes). This cross-compiler will be installed in a special directory, to separate it from the other programs. Still acting as root, create that directory with this command:
mkdir -pv $LFS/tools
Note
The LFS editors have deliberately decided not to use a /usr/lib64 directory. Several steps are taken to be sure the toolchain will not use it. If for any reason this directory appears (either because you made an error in following the instructions, or because you installed a binary package that created it after finishing LFS), it may break your system. You should always be sure this directory does not exist.
4.3. Adding the LFS User
When logged in as user root, making a single mistake can damage or destroy a system. Therefore, the packages in the next two chapters are built as an unprivileged user. You could use your own user name, but to make it easier to set up a clean working environment, we will create a new user called lfs as a member of a new group (also named lfs) and run commands as lfs during the installation process. As root, issue the following commands to add the new user:
groupadd lfs useradd -s /bin/bash -g lfs -m -k /dev/null lfs
This is what the command line options mean:
-s /bin/bash
This makes bash the default shell for user lfs.
33
Linux From Scratch - Version 12.1
-g lfs
This option adds user lfs to group lfs.
-m
This creates a home directory for lfs.
-k /dev/null
This parameter prevents possible copying of files from a skeleton directory (the default is /etc/skel) by changing the input location to the special null device.
lfs
This is the name of the new user.
If you want to log in as lfs or switch to lfs from a non-root user (as opposed to switching to user lfs when logged in as root, which does not require the lfs user to have a password), you need to set a password for lfs. Issue the following command as the root user to set the password:
passwd lfs
Grant lfs full access to all the directories under $LFS by making lfs the owner:
chown -v lfs $LFS/{usr{,/*},lib,var,etc,bin,sbin,tools} case $(uname -m) in
x86_64) chown -v lfs $LFS/lib64 ;; esac
Note
In some host systems, the following su command does not complete properly and suspends the login for the lfs user to the background. If the prompt "lfs:~$" does not appear immediately, entering the fg command will fix the issue.
Next, start a shell running as user lfs. This can be done by logging in as lfs on a virtual console, or with the following substitute/switch user command:
su - lfs
The “-” instructs su to start a login shell as opposed to a non-login shell. The difference between these two types of shells is described in detail in bash(1) and info bash.
4.4. Setting Up the Environment
Set up a good working environment by creating two new startup files for the bash shell. While logged in as user lfs, issue the following command to create a new .bash_profile:
cat > ~/.bash_profile << "EOF" exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash EOF
When logged on as user lfs, or when switched to the lfs user using an su command with the “-” option, the initial shell is a login shell which reads the /etc/profile of the host (probably containing some settings and environment variables) and then .bash_profile. The exec env -i.../bin/bash command in the .bash_profile file replaces the running shell with a new one with a completely empty environment, except for the HOME, TERM, and PS1 variables. This ensures that no unwanted and potentially hazardous environment variables from the host system leak into the build environment.
34
Linux From Scratch - Version 12.1
The new instance of the shell is a non-login shell, which does not read, and execute, the contents of the /etc/profile or .bash_profile files, but rather reads, and executes, the .bashrc file instead. Create the .bashrc file now:
cat > ~/.bashrc << "EOF" set +h umask 022 LFS=/mnt/lfs LC_ALL=POSIX LFS_TGT=$(uname -m)-lfs-linux-gnu PATH=/usr/bin if [ ! -L /bin ]; then PATH=/bin:$PATH; fi PATH=$LFS/tools/bin:$PATH CONFIG_SITE=$LFS/usr/share/config.site export LFS LC_ALL LFS_TGT PATH CONFIG_SITE EOF
The meaning of the settings in .bashrc
set +h
The set +h command turns off bash's hash function. Hashing is ordinarily a useful feature—bash uses a hash table to remember the full path to executable files to avoid searching the PATH time and again to find the same executable. However, the new tools should be used as soon as they are installed. Switching off the hash function forces the shell to search the PATH whenever a program is to be run. As such, the shell will find the newly compiled tools in $LFS/tools/bin as soon as they are available without remembering a previous version of the same program provided by the host distro, in /usr/bin or /bin.
umask 022
Setting the user file-creation mask (umask) to 022 ensures that newly created files and directories are only writable by their owner, but are readable and executable by anyone (assuming default modes are used by the open(2) system call, new files will end up with permission mode 644 and directories with mode 755).
LFS=/mnt/lfs
The LFS variable should be set to the chosen mount point.
LC_ALL=POSIX
The LC_ALL variable controls the localization of certain programs, making their messages follow the conventions of a specified country. Setting LC_ALL to “POSIX” or “C” (the two are equivalent) ensures that everything will work as expected in the cross-compilation environment.
LFS_TGT=$(uname -m)-lfs-linux-gnu
The LFS_TGT variable sets a non-default, but compatible machine description for use when building our crosscompiler and linker and when cross-compiling our temporary toolchain. More information is provided by Toolchain Technical Notes.
PATH=/usr/bin
Many modern Linux distributions have merged /bin and /usr/bin. When this is the case, the standard PATH variable should be set to /usr/bin/ for the Chapter 6 environment. When this is not the case, the following line adds / bin to the path.
if [ ! -L /bin ]; then PATH=/bin:$PATH; fi
If /bin is not a symbolic link, it must be added to the PATH variable.
PATH=$LFS/tools/bin:$PATH
By putting $LFS/tools/bin ahead of the standard PATH, the cross-compiler installed at the beginning of Chapter 5 is picked up by the shell immediately after its installation. This, combined with turning off hashing, limits the risk that the compiler from the host is used instead of the cross-compiler.
35
Linux From Scratch - Version 12.1
CONFIG_SITE=$LFS/usr/share/config.site
In Chapter 5 and Chapter 6, if this variable is not set, configure scripts may attempt to load configuration items specific to some distributions from /usr/share/config.site on the host system. Override it to prevent potential contamination from the host.
export ...
While the preceding commands have set some variables, in order to make them visible within any sub-shells, we export them.
Important
Several commercial distributions add an undocumented instantiation of /etc/bash.bashrc to the initialization of bash. This file has the potential to modify the lfs user's environment in ways that can affect the building of critical LFS packages. To make sure the lfs user's environment is clean, check for the presence of /etc/ bash.bashrc and, if present, move it out of the way. As the root user, run:
[ ! -e /etc/bash.bashrc ] || mv -v /etc/bash.bashrc /etc/bash.bashrc.NOUSE
When the lfs user is no longer needed (at the beginning of Chapter 7), you may safely restore /etc/bash. bashrc (if desired).
Note that the LFS Bash package we will build in Section 8.35, “Bash-5.2.21” is not configured to load or execute /etc/bash.bashrc, so this file is useless on a completed LFS system.
For many modern systems with multiple processors (or cores) the compilation time for a package can be reduced by performing a "parallel make" by telling the make program how many processors are available via a command line option or an environment variable. For instance, an Intel Core i9-13900K processor has 8 P (performance) cores and 16 E (efficiency) cores, and a P core can simultaneously run two threads so each P core are modeled as two logical cores by the Linux kernel. As the result there are 32 logical cores in total. One obvious way to use all these logical cores is allowing make to spawn up to 32 build jobs. This can be done by passing the -j32 option to make:
make -j32
Or set the MAKEFLAGS environment variable and its content will be automatically used by make as command line options:
export MAKEFLAGS=-j32
Important
Never pass a -j option without a number to make or set such an option in MAKEFLAGS. Doing so will allow make to spawn infinite build jobs and cause system stability problems.
To use all logical cores available for building packages in Chapter 5 and Chapter 6, set MAKEFLAGS now in .bashrc:
cat >> ~/.bashrc << "EOF" export MAKEFLAGS=-j$(nproc) EOF
Replace $(nproc) with the number of logical cores you want to use if you don't want to use all the logical cores.
Finally, to ensure the environment is fully prepared for building the temporary tools, force the bash shell to read the new user profile:
source ~/.bash_profile
36
Linux From Scratch - Version 12.1
4.5. About SBUs
Many people would like to know beforehand approximately how long it takes to compile and install each package. Because Linux From Scratch can be built on many different systems, it is impossible to provide absolute time estimates. The biggest package (gcc) will take approximately 5 minutes on the fastest systems, but could take days on slower systems! Instead of providing actual times, the Standard Build Unit (SBU) measure will be used instead.
The SBU measure works as follows. The first package to be compiled is binutils in Chapter 5. The time it takes to compile using one core is what we will refer to as the Standard Build Unit or SBU. All other compile times will be expressed in terms of this unit of time.
For example, consider a package whose compilation time is 4.5 SBUs. This means that if your system took 10 minutes to compile and install the first pass of binutils, it will take approximately 45 minutes to build the example package. Fortunately, most build times are shorter than one SBU.
SBUs are not entirely accurate because they depend on many factors, including the host system's version of GCC. They are provided here to give an estimate of how long it might take to install a package, but the numbers can vary by as much as dozens of minutes in some cases.
Note
When multiple processors are used in this way, the SBU units in the book will vary even more than they normally would. In some cases, the make step will simply fail. Analyzing the output of the build process will also be more difficult because the lines from different processes will be interleaved. If you run into a problem with a build step, revert to a single processor build to properly analyze the error messages.
The times presented here are based upon using four cores (-j4). The times in Chapter 8 also include the time to run the regression tests for the package unless specified otherwise.
4.6. About the Test Suites
Most packages provide a test suite. Running the test suite for a newly built package is a good idea because it can provide a “sanity check” indicating that everything compiled correctly. A test suite that passes its set of checks usually proves that the package is functioning as the developer intended. It does not, however, guarantee that the package is totally bug free.
Some test suites are more important than others. For example, the test suites for the core toolchain packages—GCC, binutils, and glibc—are of the utmost importance due to their central role in a properly functioning system. The test suites for GCC and glibc can take a very long time to complete, especially on slower hardware, but are strongly recommended.
Note
Running the test suites in Chapter 5 and Chapter 6 is pointless; since the test programs are compiled with a cross-compiler, they probably can't run on the build host.
A common issue with running the test suites for binutils and GCC is running out of pseudo terminals (PTYs). This can result in a large number of failing tests. This may happen for several reasons, but the most likely cause is that the host system does not have the devpts file system set up correctly. This issue is discussed in greater detail at https://www. linuxfromscratch.org/lfs/faq.html#no-ptys.
37
Linux From Scratch - Version 12.1 Sometimes package test suites will fail for reasons which the developers are aware of and have deemed non-critical. Consult the logs located at https://www.linuxfromscratch.org/lfs/build-logs/12.1/ to verify whether or not these failures are expected. This site is valid for all test suites throughout this book.
38
Linux From Scratch - Version 12.1
Part III. Building the LFS Cross Toolchain and Temporary Tools
Linux From Scratch - Version 12.1
Important Preliminary Material
Introduction
This part is divided into three stages: first, building a cross compiler and its associated libraries; second, using this cross toolchain to build several utilities in a way that isolates them from the host distribution; and third, entering the chroot environment (which further improves host isolation) and constructing the remaining tools needed to build the final system.
Important
This is where the real work of building a new system begins. Be very careful to follow the instructions exactly as the book shows them. You should try to understand what each command does, and no matter how eager you are to finish your build, you should refrain from blindly typing the commands as shown. Read the documentation when there is something you do not understand. Also, keep track of your typing and of the output of commands, by using the tee utility to send the terminal output to a file. This makes debugging easier if something goes wrong.
The next section is a technical introduction to the build process, while the following one presents very important general instructions.
Toolchain Technical Notes
This section explains some of the rationale and technical details behind the overall build method. Don't try to immediately understand everything in this section. Most of this information will be clearer after performing an actual build. Come back and re-read this chapter at any time during the build process. The overall goal of Chapter 5 and Chapter 6 is to produce a temporary area containing a set of tools that are known to be good, and that are isolated from the host system. By using the chroot command, the compilations in the remaining chapters will be isolated within that environment, ensuring a clean, trouble-free build of the target LFS system. The build process has been designed to minimize the risks for new readers, and to provide the most educational value at the same time. This build process is based on cross-compilation. Cross-compilation is normally used to build a compiler and its associated toolchain for a machine different from the one that is used for the build. This is not strictly necessary for LFS, since the machine where the new system will run is the same as the one used for the build. But cross-compilation has one great advantage: anything that is cross-compiled cannot depend on the host environment.
About Cross-Compilation
Note
The LFS book is not (and does not contain) a general tutorial to build a cross- (or native) toolchain. Don't use the commands in the book for a cross-toolchain for some purpose other than building LFS, unless you really understand what you are doing.
Cross-compilation involves some concepts that deserve a section of their own. Although this section may be omitted on a first reading, coming back to it later will help you gain a fuller understanding of the process. Let us first define some terms used in this context.
40
Linux From Scratch - Version 12.1
The build is the machine where we build programs. Note that this machine is also referred to as the “host.”
The host is the machine/system where the built programs will run. Note that this use of “host” is not the same as in other sections.
The target is only used for compilers. It is the machine the compiler produces code for. It may be different from both the build and the host.
As an example, let us imagine the following scenario (sometimes referred to as “Canadian Cross”). We have a compiler on a slow machine only, let's call it machine A, and the compiler ccA. We also have a fast machine (B), but no compiler for (B), and we want to produce code for a third, slow machine (C). We will build a compiler for machine C in three stages.
Stage 1
2
3
Build A
A
B
Host A
B
C
Target B
C
C
Action
Build crosscompiler cc1 using ccA on machine A.
Build crosscompiler cc2 using cc1 on machine A.
Build compiler ccC using cc2 on machine B.
Then, all the programs needed by machine C can be compiled using cc2 on the fast machine B. Note that unless B can run programs produced for C, there is no way to test the newly built programs until machine C itself is running. For example, to run a test suite on ccC, we may want to add a fourth stage:
Stage 4
Build C
Host C
Target C
Action
Rebuild and test ccC using ccC on machine C.
41
Linux From Scratch - Version 12.1
In the example above, only cc1 and cc2 are cross-compilers, that is, they produce code for a machine different from the one they are run on. The other compilers ccA and ccC produce code for the machine they are run on. Such compilers are called native compilers.
Implementation of Cross-Compilation for LFS
Note
All the cross-compiled packages in this book use an autoconf-based building system. The autoconf-based building system accepts system types in the form cpu-vendor-kernel-os, referred to as the system triplet. Since the vendor field is often irrelevant, autoconf lets you omit it.
An astute reader may wonder why a “triplet” refers to a four component name. The kernel field and the os field began as a single “system” field. Such a three-field form is still valid today for some systems, for example, x86_64-unknown-freebsd. But two systems can share the same kernel and still be too different to use the same triplet to describe them. For example, Android running on a mobile phone is completely different from Ubuntu running on an ARM64 server, even though they are both running on the same type of CPU (ARM64) and using the same kernel (Linux).
Without an emulation layer, you cannot run an executable for a server on a mobile phone or vice versa. So the “system” field has been divided into kernel and os fields, to designate these systems unambiguously. In our example, the Android system is designated aarch64-unknown-linux-android, and the Ubuntu system is designated aarch64-unknown-linux-gnu.
The word “triplet” remains embedded in the lexicon. A simple way to determine your system triplet is to run the config.guess script that comes with the source for many packages. Unpack the binutils sources, run the script ./config.guess, and note the output. For example, for a 32-bit Intel processor the output will be i686pc-linux-gnu. On a 64-bit system it will be x86_64-pc-linux-gnu. On most Linux systems the even simpler gcc -dumpmachine command will give you similar information.
You should also be aware of the name of the platform's dynamic linker, often referred to as the dynamic loader (not to be confused with the standard linker ld that is part of binutils). The dynamic linker provided by package glibc finds and loads the shared libraries needed by a program, prepares the program to run, and then runs it. The name of the dynamic linker for a 32-bit Intel machine is ld-linux.so.2; it's ld-linux-x86-64.so.2 on 64bit systems. A sure-fire way to determine the name of the dynamic linker is to inspect a random binary from the host system by running: readelf -l <name of binary> | grep interpreter and noting the output. The authoritative reference covering all platforms is in the shlib-versions file in the root of the glibc source tree.
In order to fake a cross-compilation in LFS, the name of the host triplet is slightly adjusted by changing the "vendor" field in the LFS_TGT variable so it says "lfs". We also use the --with-sysroot option when building the cross-linker and cross-compiler, to tell them where to find the needed host files. This ensures that none of the other programs built in Chapter 6 can link to libraries on the build machine. Only two stages are mandatory, plus one more for tests.
Stage 1
Build pc
Host pc
Target lfs
Action
Build crosscompiler cc1 using cc-pc on pc.
42
Linux From Scratch - Version 12.1
Stage 2
3
Build pc
lfs
Host lfs
lfs
Target lfs
lfs
Action
Build compiler cc-lfs using cc1 on pc.
Rebuild and test cc-lfs using cclfs on lfs.
In the preceding table, “on pc” means the commands are run on a machine using the already installed distribution. “On lfs” means the commands are run in a chrooted environment.
This is not yet the end of the story. The C language is not merely a compiler; it also defines a standard library. In this book, the GNU C library, named glibc, is used (there is an alternative, "musl"). This library must be compiled for the LFS machine; that is, using the cross-compiler cc1. But the compiler itself uses an internal library providing complex subroutines for functions not available in the assembler instruction set. This internal library is named libgcc, and it must be linked to the glibc library to be fully functional. Furthermore, the standard library for C++ (libstdc++) must also be linked with glibc. The solution to this chicken and egg problem is first to build a degraded cc1-based libgcc, lacking some functionalities such as threads and exception handling, and then to build glibc using this degraded compiler (glibc itself is not degraded), and also to build libstdc++. This last library will lack some of the functionality of libgcc.
The upshot of the preceding paragraph is that cc1 is unable to build a fully functional libstdc++ with the degraded libgcc, but cc1 is the only compiler available for building the C/C++ libraries during stage 2. There are two reasons we don't immediately use the compiler built in stage 2, cc-lfs, to build those libraries.
• Generally speaking, cc-lfs cannot run on pc (the host system). Even though the triplets for pc and lfs are compatible with each other, an executable for lfs must depend on glibc-2.39; the host distro may utilize either a different implementation of libc (for example, musl), or a previous release of glibc (for example, glibc-2.13).
• Even if cc-lfs can run on pc, using it on pc would create a risk of linking to the pc libraries, since cc-lfs is a native compiler.
So when we build gcc stage 2, we instruct the building system to rebuild libgcc and libstdc++ with cc1, but we link libstdc++ to the newly rebuilt libgcc instead of the old, degraded build. This makes the rebuilt libstdc++ fully functional.
In Chapter 8 (or “stage 3”), all the packages needed for the LFS system are built. Even if a package has already been installed into the LFS system in a previous chapter, we still rebuild the package. The main reason for rebuilding these packages is to make them stable: if we reinstall an LFS package on a completed LFS system, the reinstalled content of the package should be the same as the content of the same package when first installed in Chapter 8. The temporary packages installed in Chapter 6 or Chapter 7 cannot satisfy this requirement, because some of them are built without optional dependencies, and autoconf cannot perform some feature checks in Chapter 6 because of cross-compilation, causing the temporary packages to lack optional features, or use suboptimal code routines. Additionally, a minor reason for rebuilding the packages is to run the test suites.
Other Procedural Details
The cross-compiler will be installed in a separate $LFS/tools directory, since it will not be part of the final system.
43
Linux From Scratch - Version 12.1
Binutils is installed first because the configure runs of both gcc and glibc perform various feature tests on the assembler and linker to determine which software features to enable or disable. This is more important than one might realize at first. An incorrectly configured gcc or glibc can result in a subtly broken toolchain, where the impact of such breakage might not show up until near the end of the build of an entire distribution. A test suite failure will usually highlight this error before too much additional work is performed.
Binutils installs its assembler and linker in two locations, $LFS/tools/bin and $LFS/tools/$LFS_TGT/bin. The tools in one location are hard linked to the other. An important facet of the linker is its library search order. Detailed information can be obtained from ld by passing it the --verbose flag. For example, $LFS_TGT-ld --verbose | grep SEARCH will illustrate the current search paths and their order. (Note that this example can be run as shown only while logged in as user lfs. If you come back to this page later, replace $LFS_TGT-ld with ld).
The next package installed is gcc. An example of what can be seen during its run of configure is:
checking what assembler to use... /mnt/lfs/tools/i686-lfs-linux-gnu/bin/as checking what linker to use... /mnt/lfs/tools/i686-lfs-linux-gnu/bin/ld
This is important for the reasons mentioned above. It also demonstrates that gcc's configure script does not search the PATH directories to find which tools to use. However, during the actual operation of gcc itself, the same search paths are not necessarily used. To find out which standard linker gcc will use, run: $LFS_TGT-gcc -print-prog-name=ld. (Again, remove the $LFS_TGT- prefix if coming back to this later.)
Detailed information can be obtained from gcc by passing it the -v command line option while compiling a program. For example, $LFS_TGT-gcc -v example.c (or without $LFS_TGT- if coming back later) will show detailed information about the preprocessor, compilation, and assembly stages, including gcc's search paths for included headers and their order.
Next up: sanitized Linux API headers. These allow the standard C library (glibc) to interface with features that the Linux kernel will provide.
Next comes glibc. The most important considerations for building glibc are the compiler, binary tools, and kernel headers. The compiler is generally not an issue since glibc will always use the compiler relating to the --host parameter passed to its configure script; e.g., in our case, the compiler will be $LFS_TGT-gcc. The binary tools and kernel headers can be a bit more complicated. Therefore, we take no risks and use the available configure switches to enforce the correct selections. After the run of configure, check the contents of the config.make file in the build directory for all important details. Note the use of CC="$LFS_TGT-gcc" (with $LFS_TGT expanded) to control which binary tools are used and the use of the -nostdinc and -isystem flags to control the compiler's include search path. These items highlight an important aspect of the glibc package—it is very self-sufficient in terms of its build machinery, and generally does not rely on toolchain defaults.
As mentioned above, the standard C++ library is compiled next, followed in Chapter 6 by other programs that must be cross-compiled to break circular dependencies at build time. The install step of all those packages uses the DESTDIR variable to force installation in the LFS filesystem.
At the end of Chapter 6 the native LFS compiler is installed. First binutils-pass2 is built, in the same DESTDIR directory as the other programs, then the second pass of gcc is constructed, omitting some non-critical libraries. Due to some weird logic in gcc's configure script, CC_FOR_TARGET ends up as cc when the host is the same as the target, but different from the build system. This is why CC_FOR_TARGET=$LFS_TGT-gcc is declared explicitly as one of the configuration options.
Upon entering the chroot environment in Chapter 7, the temporary installations of programs needed for the proper operation of the toolchain are performed. From this point onwards, the core toolchain is self-contained and self-hosted. In Chapter 8, final versions of all the packages needed for a fully functional system are built, tested, and installed.
44
General Compilation Instructions
Linux From Scratch - Version 12.1
Caution
During a development cycle of LFS, the instructions in the book are often modified to adapt for a package update or take the advantage of new features from updated packages. Mixing up the instructions of different versions of the LFS book can cause subtle breakages. This kind of issue is generally a result from reusing some script created for a prior LFS release. Such a reuse is strongly discouraged. If you are reusing scripts for a prior LFS release for any reason, you'll need to be very careful to update the scripts to match current version of the LFS book.
Here are some things you should know about building each package:
• Several packages are patched before compilation, but only when the patch is needed to circumvent a problem. A patch is often needed in both the current and the following chapters, but sometimes, when the same package is built more than once, the patch is not needed right away. Therefore, do not be concerned if instructions for a downloaded patch seem to be missing. Warning messages about offset or fuzz may also be encountered when applying a patch. Do not worry about these warnings; the patch was still successfully applied.
• During the compilation of most packages, some warnings will scroll by on the screen. These are normal and can safely be ignored. These warnings are usually about deprecated, but not invalid, use of the C or C++ syntax. C standards change fairly often, and some packages have not yet been updated. This is not a serious problem, but it does cause the warnings to appear.
• Check one last time that the LFS environment variable is set up properly:
echo $LFS
Make sure the output shows the path to the LFS partition's mount point, which is /mnt/lfs, using our example.
• Finally, two important items must be emphasized:
Important
The build instructions assume that the Host System Requirements, including symbolic links, have been set properly:
• bash is the shell in use.
• sh is a symbolic link to bash.
• /usr/bin/awk is a symbolic link to gawk.
• /usr/bin/yacc is a symbolic link to bison, or to a small script that executes bison.
45
Linux From Scratch - Version 12.1
Important
Here is a synopsis of the build process. 1. Place all the sources and patches in a directory that will be accessible from the chroot environment,
such as /mnt/lfs/sources/. 2. Change to the /mnt/lfs/sources/ directory. 3. For each package:
a. Using the tar program, extract the package to be built. In Chapter 5 and Chapter 6, ensure you are the lfs user when extracting the package. Do not use any method except the tar command to extract the source code. Notably, using the cp R command to copy the source code tree somewhere else can destroy links and timestamps in the source tree, and cause the build to fail.
b. Change to the directory created when the package was extracted. c. Follow the instructions for building the package. d. Change back to the sources directory when the build is complete. e. Delete the extracted source directory unless instructed otherwise.
46
Linux From Scratch - Version 12.1
Chapter 5. Compiling a Cross-Toolchain
5.1. Introduction
This chapter shows how to build a cross-compiler and its associated tools. Although here cross-compilation is faked, the principles are the same as for a real cross-toolchain. The programs compiled in this chapter will be installed under the $LFS/tools directory to keep them separate from the files installed in the following chapters. The libraries, on the other hand, are installed into their final place, since they pertain to the system we want to build.
47
Linux From Scratch - Version 12.1
5.2. Binutils-2.42 - Pass 1
The Binutils package contains a linker, an assembler, and other tools for handling object files.
Approximate build time: 1 SBU
Required disk space:
663 MB
5.2.1. Installation of Cross Binutils
Note
Go back and re-read the notes in the section titled General Compilation Instructions. Understanding the notes labeled important can save you a lot of problems later.
It is important that Binutils be the first package compiled because both Glibc and GCC perform various tests on the available linker and assembler to determine which of their own features to enable.
The Binutils documentation recommends building Binutils in a dedicated build directory:
mkdir -v build
cd
build
Note
In order for the SBU values listed in the rest of the book to be of any use, measure the time it takes to build this package from the configuration, up to and including the first install. To achieve this easily, wrap the commands in a time command like this: time { ../configure ... && make && make install; }.
Now prepare Binutils for compilation:
../configure --prefix=$LFS/tools \
--with-sysroot=$LFS \
--target=$LFS_TGT \
--disable-nls
\
--enable-gprofng=no \
--disable-werror \
--enable-default-hash-style=gnu
The meaning of the configure options:
--prefix=$LFS/tools
This tells the configure script to prepare to install the Binutils programs in the $LFS/tools directory.
--with-sysroot=$LFS
For cross compilation, this tells the build system to look in $LFS for the target system libraries as needed.
--target=$LFS_TGT
Because the machine description in the LFS_TGT variable is slightly different than the value returned by the config.guess script, this switch will tell the configure script to adjust binutil's build system for building a cross linker.
--disable-nls
This disables internationalization as i18n is not needed for the temporary tools.
--enable-gprofng=no
This disables building gprofng which is not needed for the temporary tools.
48
Linux From Scratch - Version 12.1
--disable-werror
This prevents the build from stopping in the event that there are warnings from the host's compiler.
--enable-default-hash-style=gnu
By default, the linker would generate both the GNU-style hash table and the classic ELF hash table for shared libraries and dynamically linked executables. The hash tables are only intended for a dynamic linker to perform symbol lookup. On LFS the dynamic linker (provided by the Glibc package) will always use the GNU-style hash table which is faster to query. So the classic ELF hash table is completely useless. This makes the linker only generate the GNU-style hash table by default, so we can avoid wasting time to generate the classic ELF hash table when we build the packages, or wasting disk space to store it. Continue with compiling the package:
make
Install the package:
make install
Details on this package are located in Section 8.19.2, “Contents of Binutils.”
49
Linux From Scratch - Version 12.1
5.3. GCC-13.2.0 - Pass 1
The GCC package contains the GNU compiler collection, which includes the C and C++ compilers.
Approximate build time: 3.8 SBU
Required disk space:
4.1 GB
5.3.1. Installation of Cross GCC
GCC requires the GMP, MPFR and MPC packages. As these packages may not be included in your host distribution, they will be built with GCC. Unpack each package into the GCC source directory and rename the resulting directories so the GCC build procedures will automatically use them:
Note
There are frequent misunderstandings about this chapter. The procedures are the same as every other chapter, as explained earlier (Package build instructions). First, extract the gcc-13.2.0 tarball from the sources directory, and then change to the directory created. Only then should you proceed with the instructions below.
tar -xf ../mpfr-4.2.1.tar.xz mv -v mpfr-4.2.1 mpfr tar -xf ../gmp-6.3.0.tar.xz mv -v gmp-6.3.0 gmp tar -xf ../mpc-1.3.1.tar.gz mv -v mpc-1.3.1 mpc
On x86_64 hosts, set the default directory name for 64-bit libraries to “lib”:
case $(uname -m) in x86_64) sed -e '/m64=/s/lib64/lib/' \ -i.orig gcc/config/i386/t-linux64
;; esac
The GCC documentation recommends building GCC in a dedicated build directory:
mkdir -v build
cd
build
50
Linux From Scratch - Version 12.1
Prepare GCC for compilation:
../configure
\
--target=$LFS_TGT
\
--prefix=$LFS/tools
\
--with-glibc-version=2.39 \
--with-sysroot=$LFS
\
--with-newlib
\
--without-headers
\
--enable-default-pie
\
--enable-default-ssp
\
--disable-nls
\
--disable-shared
\
--disable-multilib
\
--disable-threads
\
--disable-libatomic
\
--disable-libgomp
\
--disable-libquadmath
\
--disable-libssp
\
--disable-libvtv
\
--disable-libstdcxx
\
--enable-languages=c,c++
The meaning of the configure options:
--with-glibc-version=2.39
This option specifies the version of Glibc which will be used on the target. It is not relevant to the libc of the host distro because everything compiled by pass1 GCC will run in the chroot environment, which is isolated from libc of the host distro.
--with-newlib
Since a working C library is not yet available, this ensures that the inhibit_libc constant is defined when building libgcc. This prevents the compiling of any code that requires libc support.
--without-headers
When creating a complete cross-compiler, GCC requires standard headers compatible with the target system. For our purposes these headers will not be needed. This switch prevents GCC from looking for them.
--enable-default-pie and --enable-default-ssp
Those switches allow GCC to compile programs with some hardening security features (more information on those in the note on PIE and SSP in chapter 8) by default. The are not strictly needed at this stage, since the compiler will only produce temporary executables. But it is cleaner to have the temporary packages be as close as possible to the final ones.
--disable-shared
This switch forces GCC to link its internal libraries statically. We need this because the shared libraries require Glibc, which is not yet installed on the target system.
--disable-multilib
On x86_64, LFS does not support a multilib configuration. This switch is harmless for x86.
--disable-threads, --disable-libatomic, --disable-libgomp, --disable-libquadmath, --disable-libssp, --
disable-libvtv, --disable-libstdcxx
These switches disable support for threading, libatomic, libgomp, libquadmath, libssp, libvtv, and the C++ standard library respectively. These features may fail to compile when building a cross-compiler and are not necessary for the task of cross-compiling the temporary libc.
--enable-languages=c,c++
This option ensures that only the C and C++ compilers are built. These are the only languages needed now.
51
Linux From Scratch - Version 12.1 Compile GCC by running:
make
Install the package:
make install
This build of GCC has installed a couple of internal system headers. Normally one of them, limits.h, would in turn include the corresponding system limits.h header, in this case, $LFS/usr/include/limits.h. However, at the time of this build of GCC $LFS/usr/include/limits.h does not exist, so the internal header that has just been installed is a partial, self-contained file and does not include the extended features of the system header. This is adequate for building Glibc, but the full internal header will be needed later. Create a full version of the internal header using a command that is identical to what the GCC build system does in normal circumstances:
Note
The command below shows an example of nested command substitution using two methods: backquotes and a $() construct. It could be rewritten using the same method for both substitutions, but is shown this way to demonstrate how they can be mixed. Generally the $() method is preferred.
cd .. cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
`dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/include/limits.h
Details on this package are located in Section 8.28.2, “Contents of GCC.”
52
Linux From Scratch - Version 12.1
5.4. Linux-6.7.4 API Headers
The Linux API Headers (in linux-6.7.4.tar.xz) expose the kernel's API for use by Glibc.
Approximate build time: less than 0.1 SBU
Required disk space:
1.5 GB
5.4.1. Installation of Linux API Headers
The Linux kernel needs to expose an Application Programming Interface (API) for the system's C library (Glibc in LFS) to use. This is done by way of sanitizing various C header files that are shipped in the Linux kernel source tarball.
Make sure there are no stale files embedded in the package:
make mrproper
Now extract the user-visible kernel headers from the source. The recommended make target “headers_install” cannot be used, because it requires rsync, which may not be available. The headers are first placed in ./usr, then copied to the needed location.
make headers find usr/include -type f ! -name '*.h' -delete cp -rv usr/include $LFS/usr
5.4.2. Contents of Linux API Headers
Installed headers: Installed directories:
/usr/include/asm/*.h, /usr/include/asm-generic/*.h, /usr/include/drm/*.h, /usr/include/ linux/*.h, /usr/include/misc/*.h, /usr/include/mtd/*.h, /usr/include/rdma/*.h, /usr/ include/scsi/*.h, /usr/include/sound/*.h, /usr/include/video/*.h, and /usr/include/xen/*.h /usr/include/asm, /usr/include/asm-generic, /usr/include/drm, /usr/include/linux, /usr/ include/misc, /usr/include/mtd, /usr/include/rdma, /usr/include/scsi, /usr/include/sound, / usr/include/video, and /usr/include/xen
Short Descriptions
/usr/include/asm/*.h /usr/include/asm-generic/*.h /usr/include/drm/*.h /usr/include/linux/*.h /usr/include/misc/*.h /usr/include/mtd/*.h /usr/include/rdma/*.h /usr/include/scsi/*.h /usr/include/sound/*.h /usr/include/video/*.h /usr/include/xen/*.h
The Linux API ASM Headers The Linux API ASM Generic Headers The Linux API DRM Headers The Linux API Linux Headers The Linux API Miscellaneous Headers The Linux API MTD Headers The Linux API RDMA Headers The Linux API SCSI Headers The Linux API Sound Headers The Linux API Video Headers The Linux API Xen Headers
53
Linux From Scratch - Version 12.1
5.5. Glibc-2.39
The Glibc package contains the main C library. This library provides the basic routines for allocating memory, searching directories, opening and closing files, reading and writing files, string handling, pattern matching, arithmetic, and so on.
Approximate build time: 1.5 SBU
Required disk space:
846 MB
5.5.1. Installation of Glibc
First, create a symbolic link for LSB compliance. Additionally, for x86_64, create a compatibility symbolic link required for proper operation of the dynamic library loader:
case $(uname -m) in i?86) ln -sfv ld-linux.so.2 $LFS/lib/ld-lsb.so.3 ;; x86_64) ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64 ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64/ld-lsb-x86-64.so.3 ;;
esac
Note
The above command is correct. The ln command has several syntactic versions, so be sure to check info coreutils ln and ln(1) before reporting what may appear to be an error.
Some of the Glibc programs use the non-FHS-compliant /var/db directory to store their runtime data. Apply the following patch to make such programs store their runtime data in the FHS-compliant locations:
patch -Np1 -i ../glibc-2.39-fhs-1.patch
The Glibc documentation recommends building Glibc in a dedicated build directory:
mkdir -v build
cd
build
Ensure that the ldconfig and sln utilities are installed into /usr/sbin:
echo "rootsbindir=/usr/sbin" > configparms
Next, prepare Glibc for compilation:
../configure
\
--prefix=/usr
\
--host=$LFS_TGT
\
--build=$(../scripts/config.guess) \
--enable-kernel=4.19
\
--with-headers=$LFS/usr/include \
--disable-nscd
\
libc_cv_slibdir=/usr/lib
The meaning of the configure options:
--host=$LFS_TGT, --build=$(../scripts/config.guess)
The combined effect of these switches is that Glibc's build system configures itself to be cross-compiled, using the cross-linker and cross-compiler in $LFS/tools.
54
Linux From Scratch - Version 12.1
--enable-kernel=4.19
This tells Glibc to compile the library with support for 4.19 and later Linux kernels. Workarounds for older kernels are not enabled.
--with-headers=$LFS/usr/include
This tells Glibc to compile itself against the headers recently installed to the $LFS/usr/include directory, so that it knows exactly what features the kernel has and can optimize itself accordingly.
libc_cv_slibdir=/usr/lib
This ensures that the library is installed in /usr/lib instead of the default /lib64 on 64-bit machines.
--disable-nscd
Do not build the name service cache daemon which is no longer used. During this stage the following warning might appear:
configure: WARNING: *** These auxiliary programs are missing or *** incompatible versions: msgfmt *** some features will be disabled. *** Check the INSTALL file for required versions.
The missing or incompatible msgfmt program is generally harmless. This msgfmt program is part of the Gettext package, which the host distribution should provide.
Note
There have been reports that this package may fail when building as a “parallel make.” If that occurs, rerun the make command with the -j1 option.
Compile the package:
make
Install the package:
Warning
If LFS is not properly set, and despite the recommendations, you are building as root, the next command will install the newly built Glibc to your host system, which will almost certainly render it unusable. So doublecheck that the environment is correctly set, and that you are not root, before running the following command.
make DESTDIR=$LFS install
The meaning of the make install option:
DESTDIR=$LFS
The DESTDIR make variable is used by almost all packages to define the location where the package should be installed. If it is not set, it defaults to the root (/) directory. Here we specify that the package is installed in $LFS , which will become the root directory in Section 7.4, “Entering the Chroot Environment”. Fix a hard coded path to the executable loader in the ldd script:
sed '/RTLDLIST=/s@/usr@@g' -i $LFS/usr/bin/ldd
55
Linux From Scratch - Version 12.1
Caution
At this point, it is imperative to stop and ensure that the basic functions (compiling and linking) of the new toolchain are working as expected. To perform a sanity check, run the following commands:
echo 'int main(){}' | $LFS_TGT-gcc -xc readelf -l a.out | grep ld-linux
If everything is working correctly, there should be no errors, and the output of the last command will be of the form:
[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
Note that for 32-bit machines, the interpreter name will be /lib/ld-linux.so.2. If the output is not as shown above, or there is no output at all, then something is wrong. Investigate and retrace the steps to find out where the problem is and correct it. This issue must be resolved before continuing. Once all is well, clean up the test file:
rm -v a.out
Note
Building the packages in the next chapter will serve as an additional check that the toolchain has been built properly. If some package, especially Binutils-pass2 or GCC-pass2, fails to build, it is an indication that something has gone wrong with the preceding Binutils, GCC, or Glibc installations. Details on this package are located in Section 8.5.3, “Contents of Glibc.”
56
Linux From Scratch - Version 12.1
5.6. Libstdc++ from GCC-13.2.0
Libstdc++ is the standard C++ library. It is needed to compile C++ code (part of GCC is written in C++), but we had to defer its installation when we built gcc-pass1 because Libstdc++ depends on Glibc, which was not yet available in the target directory.
Approximate build time: 0.2 SBU
Required disk space:
1.1 GB
5.6.1. Installation of Target Libstdc++
Note
Libstdc++ is part of the GCC sources. You should first unpack the GCC tarball and change to the gcc-13. 2.0 directory.
Create a separate build directory for Libstdc++ and enter it:
mkdir -v build
cd
build
Prepare Libstdc++ for compilation:
../libstdc++-v3/configure
\
--host=$LFS_TGT
\
--build=$(../config.guess)
\
--prefix=/usr
\
--disable-multilib
\
--disable-nls
\
--disable-libstdcxx-pch
\
--with-gxx-include-dir=/tools/$LFS_TGT/include/c++/13.2.0
The meaning of the configure options:
--host=...
Specifies that the cross-compiler we have just built should be used instead of the one in /usr/bin.
--disable-libstdcxx-pch
This switch prevents the installation of precompiled include files, which are not needed at this stage.
--with-gxx-include-dir=/tools/$LFS_TGT/include/c++/13.2.0
This specifies the installation directory for include files. Because Libstdc++ is the standard C++ library for LFS, this directory should match the location where the C++ compiler ($LFS_TGT-g++) would search for the standard C++ include files. In a normal build, this information is automatically passed to the Libstdc++ configure options from the top level directory. In our case, this information must be explicitly given. The C++ compiler will prepend the sysroot path $LFS (specified when building GCC-pass1) to the include file search path, so it will actually search in $LFS/tools/$LFS_TGT/include/c++/13.2.0. The combination of the DESTDIR variable (in the make install command below) and this switch causes the headers to be installed there.
Compile Libstdc++ by running:
make
Install the library:
make DESTDIR=$LFS install
57
Linux From Scratch - Version 12.1 Remove the libtool archive files because they are harmful for cross-compilation:
rm -v $LFS/usr/lib/lib{stdc++{,exp,fs},supc++}.la
Details on this package are located in Section 8.28.2, “Contents of GCC.”
58
Linux From Scratch - Version 12.1
Chapter 6. Cross Compiling Temporary Tools
6.1. Introduction
This chapter shows how to cross-compile basic utilities using the just built cross-toolchain. Those utilities are installed into their final location, but cannot be used yet. Basic tasks still rely on the host's tools. Nevertheless, the installed libraries are used when linking. Using the utilities will be possible in the next chapter after entering the “chroot” environment. But all the packages built in the present chapter need to be built before we do that. Therefore we cannot be independent of the host system yet. Once again, let us recall that improper setting of LFS together with building as root, may render your computer unusable. This whole chapter must be done as user lfs, with the environment as described in Section 4.4, “Setting Up the Environment”.
59
6.2. M4-1.4.19
The M4 package contains a macro processor.
Approximate build time: 0.1 SBU
Required disk space:
31 MB
6.2.1. Installation of M4
Prepare M4 for compilation:
./configure --prefix=/usr \ --host=$LFS_TGT \ --build=$(build-aux/config.guess)
Compile the package:
make
Install the package:
make DESTDIR=$LFS install
Details on this package are located in Section 8.12.2, “Contents of M4.”
Linux From Scratch - Version 12.1
60
Linux From Scratch - Version 12.1
6.3. Ncurses-6.4-20230520
The Ncurses package contains libraries for terminal-independent handling of character screens.
Approximate build time: 0.3 SBU
Required disk space:
51 MB
6.3.1. Installation of Ncurses
First, ensure that gawk is found first during configuration:
sed -i s/mawk// configure
Then, run the following commands to build the “tic” program on the build host:
mkdir build pushd build
../configure make -C include make -C progs tic popd
Prepare Ncurses for compilation:
./configure --prefix=/usr
\
--host=$LFS_TGT
\
--build=$(./config.guess) \
--mandir=/usr/share/man
\
--with-manpage-format=normal \
--with-shared
\
--without-normal
\
--with-cxx-shared
\
--without-debug
\
--without-ada
\
--disable-stripping
\
--enable-widec
The meaning of the new configure options:
--with-manpage-format=normal
This prevents Ncurses from installing compressed manual pages, which may happen if the host distribution itself has compressed manual pages.
--with-shared
This makes Ncurses build and install shared C libraries.
--without-normal
This prevents Ncurses from building and installing static C libraries.
--without-debug
This prevents Ncurses from building and installing debug libraries.
--with-cxx-shared
This makes Ncurses build and install shared C++ bindings. It also prevents it building and installing static C+ + bindings.
--without-ada
This ensures that Ncurses does not build support for the Ada compiler, which may be present on the host but will not be available once we enter the chroot environment.
61
Linux From Scratch - Version 12.1
--disable-stripping
This switch prevents the building system from using the strip program from the host. Using host tools on crosscompiled programs can cause failure.
--enable-widec
This switch causes wide-character libraries (e.g., libncursesw.so.6.4-20230520) to be built instead of normal ones (e.g., libncurses.so.6.4-20230520). These wide-character libraries are usable in both multibyte and traditional 8-bit locales, while normal libraries work properly only in 8-bit locales. Wide-character and normal libraries are source-compatible, but not binary-compatible. Compile the package:
make
Install the package:
make DESTDIR=$LFS TIC_PATH=$(pwd)/build/progs/tic install ln -sv libncursesw.so $LFS/usr/lib/libncurses.so sed -e 's/^#if.*XOPEN.*$/#if 1/' \
-i $LFS/usr/include/curses.h
The meaning of the install options:
TIC_PATH=$(pwd)/build/progs/tic
We need to pass the path of the newly built tic program that runs on the building machine, so the terminal database can be created without errors. ln -sv libncursesw.so $LFS/usr/lib/libncurses.so The libncurses.so library is needed by a few packages we will build soon. We create this symlink to use libncursesw.so as a replacement. sed -e 's/^#if.*XOPEN.*$/#if 1/' ... The header file curses.h contains the definition of various Ncurses data structures. With different preprocessor macro definitions two different sets of the data structure definition may be used: the 8-bit definition is compatible with libncurses.so and the wide-character definition is compatible with libncursesw.so. Since we are using libncursesw.so as a replacement of libncurses.so, edit the header file so it will always use the wide-character data structure definition compatible with libncursesw.so. Details on this package are located in Section 8.29.2, “Contents of Ncurses.”
62
Linux From Scratch - Version 12.1
6.4. Bash-5.2.21
The Bash package contains the Bourne-Again Shell.
Approximate build time: 0.2 SBU
Required disk space:
67 MB
6.4.1. Installation of Bash
Prepare Bash for compilation:
./configure --prefix=/usr
\
--build=$(sh support/config.guess) \
--host=$LFS_TGT
\
--without-bash-malloc
The meaning of the configure options:
--without-bash-malloc
This option turns off the use of Bash's memory allocation (malloc) function which is known to cause segmentation faults. By turning this option off, Bash will use the malloc functions from Glibc which are more stable.
Compile the package:
make
Install the package:
make DESTDIR=$LFS install
Make a link for the programs that use sh for a shell:
ln -sv bash $LFS/bin/sh
Details on this package are located in Section 8.35.2, “Contents of Bash.”
63
Linux From Scratch - Version 12.1
6.5. Coreutils-9.4
The Coreutils package contains the basic utility programs needed by every operating system.
Approximate build time: 0.3 SBU
Required disk space:
173 MB
6.5.1. Installation of Coreutils
Prepare Coreutils for compilation:
./configure --prefix=/usr
\
--host=$LFS_TGT
\
--build=$(build-aux/config.guess) \
--enable-install-program=hostname \
--enable-no-install-program=kill,uptime
The meaning of the configure options:
--enable-install-program=hostname
This enables the hostname binary to be built and installed it is disabled by default but is required by the Perl test suite.
Compile the package:
make
Install the package:
make DESTDIR=$LFS install
Move programs to their final expected locations. Although this is not necessary in this temporary environment, we must do so because some programs hardcode executable locations:
mv -v $LFS/usr/bin/chroot
$LFS/usr/sbin
mkdir -pv $LFS/usr/share/man/man8
mv -v $LFS/usr/share/man/man1/chroot.1 $LFS/usr/share/man/man8/chroot.8
sed -i 's/"1"/"8"/'
$LFS/usr/share/man/man8/chroot.8
Details on this package are located in Section 8.57.2, “Contents of Coreutils.”
64
Linux From Scratch - Version 12.1
6.6. Diffutils-3.10
The Diffutils package contains programs that show the differences between files or directories.
Approximate build time: 0.1 SBU
Required disk space:
29 MB
6.6.1. Installation of Diffutils
Prepare Diffutils for compilation:
./configure --prefix=/usr \ --host=$LFS_TGT \ --build=$(./build-aux/config.guess)
Compile the package:
make
Install the package:
make DESTDIR=$LFS install
Details on this package are located in Section 8.59.2, “Contents of Diffutils.”
65
Linux From Scratch - Version 12.1
6.7. File-5.45
The File package contains a utility for determining the type of a given file or files.
Approximate build time: 0.1 SBU
Required disk space:
37 MB
6.7.1. Installation of File
The file command on the build host needs to be the same version as the one we are building in order to create the signature file. Run the following commands to make a temporary copy of the file command:
mkdir build
pushd build
../configure --disable-bzlib
\
--disable-libseccomp \
--disable-xzlib
\
--disable-zlib
make
popd
The meaning of the new configure option:
--disable-*
The configuration script attempts to use some packages from the host distribution if the corresponding library files exist. It may cause compilation failure if a library file exists, but the corresponding header files do not. These options prevent using these unneeded capabilities from the host.
Prepare File for compilation:
./configure --prefix=/usr --host=$LFS_TGT --build=$(./config.guess)
Compile the package:
make FILE_COMPILE=$(pwd)/build/src/file
Install the package:
make DESTDIR=$LFS install
Remove the libtool archive file because it is harmful for cross compilation:
rm -v $LFS/usr/lib/libmagic.la
Details on this package are located in Section 8.10.2, “Contents of File.”
66
Linux From Scratch - Version 12.1
6.8. Findutils-4.9.0
The Findutils package contains programs to find files. Programs are provided to search through all the files in a directory tree and to create, maintain, and search a database (often faster than the recursive find, but unreliable unless the database has been updated recently). Findutils also supplies the xargs program, which can be used to run a specified command on each file selected by a search.
Approximate build time: 0.1 SBU
Required disk space:
42 MB
6.8.1. Installation of Findutils
Prepare Findutils for compilation:
./configure --prefix=/usr
\
--localstatedir=/var/lib/locate \
--host=$LFS_TGT
\
--build=$(build-aux/config.guess)
Compile the package:
make
Install the package:
make DESTDIR=$LFS install
Details on this package are located in Section 8.61.2, “Contents of Findutils.”
67
6.9. Gawk-5.3.0
The Gawk package contains programs for manipulating text files.
Approximate build time: 0.1 SBU
Required disk space:
47 MB
6.9.1. Installation of Gawk
First, ensure some unneeded files are not installed:
sed -i 's/extras//' Makefile.in
Prepare Gawk for compilation:
./configure --prefix=/usr \ --host=$LFS_TGT \ --build=$(build-aux/config.guess)
Compile the package:
make
Install the package:
make DESTDIR=$LFS install
Details on this package are located in Section 8.60.2, “Contents of Gawk.”
Linux From Scratch - Version 12.1
68
Linux From Scratch - Version 12.1
6.10. Grep-3.11
The Grep package contains programs for searching through the contents of files.
Approximate build time: 0.1 SBU
Required disk space:
27 MB
6.10.1. Installation of Grep
Prepare Grep for compilation:
./configure --prefix=/usr \ --host=$LFS_TGT \ --build=$(./build-aux/config.guess)
Compile the package:
make
Install the package:
make DESTDIR=$LFS install
Details on this package are located in Section 8.34.2, “Contents of Grep.”
69
Linux From Scratch - Version 12.1
6.11. Gzip-1.13
The Gzip package contains programs for compressing and decompressing files.
Approximate build time: 0.1 SBU
Required disk space:
11 MB
6.11.1. Installation of Gzip
Prepare Gzip for compilation:
./configure --prefix=/usr --host=$LFS_TGT
Compile the package:
make
Install the package:
make DESTDIR=$LFS install
Details on this package are located in Section 8.64.2, “Contents of Gzip.”
70
Linux From Scratch - Version 12.1
6.12. Make-4.4.1
The Make package contains a program for controlling the generation of executables and other non-source files of a package from source files.
Approximate build time: less than 0.1 SBU
Required disk space:
15 MB
6.12.1. Installation of Make
Prepare Make for compilation:
./configure --prefix=/usr \ --without-guile \ --host=$LFS_TGT \ --build=$(build-aux/config.guess)
The meaning of the new configure option:
--without-guile
Although we are cross-compiling, configure tries to use guile from the build host if it finds it. This makes compilation fail, so this switch prevents using it. Compile the package:
make
Install the package:
make DESTDIR=$LFS install
Details on this package are located in Section 8.68.2, “Contents of Make.”
71
Linux From Scratch - Version 12.1
6.13. Patch-2.7.6
The Patch package contains a program for modifying or creating files by applying a “patch” file typically created by the diff program.
Approximate build time: 0.1 SBU
Required disk space:
12 MB
6.13.1. Installation of Patch
Prepare Patch for compilation:
./configure --prefix=/usr \ --host=$LFS_TGT \ --build=$(build-aux/config.guess)
Compile the package:
make
Install the package:
make DESTDIR=$LFS install
Details on this package are located in Section 8.69.2, “Contents of Patch.”
72
6.14. Sed-4.9
The Sed package contains a stream editor.
Approximate build time: 0.1 SBU
Required disk space:
21 MB
6.14.1. Installation of Sed
Prepare Sed for compilation:
./configure --prefix=/usr \ --host=$LFS_TGT \ --build=$(./build-aux/config.guess)
Compile the package:
make
Install the package:
make DESTDIR=$LFS install
Details on this package are located in Section 8.30.2, “Contents of Sed.”
Linux From Scratch - Version 12.1
73
Linux From Scratch - Version 12.1
6.15. Tar-1.35
The Tar package provides the ability to create tar archives as well as perform various other kinds of archive manipulation. Tar can be used on previously created archives to extract files, to store additional files, or to update or list files which were already stored.
Approximate build time: 0.1 SBU
Required disk space:
42 MB
6.15.1. Installation of Tar
Prepare Tar for compilation:
./configure --prefix=/usr
\
--host=$LFS_TGT
\
--build=$(build-aux/config.guess)
Compile the package:
make
Install the package:
make DESTDIR=$LFS install
Details on this package are located in Section 8.70.2, “Contents of Tar.”
74
Linux From Scratch - Version 12.1
6.16. Xz-5.4.6
The Xz package contains programs for compressing and decompressing files. It provides capabilities for the lzma and the newer xz compression formats. Compressing text files with xz yields a better compression percentage than with the traditional gzip or bzip2 commands.
Approximate build time: 0.1 SBU
Required disk space:
22 MB
6.16.1. Installation of Xz
Prepare Xz for compilation:
./configure --prefix=/usr
\
--host=$LFS_TGT
\
--build=$(build-aux/config.guess) \
--disable-static
\
--docdir=/usr/share/doc/xz-5.4.6
Compile the package:
make
Install the package:
make DESTDIR=$LFS install
Remove the libtool archive file because it is harmful for cross compilation:
rm -v $LFS/usr/lib/liblzma.la
Details on this package are located in Section 8.8.2, “Contents of Xz.”
75
Linux From Scratch - Version 12.1
6.17. Binutils-2.42 - Pass 2
The Binutils package contains a linker, an assembler, and other tools for handling object files.
Approximate build time: 0.5 SBU
Required disk space:
537 MB
6.17.1. Installation of Binutils
Binutils building system relies on an shipped libtool copy to link against internal static libraries, but the libiberty and zlib copies shipped in the package do not use libtool. This inconsistency may cause produced binaries mistakenly linked against libraries from the host distro. Work around this issue:
sed '6009s/$add_dir//' -i ltmain.sh
Create a separate build directory again:
mkdir -v build
cd
build
Prepare Binutils for compilation:
../configure
\
--prefix=/usr
\
--build=$(../config.guess) \
--host=$LFS_TGT
\
--disable-nls
\
--enable-shared
\
--enable-gprofng=no
\
--disable-werror
\
--enable-64-bit-bfd
\
--enable-default-hash-style=gnu
The meaning of the new configure options:
--enable-shared
Builds libbfd as a shared library.
--enable-64-bit-bfd
Enables 64-bit support (on hosts with smaller word sizes). This may not be needed on 64-bit systems, but it does no harm.
Compile the package:
make
Install the package:
make DESTDIR=$LFS install
Remove the libtool archive files because they are harmful for cross compilation, and remove unnecessary static libraries:
rm -v $LFS/usr/lib/lib{bfd,ctf,ctf-nobfd,opcodes,sframe}.{a,la}
Details on this package are located in Section 8.19.2, “Contents of Binutils.”
76
Linux From Scratch - Version 12.1
6.18. GCC-13.2.0 - Pass 2
The GCC package contains the GNU compiler collection, which includes the C and C++ compilers.
Approximate build time: 4.4 SBU
Required disk space:
4.8 GB
6.18.1. Installation of GCC
As in the first build of GCC, the GMP, MPFR, and MPC packages are required. Unpack the tarballs and move them into the required directories:
tar -xf ../mpfr-4.2.1.tar.xz mv -v mpfr-4.2.1 mpfr tar -xf ../gmp-6.3.0.tar.xz mv -v gmp-6.3.0 gmp tar -xf ../mpc-1.3.1.tar.gz mv -v mpc-1.3.1 mpc
If building on x86_64, change the default directory name for 64-bit libraries to “lib”:
case $(uname -m) in x86_64) sed -e '/m64=/s/lib64/lib/' \ -i.orig gcc/config/i386/t-linux64 ;;
esac
Override the building rule of libgcc and libstdc++ headers, to allow building these libraries with POSIX threads support:
sed '/thread_header =/s/@.*@/gthr-posix.h/' \ -i libgcc/Makefile.in libstdc++-v3/include/Makefile.in
Create a separate build directory again:
mkdir -v build
cd
build
Before starting to build GCC, remember to unset any environment variables that override the default optimization flags.
Now prepare GCC for compilation:
../configure
\
--build=$(../config.guess)
\
--host=$LFS_TGT
\
--target=$LFS_TGT
\
LDFLAGS_FOR_TARGET=-L$PWD/$LFS_TGT/libgcc
\
--prefix=/usr
\
--with-build-sysroot=$LFS
\
--enable-default-pie
\
--enable-default-ssp
\
--disable-nls
\
--disable-multilib
\
--disable-libatomic
\
--disable-libgomp
\
--disable-libquadmath
\
--disable-libsanitizer
\
--disable-libssp
\
--disable-libvtv
\
--enable-languages=c,c++
77
Linux From Scratch - Version 12.1
The meaning of the new configure options:
--with-build-sysroot=$LFS
Normally, using --host ensures that a cross-compiler is used for building GCC, and that compiler knows that it has to look for headers and libraries in $LFS. But the build system for GCC uses other tools, which are not aware of this location. This switch is needed so those tools will find the needed files in $LFS, and not on the host.
--target=$LFS_TGT
We are cross-compiling GCC, so it's impossible to build target libraries (libgcc and libstdc++) with the previously compiled GCC binaries—those binaries won't run on the host. The GCC build system will attempt to use the host's C and C++ compilers as a workaround by default. Building the GCC target libraries with a different version of GCC is not supported, so using the host's compilers may cause the build to fail. This parameter ensures the libraries are built by GCC pass 1.
LDFLAGS_FOR_TARGET=...
Allow libstdc++ to use the shared libgcc being built in this pass, instead of the static version that was built in GCC pass 1. This is necessary to support C++ exception handling.
--disable-libsanitizer
Disable GCC sanitizer runtime libraries. They are not needed for the temporary installation. This switch is necessary to build GCC without libcrypt installed for the target. In gcc-pass1 it was implied by --disablelibstdcxx, but now we have to explicitly pass it. Compile the package:
make
Install the package:
make DESTDIR=$LFS install
As a finishing touch, create a utility symlink. Many programs and scripts run cc instead of gcc, which is used to keep programs generic and therefore usable on all kinds of UNIX systems where the GNU C compiler is not always installed. Running cc leaves the system administrator free to decide which C compiler to install:
ln -sv gcc $LFS/usr/bin/cc
Details on this package are located in Section 8.28.2, “Contents of GCC.”
78
Linux From Scratch - Version 12.1
Chapter 7. Entering Chroot and Building Additional Temporary Tools
7.1. Introduction
This chapter shows how to build the last missing bits of the temporary system: the tools needed to build the various packages. Now that all circular dependencies have been resolved, a “chroot” environment, completely isolated from the host operating system (except for the running kernel), can be used for the build. For proper operation of the isolated environment, some communication with the running kernel must be established. This is done via the so-called Virtual Kernel File Systems, which will be mounted before entering the chroot environment. You may want to verify that they are mounted by issuing the findmnt command. Until Section 7.4, “Entering the Chroot Environment”, the commands must be run as root, with the LFS variable set. After entering chroot, all commands are run as root, fortunately without access to the OS of the computer you built LFS on. Be careful anyway, as it is easy to destroy the whole LFS system with bad commands.
7.2. Changing Ownership
Note
The commands in the remainder of this book must be performed while logged in as user root and no longer as user lfs. Also, double check that $LFS is set in root's environment.
Currently, the whole directory hierarchy in $LFS is owned by the user lfs, a user that exists only on the host system. If the directories and files under $LFS are kept as they are, they will be owned by a user ID without a corresponding account. This is dangerous because a user account created later could get this same user ID and would own all the files under $LFS, thus exposing these files to possible malicious manipulation. To address this issue, change the ownership of the $LFS/* directories to user root by running the following command:
chown -R root:root $LFS/{usr,lib,var,etc,bin,sbin,tools} case $(uname -m) in
x86_64) chown -R root:root $LFS/lib64 ;; esac
7.3. Preparing Virtual Kernel File Systems
Applications running in userspace utilize various file systems created by the kernel to communicate with the kernel itself. These file systems are virtual: no disk space is used for them. The content of these file systems resides in memory. These file systems must be mounted in the $LFS directory tree so the applications can find them in the chroot environment. Begin by creating the directories on which these virtual file systems will be mounted:
mkdir -pv $LFS/{dev,proc,sys,run}
7.3.1. Mounting and Populating /dev
During a normal boot of an LFS system, the kernel automatically mounts the devtmpfs file system on the /dev directory; the kernel creates device nodes on that virtual file system during the boot process, or when a device is first detected or accessed. The udev daemon may change the ownership or permissions of the device nodes created by the kernel,
79
Linux From Scratch - Version 12.1
and create new device nodes or symlinks, to ease the work of distro maintainers and system administrators. (See Section 9.3.2.2, “Device Node Creation” for details.) If the host kernel supports devtmpfs, we can simply mount a devtmpfs at $LFS/dev and rely on the kernel to populate it.
But some host kernels lack devtmpfs support; these host distros use different methods to create the content of /dev. So the only host-agnostic way to populate the $LFS/dev directory is by bind mounting the host system's /dev directory. A bind mount is a special type of mount that makes a directory subtree or a file visible at some other location. Use the following command to do this.
mount -v --bind /dev $LFS/dev
7.3.2. Mounting Virtual Kernel File Systems
Now mount the remaining virtual kernel file systems:
mount -vt devpts devpts -o gid=5,mode=0620 $LFS/dev/pts mount -vt proc proc $LFS/proc mount -vt sysfs sysfs $LFS/sys mount -vt tmpfs tmpfs $LFS/run
The meaning of the mount options for devpts:
gid=5
This ensures that all devpts-created device nodes are owned by group ID 5. This is the ID we will use later on for the tty group. We use the group ID instead of a name, since the host system might use a different ID for its tty group.
mode=0620
This ensures that all devpts-created device nodes have mode 0620 (user readable and writable, group writable). Together with the option above, this ensures that devpts will create device nodes that meet the requirements of grantpt(), meaning the Glibc pt_chown helper binary (which is not installed by default) is not necessary.
In some host systems, /dev/shm is a symbolic link to a directory, typically /run/shm. The /run tmpfs was mounted above so in this case only a directory needs to be created with the correct permissions.
In other host systems /dev/shm is a mount point for a tmpfs. In that case the mount of /dev above will only create /dev/ shm as a directory in the chroot environment. In this situation we must explicitly mount a tmpfs:
if [ -h $LFS/dev/shm ]; then install -v -d -m 1777 $LFS$(realpath /dev/shm)
else mount -vt tmpfs -o nosuid,nodev tmpfs $LFS/dev/shm
fi
7.4. Entering the Chroot Environment
Now that all the packages which are required to build the rest of the needed tools are on the system, it is time to enter the chroot environment and finish installing the temporary tools. This environment will also be used to install the final system. As user root, run the following command to enter the environment that is, at the moment, populated with nothing but temporary tools:
chroot "$LFS" /usr/bin/env -i \
HOME=/root
\
TERM="$TERM"
\
PS1='(lfs chroot) \u:\w\$ ' \
PATH=/usr/bin:/usr/sbin
\
MAKEFLAGS="-j$(nproc)"
\
TESTSUITEFLAGS="-j$(nproc)" \
/bin/bash --login
80
Linux From Scratch - Version 12.1 If you don't want to use all available logical cores, replace $(nproc) with the number of logical cores you want to use for building packages in this chapter and the following chapters. The test suites of some packages (notably Autoconf, Libtool, and Tar) in Chapter 8 are not affected by MAKEFLAGS, they use a TESTSUITEFLAGS environment variable instead. We set that here as well for running these test suites with multiple cores. The -i option given to the env command will clear all the variables in the chroot environment. After that, only the HOME, TERM, PS1, and PATH variables are set again. The TERM=$TERM construct sets the TERM variable inside chroot to the same value as outside chroot. This variable is needed so programs like vim and less can operate properly. If other variables are desired, such as CFLAGS or CXXFLAGS, this is a good place to set them. From this point on, there is no need to use the LFS variable any more because all work will be restricted to the LFS file system; the chroot command runs the Bash shell with the root (/) directory set to $LFS. Notice that /tools/bin is not in the PATH. This means that the cross toolchain will no longer be used. Also note that the bash prompt will say I have no name! This is normal because the /etc/passwd file has not been created yet.
Note
It is important that all the commands throughout the remainder of this chapter and the following chapters are run from within the chroot environment. If you leave this environment for any reason (rebooting for example), ensure that the virtual kernel filesystems are mounted as explained in Section 7.3.1, “Mounting and Populating /dev” and Section 7.3.2, “Mounting Virtual Kernel File Systems” and enter chroot again before continuing with the installation.
7.5. Creating Directories
It is time to create the full directory structure in the LFS file system.
Note
Some of the directories mentioned in this section may have already been created earlier with explicit instructions, or when installing some packages. They are repeated below for completeness.
Create some root-level directories that are not in the limited set required in the previous chapters by issuing the following command:
mkdir -pv /{boot,home,mnt,opt,srv}
81