Linux From Scratch Version 6.1.1 Gerard Beekmans Copyright © 1999-2005 Gerard Beekmans Copyright (c) 1999-2005, Gerard Beekmans All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions in any form must retain the above copyright notice, this list of conditions and the following disclaimer * Neither the name of "Linux From Scratch" nor the names of its contributors may be used to endorse or promote products derived from this material without specific prior written permission * Any material derived from Linux From Scratch must contain a reference to the "Linux From Scratch" project THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. _________________________________________________________________ Table of Contents * Preface + [1]Foreword + [2]Audience + [3]Prerequisites + [4]Host System Requirements + [5]Typography + [6]Structure + [7]Errata * I. Introduction + 1. Introduction o [8]How to Build an LFS System o [9]Changelog o [10]Resources o [11]Help * II. Preparing for the Build + 2. Preparing a New Partition o [12]Introduction o [13]Creating a New Partition o [14]Creating a File System on the Partition o [15]Mounting the New Partition + 3. Packages and Patches o [16]Introduction o [17]All Packages o [18]Needed Patches + 4. Final Preparations o [19]About $LFS o [20]Creating the $LFS/tools Directory o [21]Adding the LFS User o [22]Setting Up the Environment o [23]About SBUs o [24]About the Test Suites + 5. Constructing a Temporary System o [25]Introduction o [26]Toolchain Technical Notes o [27]Binutils-2.15.94.0.2.2 - Pass 1 o [28]GCC-3.4.3 - Pass 1 o [29]Linux-Libc-Headers-2.6.11.2 o [30]Glibc-2.3.4 o [31]Adjusting the Toolchain o [32]Tcl-8.4.9 o [33]Expect-5.43.0 o [34]DejaGNU-1.4.4 o [35]GCC-3.4.3 - Pass 2 o [36]Binutils-2.15.94.0.2.2 - Pass 2 o [37]Gawk-3.1.4 o [38]Coreutils-5.2.1 o [39]Bzip2-1.0.3 o [40]Gzip-1.3.5 o [41]Diffutils-2.8.1 o [42]Findutils-4.2.23 o [43]Make-3.80 o [44]Grep-2.5.1a o [45]Sed-4.1.4 o [46]Gettext-0.14.3 o [47]Ncurses-5.4 o [48]Patch-2.5.4 o [49]Tar-1.15.1 o [50]Texinfo-4.8 o [51]Bash-3.0 o [52]M4-1.4.3 o [53]Bison-2.0 o [54]Flex-2.5.31 o [55]Util-linux-2.12q o [56]Perl-5.8.7 o [57]Stripping * III. Building the LFS System + 6. Installing Basic System Software o [58]Introduction o [59]Mounting Virtual Kernel File Systems o [60]Entering the Chroot Environment o [61]Changing Ownership o [62]Creating Directories o [63]Creating Essential Symlinks o [64]Creating the passwd, group, and log Files o [65]Populating /dev o [66]Linux-Libc-Headers-2.6.11.2 o [67]Man-pages-2.01 o [68]Glibc-2.3.4 o [69]Re-adjusting the Toolchain o [70]Binutils-2.15.94.0.2.2 o [71]GCC-3.4.3 o [72]Coreutils-5.2.1 o [73]Zlib-1.2.3 o [74]Mktemp-1.5 o [75]Iana-Etc-1.04 o [76]Findutils-4.2.23 o [77]Gawk-3.1.4 o [78]Ncurses-5.4 o [79]Readline-5.0 o [80]Vim-6.3 o [81]M4-1.4.3 o [82]Bison-2.0 o [83]Less-382 o [84]Groff-1.19.1 o [85]Sed-4.1.4 o [86]Flex-2.5.31 o [87]Gettext-0.14.3 o [88]Inetutils-1.4.2 o [89]IPRoute2-2.6.11-050330 o [90]Perl-5.8.7 o [91]Texinfo-4.8 o [92]Autoconf-2.59 o [93]Automake-1.9.5 o [94]Bash-3.0 o [95]File-4.13 o [96]Libtool-1.5.14 o [97]Bzip2-1.0.3 o [98]Diffutils-2.8.1 o [99]Kbd-1.12 o [100]E2fsprogs-1.37 o [101]Grep-2.5.1a o [102]GRUB-0.96 o [103]Gzip-1.3.5 o [104]Hotplug-2004_09_23 o [105]Man-1.5p o [106]Make-3.80 o [107]Module-Init-Tools-3.1 o [108]Patch-2.5.4 o [109]Procps-3.2.5 o [110]Psmisc-21.6 o [111]Shadow-4.0.9 o [112]Sysklogd-1.4.1 o [113]Sysvinit-2.86 o [114]Tar-1.15.1 o [115]Udev-056 o [116]Util-linux-2.12q o [117]About Debugging Symbols o [118]Stripping Again o [119]Cleaning Up + 7. Setting Up System Bootscripts o [120]Introduction o [121]LFS-Bootscripts-3.2.1 o [122]How Do These Bootscripts Work? o [123]Device and Module Handling on an LFS System o [124]Configuring the setclock Script o [125]Configuring the Linux Console o [126]Configuring the sysklogd script o [127]Creating the /etc/inputrc File o [128]The Bash Shell Startup Files o [129]Configuring the localnet Script o [130]Creating the /etc/hosts File o [131]Configuring the network Script + 8. Making the LFS System Bootable o [132]Introduction o [133]Creating the /etc/fstab File o [134]Linux-2.6.11.12 o [135]Making the LFS System Bootable + 9. The End o [136]The End o [137]Get Counted o [138]Rebooting the System o [139]What Now? * IV. Appendices + [140]A. Acronyms and Terms + [141]B. Acknowledgments * [142]Index Preface 1. Foreword My adventures in Linux began in 1998 when I downloaded and installed my first distribution. After working with it for a while, I discovered issues I definitely would have liked to see improved upon. For example, I didn't like the arrangement of the bootscripts or the way programs were configured by default. I tried a number of alternative distributions to address these issues, yet each had its pros and cons. Finally, I realized that if I wanted full satisfaction from my Linux system, I would have to build my own from scratch. What does this mean? I resolved not to use pre-compiled packages of any kind, nor CD-ROMs or boot disks that would install basic utilities. I would use my current Linux system to develop my own customized system. This "perfect" Linux system would then have the strengths of various systems without their associated weaknesses. In the beginning, the idea was rather daunting, but I remained committed to the idea that a system could be built that would conform to my needs and desires rather than to a standard that just did not fit what I was looking for. After sorting through issues such as circular dependencies and compile-time errors, I created a custom-built Linux system that was fully operational and suitable to individual needs. This process also allowed me to create compact and streamlined Linux systems which are faster and take up less space than traditional operating systems. I called this system a Linux From Scratch system, or an LFS system for short. As I shared my goals and experiences with other members of the Linux community, it became apparent that there was sustained interest in the ideas set forth in my Linux adventures. Such custom-built LFS systems serve not only to meet user specifications and requirements, but also serve as an ideal learning opportunity for programmers and system administrators to enhance their Linux skills. Out of this broadened interest, the Linux From Scratch Project was born. This Linux From Scratch book provides readers with the background and instruction to design and build custom Linux systems. This book highlights the Linux from Scratch project and the benefits of using this system. Users can dictate all aspects of their system, including directory layout, script setup, and security. The resulting system will be compiled completely from the source code, and the user will be able to specify where, why, and how programs are installed. This book allows readers to fully customize Linux systems to their own needs and allows users more control over their system. I hope you will have a great time working on your own LFS system, and enjoy the numerous benefits of having a system that is truly your own. -- Gerard Beekmans gerard AT linuxfromscratch D0T org 2. Audience There are many reasons why somebody would want to read this book. The principal reason is to install a Linux system from the source code. A question 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?" That is a good question and is the impetus for this section of the book. One important reason for LFS's existence is to help people 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 that this learning experience provides is the ability to customize Linux to your own tastes and needs. A key benefit of LFS is that it allows users to have more control over the system without relying on someone else's Linux implementation. With LFS, you are in the driver's seat and dictate every aspect of the system, such as the directory layout and bootscript setup. You also dictate where, why, and how programs are installed. Another benefit of LFS is the ability to create a very compact Linux system. When installing a regular distribution, one is often forced to include several programs which are probably never used. These programs waste disk space, or worse, CPU cycles. It is not difficult to build an LFS system of less than 100 megabytes (MB), which is substantially smaller than the majority of existing installations. Does this still sound like a lot of space? A few of us have been working on creating a very small embedded LFS system. We successfully built a system that was specialized to run the Apache web server with approximately 8MB of disk space used. Further stripping could bring this down to 5 MB or less. Try that with a regular distribution! This is only one of the many benefits of designing your own Linux implementation. We could compare Linux distributions to a hamburger purchased at a fast-food restaurant--you have no idea what might be in what you are eating. LFS, on the other hand, does not give you a hamburger. Rather, LFS provides the recipe to make the exact hamburger desired. This allows users to review the recipe, omit unwanted ingredients, and add your own ingredients to enhance the flavor of the burger. When you are satisfied with the recipe, move on to preparing it. It can be made to exact specifications--broil it, bake it, deep-fry it, or barbecue it. Another analogy that we can use is that of comparing LFS with a finished house. LFS provides the skeletal plan of a house, but it is up to you to build it. LFS maintains the freedom to adjust plans throughout the process, customizing it to the user's needs and preferences. An additional 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 desired. It is no longer necessary 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. Readers who do not wish to build their own Linux system from scratch may not benefit from the information in this book. If you only want to know what happens while the computer boots, we recommend the "From Power Up To Bash Prompt" HOWTO located at [143]http://axiom.anu.edu.au/~okeefe/p2b/ or on The Linux Documentation Project's (TLDP) website at [144]http://www.tldp.org/HOWTO/From-PowerUp-To-Bash-Prompt-HOWTO.html. The HOWTO builds a system which is similar to that of this book, but it focuses strictly on creating a system capable of booting to a BASH prompt. Consider your objective. If you wish to build a Linux system while learning along the way, then this book is your best choice. There are too many good reasons to build your own LFS system to list them all here. This section is only the tip of the iceberg. As you continue in your LFS experience, you will find the power that information and knowledge truly bring. 3. 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, the reader should already have the ability 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 the reader has a reasonable knowledge of using and installing Linux software. Because the LFS book assumes at least this basic level of skill, the various LFS support forums are unlikely to be able to provide you with much assistance; 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 recommend reading the following HOWTOs: * Software-Building-HOWTO [145]http://www.tldp.org/HOWTO/Software-Building-HOWTO.html This is a comprehensive guide to building and installing "generic" Unix software distributions under Linux. * The Linux Users' Guide [146]http://www.linuxhq.com/guides/LUG/guide.html This guide covers the usage of assorted Linux software. * The Essential Pre-Reading Hint [147]http://www.linuxfromscratch.org/hints/downloads/files/essenti al_prereading.txt This is an LFS Hint written specifically for users new to Linux. It includes a list of links to excellent sources of information on a wide range of topics. Anyone attempting to install LFS should have an understanding of many of the topics in this hint. 4. Host System Requirements The host must be running at least a 2.6.2 kernel compiled with GCC-3.0 or higher. There are two main reasons for this requirement. First, the Native POSIX Threading Library (NPTL) test suite will segfault if the host's kernel has not been compiled with GCC-3.0 or a later version. Second, the 2.6.2 or later version of the kernel is required for the use of Udev. Udev creates devices dynamically by reading from the sysfs file system. However, support for this filesystem has only recently been implemented in most of the kernel drivers. We must be sure that all critical system devices get created properly. In order to determine whether the host kernel meets the requirements outlined above, run the following command: cat /proc/version This will produce output similar to: Linux version 2.6.2 (user@host) (gcc version 3.4.0) #1 Tue Apr 20 21:22:18 GMT 2004 If the results of the above command do not state that the host kernel is either 2.6.2 (or later), or that it was not compiled using a GCC-3.0 (or later) compiler, one will need to be installed. There are two methods you can take to solve this. First, see if your Linux vendor provides a 2.6.2 (or later) kernel package. If so, you may wish to install it. If your vendor doesn't offer a 2.6.2 (or later) kernel package, or you would prefer not to install it, then you can compile a 2.6 kernel yourself. Instructions for compiling the kernel and configuring the boot loader (assuming the host uses GRUB) are located in [148]Chapter 8. This second option can also be seen as a gauge of your current Linux skills. If this second requirement is too steep, then the LFS book will not likely be much use to you at this time. 5. 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. install-info: unknown option '--dir-file=/mnt/lfs/usr/info/dir' This form of text (fixed-width text) shows screen output, probably as the result of commands issued. This format is also used to show filenames, such as /etc/ld.so.conf. Emphasis This form of text is used for several purposes in the book. Its main purpose is to emphasize important points or items. [149]http://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 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 copied-and-pasted. passwd(5) This format is used to refer to a specific manual page (hereinafter referred to simply as a "man" page). The number inside parentheses indicates a specific section inside of man. 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. Both man pages have different information in them. 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 specific page being referred to. It should be noted that most man pages do not have duplicate page names in different sections. Therefore, man [program name] is generally sufficient. 6. Structure This book is divided into the following parts. 6.1. Part I - Introduction Part I explains a few important notes on how to proceed with the LFS installation. This section also provides meta-information about the book. 6.2. 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. 6.3. Part III - Building the LFS System Part III 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. 7. Errata 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 accommodate security vulnerabilities or other bug fixes, please visit [150]http://www.linuxfromscratch.org/lfs/errata/6.1.1/ before proceeding with your build. You should note any changes shown and apply them to the relevant section of the book as you progress with building the LFS system. Part I. Introduction Table of Contents * 1. Introduction + [151]How to Build an LFS System + [152]Changelog + [153]Resources + [154]Help Chapter 1. Introduction 1.1. How to Build an LFS System The LFS system will be built by using a previously installed Linux distribution (such as Debian, Mandrake, Red Hat, or SuSE). 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 be able to access these tools. As an alternative to installing an entire separate distribution onto your machine, you may wish to use the Linux From Scratch LiveCD. The CD works well as a host system, providing all the tools you need to successfully follow the instructions in this book. Additionally, it contains all the source packages, patches and a copy of this book. So once you have the CD, no network connection or additional downloads are necessary. For more information about the LFS LiveCD or to download a copy, visit [155]http://www.linuxfromscratch.org/livecd/. [156]Chapter 2 of this book describes how to create a new Linux native partition and file system, the place where the new LFS system will be compiled and installed. [157]Chapter 3 explains which packages and patches need to be downloaded to build an LFS system and how to store them on the new file system. [158]Chapter 4 discusses the setup for an appropriate working environment. Please read [159]Chapter 4 carefully as it explains several important issues the developer should be aware of before beginning to work through [160]Chapter 5 and beyond. [161]Chapter 5 explains the installation of a number of packages that will form the basic development suite (or toolchain) which is used to build the actual system in [162]Chapter 6. Some of these packages are needed to resolve circular dependencies--for example, to compile a compiler, you need a compiler. [163]Chapter 5 also shows the user how to build a first pass of the toolchain, including Binutils and GCC (first pass basically means these two core packages will be re-installed a second time). The next step is to build Glibc, the C library. Glibc will be compiled by the toolchain programs built in the first pass. Then, a second pass of the toolchain will be built. This time, the toolchain will be dynamically linked against the newly built Glibc. The remaining [164]Chapter 5 packages are built using this second pass toolchain. When this is done, the LFS installation process will no longer depend on the host distribution, with the exception of the running kernel. This effort to isolate the new system from the host distribution may seem excessive, but a full technical explanation is provided in [165]Section 5.2, "Toolchain Technical Notes". In [166]Chapter 6, the full LFS system is built. The chroot (change root) program is used to enter a virtual environment and start a new shell whose root directory will be set to the LFS partition. This is very similar to rebooting and instructing the kernel to mount the LFS partition as the root partition. The system does not actually reboot, but instead chroot's because creating a bootable system requires additional work which is not necessary just yet. The major advantage is that "chrooting" allows the builder to continue using the host while LFS is being built. While waiting for package compilation to complete, a user can switch to a different virtual console (VC) or X desktop and continue using the computer as normal. To finish the installation, the LFS-Bootscripts are set up in [167]Chapter 7, and the kernel and boot loader are set up in [168]Chapter 8. [169]Chapter 9 contains information on furthering the LFS experience beyond this book. After the steps in this book have been implemented, the computer will be ready to reboot into the new LFS system. This is the process in a nutshell. Detailed information on each step is discussed in the following chapters and package descriptions. Items that may seem complicated will be clarified, and everything will fall into place as the reader embarks on the LFS adventure. 1.2. Changelog This is version 6.1.1 of the Linux From Scratch book, dated November 30, 2005. 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 [170]http://www.linuxfromscratch.org/. Below is a list of changes made since the previous release of the book. First a summary, then a detailed log. * Upgraded to: + Perl 5.8.7 + Zlib 1.2.3 * Added: + binutils-2.15.94.0.2.2-gcc4-1.patch + bzip2-1.0.3-install_docs-1.patch + bzip2-1.0.3-bzgrep_security-1.patch + glibc-2.3.4-rtld_search_dirs-1.patch + glibc-2.3.4-tls_assert-1.patch + texinfo-4.8-tempfile_fix-1.patch + util-linux-2.12q-umount_fix-1.patch + vim-6.3-security_fix-2.patch * Removed: + zlib-1.2.2-security_fix-1.patch; * November 30, 2005 [matt]: LFS-6.1.1 release. * November 24, 2005 [matt]: LFS-6.1.1-pre2 release. * November 24, 2005 [matt]: Fix an issue with Glibc that prevents some programs (including OpenOffice.org) from running. * November 23, 2005 [gerard]: Corrected reference to 'man page' to 'HTML documentation' in chapter 6/sec * November 18, 2005 [manuel]: Fixed the unpack of the module-init-tools-testsuite package. * November 18, 2005 [manuel]: PDF fixes. * November 17, 2005 [matt]: LFS-6.1.1-pre1 release. * November 12, 2005 [matt]: Improve the heuristic for determining a locale that is supported by both Glibc and packages outside LFS (bug 1642). Many thanks to Alexander Patrakov for highlighting the numerous issues and for reviewing the various suggested fixes. * November 12, 2005 [matt]: Omit running Bzip2's testsuite as a separate step, as make runs it automatically (bug 1652). * November 7, 2005 [matt]: Stop Udev from killing udevd processes on the host system (fixes bug 1651). Thanks to Alexander Patrakov for the report and the fix. * November 5, 2005 [matt]: Add a note to the toolchain sanity check in chapter 5 to explain that if TCL fails to build, it's an indication of a broken toolchain (bug 1581). * November 4, 2005 [matt]: Correct the instructions for running Module-Init-Tools' testsuite (fixes bug 1597). Thanks to Greg Schafer, Tushar Teredesai and to Randy McMurchy for providing the patch. * October 29, 2005 [manuel]: PDF fixes. * October 23, 2005 [manuel]: Added Bash documentation installation. Added notes about libiconv and Cracklib. Fixed the installation of Sed documentation. Replaced a patch for IPRoute2 by a sed command. * October 19, 2005 [manuel]: Updated the acknowledgements to current trunk version. Ported some redaction changes in preface and chapter01 pages. Moved chapter02 to part II. Added -v switches. Ported several typos and redaction fixes from trunk. * October 19, 2005 [manuel]: Updated the stylesheets, Makefile and related files to current trunk versions. * October 15, 2005 [matt]: Use an updated version of the Udev rules file (fixes bug 1639). * October 15, 2005 [matt]: Add a cdrom group as required by the Udev rules file * October 14th, 2005 [ken]: Added a patch to allow binutils to be built from a host running gcc-4, updated glibc instructions for the rtld patch, updated space/time for perl and zlib. * October 14th, 2005 [matt]: Added a patch to fix a security vulnerability in util-linux. * October 14th, 2005 [matt]: Added the updated vim security patch. * October 14th, 2005 [jhuntwork]: Added the bzip2 security and install docs patches. * October 14th, 2005 [jhuntwork]: Added the tempfile patch for texinfo. * October 14th, 2005 [ken]: Update packages and patches in the changelog to only reflect changes since 6.1. Update zlib. * October 13th, 2005 [ken]: Fix known errors in lists of installed files and bump the perl version. 1.3. Resources 1.3.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 Frequently Asked Questions (FAQ) that is located at [171]http://www.linuxfromscratch.org/faq/. 1.3.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 the FAQ does not solve the problem you are having, the next step would be to search the mailing lists at [172]http://www.linuxfromscratch.org/search.html. For information on the different lists, how to subscribe, archive locations, and additional information, visit [173]http://www.linuxfromscratch.org/mail.html. 1.3.3. News Server The mailing lists hosted at linuxfromscratch.org are also accessible via the Network News Transfer Protocol (NNTP) server. All messages posted to a mailing list are copied to the corresponding newsgroup, and vice versa. The news server is located at news.linuxfromscratch.org. 1.3.4. IRC Several members of the LFS community offer assistance on our community Internet Relay Chat (IRC) network. Before using this support, please make sure that your question is not already answered in the LFS FAQ or the mailing list archives. You can find the IRC network at irc.linuxfromscratch.org. The support channel is named #LFS-support. 1.3.5. References For additional information on the packages, useful tips are available in the LFS Package Reference page located at [174]http://www.linuxfromscratch.org/~matthew/LFS-references.html. 1.3.6. 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 [175]http://www.linuxfromscratch.org/mirrors.html for a list of current mirrors. 1.3.7. Contact Information Please direct all your questions and comments to one of the LFS mailing lists (see above). 1.4. Help If an issue or a question is encountered while working through this book, check the FAQ page at [176]http://www.linuxfromscratch.org/faq/#generalfaq. Questions are often already answered there. If your question is not answered on this page, try to find the source of the problem. The following hint will give you some guidance for troubleshooting: [177]http://www.linuxfromscratch.org/hints/downloads/files/errors.txt. If you cannot find your problem listed in the FAQ, search the mailing lists at [178]http://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 [179]Section 1.3, "Resources" section of this book). However, we get several support questions everyday and many of them can be easily answered by going to the FAQ and by searching the mailing lists first. So for us to offer the best assistance possible, you need to do some research on your own first. That allows us to focus on the more unusual support needs. If your searches do not produce a solution, please include all relevant information (mentioned below) in your request for help. 1.4.1. Things to Mention Apart from a brief explanation of the problem being experienced, the essential things to include in any request for help are: * The version of the book being used (in this case 6.1.1) * The host distribution and version being used to create LFS * The package or section the problem was encountered in * The exact error message or symptom being received * 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 upfront about any changes to the established procedure helps us evaluate and determine possible causes of your problem. 1.4.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. 1.4.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 enough of the relevant information. Below is an example of the type of information to include from the screen output from make: 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 properly 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 the associated error message(s). An excellent article about asking for help on the Internet is available online at [180]http://catb.org/~esr/faqs/smart-questions.html. Read and follow the hints in this document to increase the likelihood of getting the help you need. Part II. Preparing for the Build Table of Contents * 2. Preparing a New Partition + [181]Introduction + [182]Creating a New Partition + [183]Creating a File System on the Partition + [184]Mounting the New Partition * 3. Packages and Patches + [185]Introduction + [186]All Packages + [187]Needed Patches * 4. Final Preparations + [188]About $LFS + [189]Creating the $LFS/tools Directory + [190]Adding the LFS User + [191]Setting Up the Environment + [192]About SBUs + [193]About the Test Suites * 5. Constructing a Temporary System + [194]Introduction + [195]Toolchain Technical Notes + [196]Binutils-2.15.94.0.2.2 - Pass 1 + [197]GCC-3.4.3 - Pass 1 + [198]Linux-Libc-Headers-2.6.11.2 + [199]Glibc-2.3.4 + [200]Adjusting the Toolchain + [201]Tcl-8.4.9 + [202]Expect-5.43.0 + [203]DejaGNU-1.4.4 + [204]GCC-3.4.3 - Pass 2 + [205]Binutils-2.15.94.0.2.2 - Pass 2 + [206]Gawk-3.1.4 + [207]Coreutils-5.2.1 + [208]Bzip2-1.0.3 + [209]Gzip-1.3.5 + [210]Diffutils-2.8.1 + [211]Findutils-4.2.23 + [212]Make-3.80 + [213]Grep-2.5.1a + [214]Sed-4.1.4 + [215]Gettext-0.14.3 + [216]Ncurses-5.4 + [217]Patch-2.5.4 + [218]Tar-1.15.1 + [219]Texinfo-4.8 + [220]Bash-3.0 + [221]M4-1.4.3 + [222]Bison-2.0 + [223]Flex-2.5.31 + [224]Util-linux-2.12q + [225]Perl-5.8.7 + [226]Stripping Chapter 2. Preparing a New Partition 2.1. Introduction In this chapter, the 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. 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. However, an LFS system (in fact even multiple LFS systems) may also be installed on a partition already occupied by another operating system and the different systems will co-exist peacefully. The document [227]http://www.linuxfromscratch.org/hints/downloads/files/lfs_next_to _existing_systems.txt explains how to implement this, whereas this book discusses the method of using a fresh partition for the installation. A minimal system requires a partition of around 1.3 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 (2-3 GB). The LFS system itself will not take up this much room. A large portion of this requirement is to provide sufficient free temporary storage. 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. 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/hda for the primary Integrated Drive Electronics (IDE) disk. 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. Remember the designation of the new partition (e.g., hda5). 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.3. Creating a File System on the Partition Now that a blank partition has been set up, the file system can be created. The most widely-used system in the Linux world is the second extended file system (ext2), but with newer high-capacity hard disks, journaling file systems are becoming increasingly popular. We will create an ext2 file system. Build instructions for other file systems can be found at [228]http://www.linuxfromscratch.org/blfs/view/svn/postlfs/filesystems .html. To create an ext2 file system on the LFS partition, run the following: mke2fs -v /dev/[xxx] Replace [xxx] with the name of the LFS partition (hda5 in our previous example). Note Some host distributions use custom features in their filesystem creation tools (e2fsprogs). This can cause problems when booting into your new LFS in Chapter 9, as those features will not be supported by the LFS-installed e2fsprogs; you will get an error similar to "unsupported filesystem features, upgrade your e2fsprogs". To check if your host system uses custom enhancements, run the following command: debugfs -R feature /dev/[xxx] If the output contains features other than: dir_index; filetype; large_file; resize_inode or sparse_super then your host system may have custom enhancements. In that case, to avoid later problems, you should compile the stock e2fsprogs package and use the resulting binaries to re-create the filesystem on your LFS partition: cd /tmp tar -xjvf /path/to/sources/e2fsprogs-1.37.tar.bz2 cd e2fsprogs-1.37 mkdir -v build cd build ../configure make #note that we intentionally don't 'make install' here! ./misc/mke2fs -v /dev/[xxx] cd /tmp rm -rfv e2fsprogs-1.37 If a swap partition was created, it will need to be initialized for use by issuing the command below. If you are using an existing swap partition, there is no need to format it. mkswap -v /dev/[yyy] Replace [yyy] with the name of the swap partition. 2.4. Mounting the New Partition Now that a file system has been created, the partition needs to be made accessible. In order to do this, the partition needs to be mounted at a chosen mount point. For the purposes of this book, it is assumed that the file system is mounted under /mnt/lfs, but the directory choice is up to you. Choose a mount point and assign it to the LFS environment variable by running: export LFS=/mnt/lfs Next, create the mount point and mount the LFS file system by running: mkdir -pv $LFS mount -v /dev/[xxx] $LFS Replace [xxx] with the designation of the LFS partition. If using multiple partitions for LFS (e.g., one for / and another for /usr), mount them using: mkdir -pv $LFS mount -v /dev/[xxx] $LFS mkdir -v $LFS/usr mount -v /dev/[yyy] $LFS/usr 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, nodev, or noatime options). Run the mount command without any parameters to see what options are set for the mounted LFS partition. If nosuid, nodev, and/or noatime are set, the partition will need to be remounted. Now that there is an established place to work, it is time to download the packages. Chapter 3. Packages and Patches 3.1. Introduction This chapter includes a list of packages that need to be downloaded for building 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 not using newer versions because the build commands for one version may not work with a newer version. 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. Download locations may not always be accessible. If a download location has changed since this book was published, Google ([229]http://www.google.com/) provides a useful search engine for most packages. If this search is unsuccessful, try one of the alternative means of downloading discussed at [230]http://www.linuxfromscratch.org/lfs/packages.html. 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, as user root, the following command 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 3.2. All Packages Download or otherwise obtain the following packages: Autoconf (2.59) - 908 kilobytes (KB): [231]http://ftp.gnu.org/gnu/autoconf/ Automake (1.9.5) - 748 KB: [232]http://ftp.gnu.org/gnu/automake/ Bash (3.0) - 1,824 KB: [233]http://ftp.gnu.org/gnu/bash/ Bash Documentation (3.0) - 1,994 KB: [234]http://ftp.gnu.org/gnu/bash/ Binutils (2.15.94.0.2.2) - 11,056 KB: [235]http://www.kernel.org/pub/linux/devel/binutils/ Bison (2.0) - 916 KB: [236]http://ftp.gnu.org/gnu/bison/ Bzip2 (1.0.3) - 596 KB: [237]http://www.bzip.org/ Coreutils (5.2.1) - 4,184 KB: [238]http://ftp.gnu.org/gnu/coreutils/ DejaGNU (1.4.4) - 852 KB: [239]http://ftp.gnu.org/gnu/dejagnu/ Diffutils (2.8.1) - 648 KB: [240]http://ftp.gnu.org/gnu/diffutils/ E2fsprogs (1.37) - 3,100 KB: [241]http://prdownloads.sourceforge.net/e2fsprogs/ Expect (5.43.0) - 416 KB: [242]http://expect.nist.gov/src/ File (4.13) - 324 KB: [243]ftp://ftp.gw.com/mirrors/pub/unix/file/ Note File (4.13) may no longer be available at the listed location. The site administrators of the master download location occasionally remove older versions when new ones are released. An alternative download location that may have the correct version available can also be found at: [244]http://www.linuxfromscratch.org/lfs/download.html#ftp. Findutils (4.2.23) - 784 KB: [245]http://ftp.gnu.org/gnu/findutils/ Flex (2.5.31) - 672 KB: [246]http://prdownloads.sourceforge.net/lex/ Gawk (3.1.4) - 1,696 KB: [247]http://ftp.gnu.org/gnu/gawk/ GCC (3.4.3) - 26,816 KB: [248]http://ftp.gnu.org/gnu/gcc/ Gettext (0.14.3) - 4,568 KB: [249]http://ftp.gnu.org/gnu/gettext/ Glibc (2.3.4) - 12,924 KB: [250]http://ftp.gnu.org/gnu/glibc/ Glibc-Linuxthreads (2.3.4) - 236 KB: [251]http://ftp.gnu.org/gnu/glibc/ Grep (2.5.1a) - 520 KB: [252]http://ftp.gnu.org/gnu/grep/ Groff (1.19.1) - 2,096 KB: [253]http://ftp.gnu.org/gnu/groff/ GRUB (0.96) - 768 KB: [254]ftp://alpha.gnu.org/gnu/grub/ Gzip (1.3.5) - 284 KB: [255]ftp://alpha.gnu.org/gnu/gzip/ Hotplug (2004_09_23) - 40 KB: [256]http://www.kernel.org/pub/linux/utils/kernel/hotplug/ Iana-Etc (1.04) - 176 KB: [257]http://www.sethwklein.net/projects/iana-etc/downloads/ Inetutils (1.4.2) - 752 KB: [258]http://ftp.gnu.org/gnu/inetutils/ IPRoute2 (2.6.11-050330) - 276 KB: [259]http://developer.osdl.org/dev/iproute2/download/ Kbd (1.12) - 624 KB: [260]http://www.kernel.org/pub/linux/utils/kbd/ Less (382) - 216 KB: [261]http://ftp.gnu.org/gnu/less/ LFS-Bootscripts (3.2.1) - 32 KB: [262]http://downloads.linuxfromscratch.org/ Libtool (1.5.14) - 1,604 KB: [263]http://ftp.gnu.org/gnu/libtool/ Linux (2.6.11.12) - 35,792 KB: [264]http://www.kernel.org/pub/linux/kernel/v2.6/ Linux-Libc-Headers (2.6.11.2) - 2,476 KB: [265]http://ep09.pld-linux.org/~mmazur/linux-libc-headers/ M4 (1.4.3) - 304 KB: [266]http://ftp.gnu.org/gnu/m4/ Make (3.80) - 904 KB: [267]http://ftp.gnu.org/gnu/make/ Man (1.5p) - 208 KB: [268]http://www.kernel.org/pub/linux/utils/man/ Man-pages (2.01) - 1,640 KB: [269]http://www.kernel.org/pub/linux/docs/manpages/ Mktemp (1.5) - 68 KB: [270]ftp://ftp.mktemp.org/pub/mktemp/ Module-Init-Tools (3.1) - 128 KB: [271]http://www.kernel.org/pub/linux/utils/kernel/module-init-t ools/ Module-Init-Tools-Testsuite (3.1) - 34 KB: [272]http://www.kernel.org/pub/linux/utils/kernel/module-init-t ools/ Ncurses (5.4) - 1,556 KB: [273]ftp://invisible-island.net/ncurses/ Patch (2.5.4) - 156 KB: [274]http://ftp.gnu.org/gnu/patch/ Perl (5.8.7) - 9,628 KB: [275]http://ftp.funet.fi/pub/CPAN/src/ Procps (3.2.5) - 224 KB: [276]http://procps.sourceforge.net/ Psmisc (21.6) - 188 KB: [277]http://prdownloads.sourceforge.net/psmisc/ Readline (5.0) - 1,456 KB: [278]http://ftp.gnu.org/gnu/readline/ Sed (4.1.4) - 632 KB: [279]http://ftp.gnu.org/gnu/sed/ Shadow (4.0.9) - 1,084 KB: [280]ftp://ftp.pld.org.pl/software/shadow/ Note Shadow (4.0.9) may no longer be available at the listed location. The site administrators of the master download location occasionally remove older versions when new ones are released. An alternative download location that may have the correct version available cat also be found at: [281]http://www.linuxfromscratch.org/lfs/download.html#ftp. Sysklogd (1.4.1) - 72 KB: [282]http://www.infodrom.org/projects/sysklogd/download/ Sysvinit (2.86) - 88 KB: [283]ftp://ftp.cistron.nl/pub/people/miquels/sysvinit/ Tar (1.15.1) - 1,580 KB: [284]http://ftp.gnu.org/gnu/tar/ Tcl (8.4.9) - 2,748 KB: [285]http://prdownloads.sourceforge.net/tcl/ Texinfo (4.8) - 1,492 KB: [286]http://ftp.gnu.org/gnu/texinfo/ Udev (056) - 476 KB: [287]http://www.kernel.org/pub/linux/utils/kernel/hotplug/ Udev Rules Configuration - 5 KB: [288]http://downloads.linuxfromscratch.org/udev-config-4.rules Util-linux (2.12q) - 1,344 KB: [289]http://www.kernel.org/pub/linux/utils/util-linux/ Vim (6.3) - 3,620 KB: [290]ftp://ftp.vim.org/pub/vim/unix/ Vim (6.3) language files (optional) - 540 KB: [291]ftp://ftp.vim.org/pub/vim/extra/ Zlib (1.2.3) - 415 KB: [292]http://www.zlib.net/ Total size of these packages: 146 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 Avoid Wcontinued Patch - 1 KB: [293]http://www.linuxfromscratch.org/patches/lfs/6.1.1/bash-3.0 -avoid_WCONTINUED-1.patch Bash Various Fixes - 23 KB: [294]http://www.linuxfromscratch.org/patches/lfs/6.1.1/bash-3.0 -fixes-3.patch Binutils Build From Host Running Gcc4 Patch - 2 KB: [295]http://www.linuxfromscratch.org/patches/lfs/6.1.1/binutils -2.15.94.0.2.2-gcc4-1.patch Bzip2 Documentation Patch - 1 KB: [296]http://www.linuxfromscratch.org/patches/lfs/6.1.1/bzip2-1. 0.3-install_docs-1.patch Bzip2 Bzgrep Security Fixes Patch - 1 KB: [297]http://www.linuxfromscratch.org/patches/lfs/6.1.1/bzip2-1. 0.3-bzgrep_security-1.patch Coreutils Suppress Uptime, Kill, Su Patch - 15 KB: [298]http://www.linuxfromscratch.org/patches/lfs/6.1.1/coreutil s-5.2.1-suppress_uptime_kill_su-1.patch Coreutils Uname Patch - 4 KB: [299]http://www.linuxfromscratch.org/patches/lfs/6.1.1/coreutil s-5.2.1-uname-2.patch Expect Spawn Patch - 7 KB: [300]http://www.linuxfromscratch.org/patches/lfs/6.1.1/expect-5 .43.0-spawn-1.patch Flex Brokenness Patch - 156 KB: [301]http://www.linuxfromscratch.org/patches/lfs/6.1.1/flex-2.5 .31-debian_fixes-3.patch GCC Linkonce Patch - 12 KB: [302]http://www.linuxfromscratch.org/patches/lfs/6.1.1/gcc-3.4. 3-linkonce-1.patch GCC No-Fixincludes Patch - 1 KB: [303]http://www.linuxfromscratch.org/patches/lfs/6.1.1/gcc-3.4. 3-no_fixincludes-1.patch GCC Specs Patch - 14 KB: [304]http://www.linuxfromscratch.org/patches/lfs/6.1.1/gcc-3.4. 3-specs-2.patch Glibc Rtld Search Dirs Patch - 1 KB: [305]http://www.linuxfromscratch.org/patches/lfs/6.1.1/glibc-2. 3.4-rtld_search_dirs-1.patch Glibc Fix Testsuite Patch - 1 KB: [306]http://www.linuxfromscratch.org/patches/lfs/6.1.1/glibc-2. 3.4-fix_test-1.patch Glibc TLS Assertion Patch - 6 KB: [307]http://www.linuxfromscratch.org/patches/lfs/6.1.1/glibc-2. 3.4-tls_assert-1.patch Gzip Security Patch - 2 KB: [308]http://www.linuxfromscratch.org/patches/lfs/6.1.1/gzip-1.3 .5-security_fixes-1.patch Inetutils Kernel Headers Patch - 1 KB: [309]http://www.linuxfromscratch.org/patches/lfs/6.1.1/inetutil s-1.4.2-kernel_headers-1.patch Inetutils No-Server-Man-Pages Patch - 4 KB: [310]http://www.linuxfromscratch.org/patches/lfs/6.1.1/inetutil s-1.4.2-no_server_man_pages-1.patch Mktemp Tempfile Patch - 3 KB: [311]http://www.linuxfromscratch.org/patches/lfs/6.1.1/mktemp-1 .5-add_tempfile-2.patch Perl Libc Patch - 1 KB: [312]http://www.linuxfromscratch.org/patches/lfs/6.1.1/perl-5.8 .7-libc-1.patch Readline Fixes Patch - 7 KB: [313]http://www.linuxfromscratch.org/patches/lfs/6.1.1/readline -5.0-fixes-1.patch Sysklogd Fixes Patch - 27 KB: [314]http://www.linuxfromscratch.org/patches/lfs/6.1.1/sysklogd -1.4.1-fixes-1.patch Tar Sparse Fix Patch - 1 KB: [315]http://www.linuxfromscratch.org/patches/lfs/6.1.1/tar-1.15 .1-sparse_fix-1.patch Texinfo Tempfile Fix Patch - 2 KB: [316]http://www.linuxfromscratch.org/patches/lfs/6.1.1/texinfo- 4.8-tempfile_fix-1.patch Util-linux Cramfs Patch - 3 KB: [317]http://www.linuxfromscratch.org/patches/lfs/6.1.1/util-lin ux-2.12q-cramfs-1.patch Util-linux Umount Patch - 1 KB: [318]http://www.linuxfromscratch.org/patches/lfs/6.1.1/util-lin ux-2.12q-umount_fix-1.patch Vim Security Patch - 8 KB: [319]http://www.linuxfromscratch.org/patches/lfs/6.1.1/vim-6.3- security_fix-2.patch 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 [320]http://www.linuxfromscratch.org/patches/ and acquire any additional patches to suit the system needs. Chapter 4. Final Preparations 4.1. About $LFS Throughout this book, the environment variable LFS will be used several times. It is paramount that this variable is always defined. It should be set to the mount point chosen for the LFS partition. Check that the LFS variable is set up properly with: echo $LFS Make sure the output shows the path to the LFS partition's mount point, which is /mnt/lfs if the provided example was followed. If the output is incorrect, the variable can be set with: export LFS=/mnt/lfs Having this variable set is beneficial in that commands such as mkdir $LFS/tools can be typed literally. The shell will automatically replace "$LFS" with "/mnt/lfs" (or whatever the variable was set to) when it processes the command line. Do not forget to check that $LFS is set whenever you leave and reenter the current working environment (as when doing a "su" to root or another user). 4.2. Creating the $LFS/tools Directory All programs compiled in [321]Chapter 5 will be installed under $LFS/tools to keep them separate from the programs compiled in [322]Chapter 6. The programs compiled here are temporary tools and will not be a part of the final LFS system. By keeping these programs in a separate directory, they can easily be discarded later after their use. This also prevents these programs from ending up in the host production directories (easy to do by accident in [323]Chapter 5). Create the required directory by running the following as root: mkdir -v $LFS/tools The next step is to create a /tools symlink on the host system. This will point to the newly-created directory on the LFS partition. Run this command as root as well: ln -sv $LFS/tools / Note The above command is correct. The ln command has a few syntactic variations, so be sure to check info coreutils ln and ln(1) before reporting what you may think is an error. The created symlink enables the toolchain to be compiled so that it always refers to /tools, meaning that the compiler, assembler, and linker will work both in this chapter (when we are still using some tools from the host) and in the next (when we are "chrooted" to the LFS partition). 4.3. Adding the LFS User When logged in as user root, making a single mistake can damage or destroy a system. Therefore, we recommend building the packages in this chapter as an unprivileged user. You could use your own user name, but to make it easier to set up a clean working environment, create a new user called lfs as a member of a new group (also named lfs) and use this user 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 The meaning of the command line options: -s /bin/bash This makes bash the default shell for user lfs. -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 (default is /etc/skel) by changing the input location to the special null device. lfs This is the actual name for the created group and user. To log in as lfs (as opposed to switching to user lfs when logged in as root, which does not require the lfs user to have a password), give lfs a password: passwd lfs Grant lfs full access to $LFS/tools by making lfs the directory owner: chown -v lfs $LFS/tools If a separate working directory was created as suggested, give user lfs ownership of this directory: chown -v lfs $LFS/sources Next, login as user lfs. This can be done via a virtual console, through a display manager, or with the following substitute 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 can be found 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, the initial shell is usually 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. The technique used here achieves the goal of ensuring a clean environment. The new instance of the shell is a non-login shell, which does not read the /etc/profile or .bash_profile files, but rather reads the .bashrc file instead. Create the .bashrc file now: cat > ~/.bashrc << "EOF" set +h umask 022 LFS=/mnt/lfs LC_ALL=POSIX PATH=/tools/bin:/bin:/usr/bin export LFS LC_ALL PATH EOF 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 of 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. By switching off the hash function, the shell will always search the PATH when a program is to be run. As such, the shell will find the newly compiled tools in $LFS/tools as soon as they are available without remembering a previous version of the same program in a different location. 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). The LFS variable should be set to the chosen mount point. The LC_ALL variable controls the localization of certain programs, making their messages follow the conventions of a specified country. If the host system uses a version of Glibc older than 2.2.4, having LC_ALL set to something other than "POSIX" or "C" (during this chapter) may cause issues if you exit the chroot environment and wish to return later. Setting LC_ALL to "POSIX" or "C" (the two are equivalent) ensures that everything will work as expected in the chroot environment. By putting /tools/bin ahead of the standard PATH, all the programs installed in [324]Chapter 5 are picked up by the shell immediately after their installation. This, combined with turning off hashing, limits the risk that old programs are used from the host when the same programs are available in the chapter 5 environment. Finally, to have the environment fully prepared for building the temporary tools, source the just-created user profile: source ~/.bash_profile 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 accurate time estimates. The biggest package (Glibc) will take approximately 20 minutes on the fastest systems, but could take up to three 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 from this book is Binutils in [325]Chapter 5. The time it takes to compile this package is what will be referred to as the Standard Build Unit or SBU. All other compile times will be expressed relative to this time. For example, consider a package whose compilation time is 4.5 SBUs. This means that if a system took 10 minutes to compile and install the first pass of Binutils, it will take approximately 45 minutes to build this example package. Fortunately, most build times are shorter than the one for Binutils. In general, SBUs are not entirely accurate because they depend on many factors, including the host system's version of GCC. Note that on Symmetric Multi-Processor (SMP)-based machines, SBUs are even less accurate. 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. To view actual timings for a number of specific machines, we recommend The LinuxFromScratch SBU Home Page at [326]http://www.linuxfromscratch.org/~bdubbs/. 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 Experience has shown that there is little to be gained from running the test suites in [327]Chapter 5. There can be no escaping the fact that the host system always exerts some influence on the tests in that chapter, often causing inexplicable failures. Because the tools built in [328]Chapter 5 are temporary and eventually discarded, we do not recommend running the test suites in [329]Chapter 5 for the average reader. The instructions for running those test suites are provided for the benefit of testers and developers, but they are strictly optional. A common issue with running the test suites for Binutils and GCC is running out of pseudo terminals (PTYs). This can result in a high 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 in [330]Chapter 5. Sometimes package test suites will fail, but for reasons which the developers are aware of and have deemed non-critical. Consult the logs located at [331]http://www.linuxfromscratch.org/lfs/build-logs/6.1.1/ to verify whether or not these failures are expected. This site is valid for all tests throughout this book. Chapter 5. Constructing a Temporary System 5.1. Introduction This chapter shows how to compile and install a minimal Linux system. This system will contain just enough tools to start constructing the final LFS system in [332]Chapter 6 and allow a working environment with more user convenience than a minimum environment would. There are two steps in building this minimal system. The first step is to build a new and host-independent toolchain (compiler, assembler, linker, libraries, and a few useful utilities). The second step uses this toolchain to build the other essential tools. The files compiled in this chapter will be installed under the $LFS/tools directory to keep them separate from the files installed in the next chapter and the host production directories. Since the packages compiled here are temporary, we do not want them to pollute the soon-to-be LFS system. Important Before issuing the build instructions for a package, the package should be unpacked as user lfs, and a cd into the created directory should be performed. The build instructions assume that the bash shell is in use. Several of the packages are patched before compilation, but only when the patch is needed to circumvent a problem. A patch is often needed in both this and the next chapter, but sometimes in only one or the other. 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, as the patch was still successfully applied. During the compilation of most packages, there will be several warnings that scroll by on the screen. These are normal and can safely be ignored. These warnings are as they appear--warnings about deprecated, but not invalid, use of the C or C++ syntax. C standards change fairly often, and some packages still use the older standard. This is not a problem, but does prompt the warning. Important After installing each package, delete its source and build directories, unless specifically instructed otherwise. Deleting the sources prevents mis-configuration when the same package is reinstalled later. Only three of the packages need to retain the source and build directories in order for their contents to be used by later commands. Pay special attention to these reminders. 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. 5.2. Toolchain Technical Notes This section explains some of the rationale and technical details behind the overall build method. It is not essential to immediately understand everything in this section. Most of this information will be clearer after performing an actual build. This section can be referred back to at any time during the process. The overall goal of [333]Chapter 5 is to provide a temporary environment that can be chrooted into and from which can be produced a clean, trouble-free build of the target LFS system in [334]Chapter 6. Along the way, we separate the new system from the host system as much as possible, and in doing so, build a self-contained and self-hosted toolchain. It should be noted that the build process has been designed to minimize the risks for new readers and provide maximum educational value at the same time. Important Before continuing, be aware of the name of the working platform, often referred to as the target triplet. Many times, the target triplet will probably be i686-pc-linux-gnu. A simple way to determine the name of the target triplet is to run the config.guess script that comes with the source for many packages. Unpack the Binutils sources and run the script: ./config.guess and note the output. 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 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 will usually be ld-linux.so.2. On platforms that are less prevalent, the name might be ld.so.1, and newer 64 bit platforms might be named something else entirely. The name of the platform's dynamic linker can be determined by looking in the /lib directory on the host system. A sure-fire way to determine the name is to inspect a random binary from the host system by running: readelf -l | 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. Some key technical points of how the [335]Chapter 5 build method works: * The process is similar in principle to cross-compiling, whereby tools installed in the same prefix work in cooperation, and thus utilize a little GNU "magic" * Careful manipulation of the standard linker's library search path ensures programs are linked only against chosen libraries * Careful manipulation of gcc's specs file tells the compiler which target dynamic linker will be used 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 first realize. 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, /tools/bin and /tools/$TARGET_TRIPLET/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, an ld --verbose | grep SEARCH will illustrate the current search paths and their order. It shows which files are linked by ld by compiling a dummy program and passing the --verbose switch to the linker. For example, gcc dummy.c -Wl,--verbose 2>&1 | grep succeeded will show all the files successfully opened during the linking. The next package installed is GCC. An example of what can be seen during its run of configure is: checking what assembler to use... /tools/i686-pc-linux-gnu/bin/as checking what linker to use... /tools/i686-pc-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: gcc -print-prog-name=ld. Detailed information can be obtained from gcc by passing it the -v command line option while compiling a dummy program. For example, gcc -v dummy.c will show detailed information about the preprocessor, compilation, and assembly stages, including gcc's included search paths and their order. The next package installed is 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 gcc found in a PATH directory. The binary tools and kernel headers can be a bit more complicated. Therefore, 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 glibc-build directory for all important details. Note the use of CC="gcc -B/tools/bin/" 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. After the Glibc installation, make some adjustments to ensure that searching and linking take place only within the /tools prefix. Install an adjusted ld, which has a hard-wired search path limited to /tools/lib. Then amend gcc's specs file to point to the new dynamic linker in /tools/lib. This last step is vital to the whole process. As mentioned above, a hard-wired path to a dynamic linker is embedded into every Executable and Link Format (ELF)-shared executable. This can be inspected by running: readelf -l | grep interpreter. Amending gcc's specs file ensures that every program compiled from here through the end of this chapter will use the new dynamic linker in /tools/lib. The need to use the new dynamic linker is also the reason why the Specs patch is applied for the second pass of GCC. Failure to do so will result in the GCC programs themselves having the name of the dynamic linker from the host system's /lib directory embedded into them, which would defeat the goal of getting away from the host. During the second pass of Binutils, we are able to utilize the --with-lib-path configure switch to control ld's library search path. From this point onwards, the core toolchain is self-contained and self-hosted. The remainder of the [336]Chapter 5 packages all build against the new Glibc in /tools. Upon entering the chroot environment in [337]Chapter 6, the first major package to be installed is Glibc, due to its self-sufficient nature mentioned above. Once this Glibc is installed into /usr, perform a quick changeover of the toolchain defaults, then proceed in building the rest of the target LFS system. 5.3. Binutils-2.15.94.0.2.2 - Pass 1 The Binutils package contains a linker, an assembler, and other tools for handling object files. Approximate build time: 1.0 SBU Required disk space: 179 MB Installation depends on: Bash, Bison, Coreutils, Diffutils, Flex, GCC, Gettext, Glibc, Grep, M4, Make, Perl, Sed, and Texinfo 5.3.1. Installation of Binutils 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. This package is known to have issues when its default optimization flags (including the -march and -mcpu options) are changed. If any environment variables that override default optimizations have been defined, such as CFLAGS and CXXFLAGS, unset them when building Binutils. If you are building from a host running Gcc-4 or later, it is necessary to patch the first build of this version of Binutils so that it can be compiled by the host system. patch -Np1 -i ../binutils-2.15.94.0.2.2-gcc4-1.patch The Binutils documentation recommends building Binutils outside of the source directory in a dedicated build directory: mkdir -v ../binutils-build cd ../binutils-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 three commands in a time command like this: time { ./configure ... && make && make install; }. Now prepare Binutils for compilation: ../binutils-2.15.94.0.2.2/configure --prefix=/tools --disable-nls The meaning of the configure options: --prefix=/tools This tells the configure script to prepare to install the Binutils programs in the /tools directory. --disable-nls This disables internationalization as i18n is not needed for the temporary tools. Continue with compiling the package: make Compilation is now complete. Ordinarily we would now run the test suite, but at this early stage the test suite framework (Tcl, Expect, and DejaGNU) is not yet in place. The benefits of running the tests at this point are minimal since the programs from this first pass will soon be replaced by those from the second. Install the package: make install Next, prepare the linker for the "Adjusting" phase later on: make -C ld clean make -C ld LIB_PATH=/tools/lib The meaning of the make parameters: -C ld clean This tells the make program to remove all compiled files in the ld subdirectory. -C ld LIB_PATH=/tools/lib This option rebuilds everything in the ld subdirectory. Specifying the LIB_PATH Makefile variable on the command line allows us to override the default value and point it to the temporary tools location. The value of this variable specifies the linker's default library search path. This preparation is used later in the chapter. Warning Do not remove the Binutils build and source directories yet. These will be needed again in their current state later in this chapter. Details on this package are located in [338]Section 6.13.2, "Contents of Binutils." 5.4. GCC-3.4.3 - Pass 1 The GCC package contains the GNU compiler collection, which includes the C and C++ compilers. Approximate build time: 4.4 SBU Required disk space: 219 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, Findutils, Gawk, Gettext, Glibc, Grep, Make, Perl, Sed, and Texinfo 5.4.1. Installation of GCC This package is known to have issues when its default optimization flags (including the -march and -mcpu options) are changed. If any environment variables that override default optimizations have been defined, such as CFLAGS and CXXFLAGS, unset them when building GCC. The GCC documentation recommends building GCC outside of the source directory in a dedicated build directory: mkdir -v ../gcc-build cd ../gcc-build Prepare GCC for compilation: ../gcc-3.4.3/configure --prefix=/tools \ --libexecdir=/tools/lib --with-local-prefix=/tools \ --disable-nls --enable-shared --enable-languages=c The meaning of the configure options: --with-local-prefix=/tools The purpose of this switch is to remove /usr/local/include from gcc's include search path. This is not absolutely essential, however, it helps to minimize the influence of the host system. --enable-shared This switch allows the building of libgcc_s.so.1 and libgcc_eh.a. Having libgcc_eh.a available ensures that the configure script for Glibc (the next package we compile) produces the proper results. --enable-languages=c This option ensures that only the C compiler is built. Continue with compiling the package: make bootstrap The meaning of the make parameters: bootstrap This target does not just compile GCC, but compiles it several times. It uses the programs compiled in a first round to compile itself a second time, and then again a third time. It then compares these second and third compiles to make sure it can reproduce itself flawlessly. This also implies that it was compiled correctly. Compilation is now complete. At this point, the test suite would normally be run, but, as mentioned before, the test suite framework is not in place yet. The benefits of running the tests at this point are minimal since the programs from this first pass will soon be replaced. Install the package: make install As a finishing touch, create a 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 -vs gcc /tools/bin/cc Details on this package are located in [339]Section 6.14.2, "Contents of GCC." 5.5. Linux-Libc-Headers-2.6.11.2 The Linux-Libc-Headers package contains the "sanitized" kernel headers. Approximate build time: 0.1 SBU Required disk space: 26.9 MB Installation depends on: Coreutils 5.5.1. Installation of Linux-Libc-Headers For years it has been common practice to use "raw" kernel headers (straight from a kernel tarball) in /usr/include, but over the last few years, the kernel developers have taken a strong stance that this should not be done. This gave birth to the Linux-Libc-Headers Project, which was designed to maintain an Application Programming Interface (API) stable version of the Linux headers. Install the header files: cp -Rv include/asm-i386 /tools/include/asm cp -Rv include/linux /tools/include If your architecture is not i386 (compatible), adjust the first command accordingly. Details on this package are located in [340]Section 6.9.2, "Contents of Linux-Libc-Headers." 5.6. Glibc-2.3.4 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: 11.8 SBU Required disk space: 454 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, Gawk, GCC, Gettext, Grep, Make, Perl, Sed, and Texinfo 5.6.1. Installation of Glibc This package is known to have issues when its default optimization flags (including the -march and -mcpu options) are changed. If any environment variables that override default optimizations have been defined, such as CFLAGS and CXXFLAGS, unset them when building Glibc. It should be noted that compiling Glibc in any way other than the method suggested in this book puts the stability of the system at risk. Glibc has two tests which fail when the running kernel is 2.6.11 or later. The problem has been determined to be with the tests themselves, not with the C library or the kernel. If you plan to run the testsuite apply this patch: patch -Np1 -i ../glibc-2.3.4-fix_test-1.patch The Glibc documentation recommends building Glibc outside of the source directory in a dedicated build directory: mkdir -v ../glibc-build cd ../glibc-build Next, prepare Glibc for compilation: ../glibc-2.3.4/configure --prefix=/tools \ --disable-profile --enable-add-ons \ --enable-kernel=2.6.0 --with-binutils=/tools/bin \ --without-gd --with-headers=/tools/include \ --without-selinux The meaning of the configure options: --disable-profile This builds the libraries without profiling information. Omit this option if profiling on the temporary tools is necessary. --enable-add-ons This tells Glibc to use the NPTL add-on as its threading library. --enable-kernel=2.6.0 This tells Glibc to compile the library with support for 2.6.x Linux kernels. --with-binutils=/tools/bin While not required, this switch ensures that there are no errors pertaining to which Binutils programs get used during the Glibc build. --without-gd This prevents the build of the memusagestat program, which insists on linking against the host's libraries (libgd, libpng, libz, etc.). --with-headers=/tools/include This tells Glibc to compile itself against the headers recently installed to the tools directory, so that it knows exactly what features the kernel has and can optimize itself accordingly. --without-selinux When building from hosts that include SELinux functionality (e.g. Fedora Core 3), Glibc will build with support for SELinux. As the LFS tools environment does not contain support for SELinux, a Glibc compiled with such support will fail to operate correctly. 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, but it can sometimes cause issues when running the test suite. This msgfmt program is part of the Gettext package which the host distribution should provide. If msgfmt is present but deemed incompatible, upgrade the host system's Gettext package or continue without it and see if the test suite runs without problems regardless. Compile the package: make Compilation is now complete. As mentioned earlier, running the test suites for the temporary tools installed in this chapter is not mandatory. To run the Glibc test suite (if desired), the following command will do so: make check For a discussion of test failures that are of particular importance, please see [341]Section 6.11, "Glibc-2.3.4." In this chapter, some tests can be adversely affected by existing tools or environmental issues on the host system. Glibc test suite failures in this chapter are typically not worrisome. The Glibc installed in [342]Chapter 6 is the one that will ultimately end up being used, so that is the one that needs to pass most tests (even in [343]Chapter 6, some failures could still occur, for example, with the math tests). When experiencing a failure, make a note of it, then continue by reissuing the make check command. The test suite should pick up where it left off and continue. This stop-start sequence can be circumvented by issuing a make -k check command. If using this option, be sure to log the output so that the log file can be examined for failures later. The install stage of Glibc will issue a harmless warning at the end about the absence of /tools/etc/ld.so.conf. Prevent this warning with: mkdir -v /tools/etc touch /tools/etc/ld.so.conf Install the package: make install Different countries and cultures have varying conventions for how to communicate. These conventions range from the format for representing dates and times to more complex issues, such as the language spoken. The "internationalization" of GNU programs works by locale. Note If the test suites are not being run in this chapter (as per the recommendation), there is no need to install the locales now. The appropriate locales will be installed in the next chapter. To install the Glibc locales anyway, use the following command: make localedata/install-locales To save time, an alternative to running the previous command (which generates and installs every locale Glibc is aware of) is to install only those locales that are wanted and needed. This can be achieved by using the localedef command. Information on this command is located in the INSTALL file in the Glibc source. However, there are a number of locales that are essential in order for the tests of future packages to pass, in particular, the libstdc++ tests from GCC. The following instructions, instead of the install-locales target used above, will install the minimum set of locales necessary for the tests to run successfully: mkdir -pv /tools/lib/locale localedef -i de_DE -f ISO-8859-1 de_DE localedef -i de_DE@euro -f ISO-8859-15 de_DE@euro localedef -i en_HK -f ISO-8859-1 en_HK localedef -i en_PH -f ISO-8859-1 en_PH localedef -i en_US -f ISO-8859-1 en_US localedef -i es_MX -f ISO-8859-1 es_MX localedef -i fa_IR -f UTF-8 fa_IR localedef -i fr_FR -f ISO-8859-1 fr_FR localedef -i fr_FR@euro -f ISO-8859-15 fr_FR@euro localedef -i it_IT -f ISO-8859-1 it_IT localedef -i ja_JP -f EUC-JP ja_JP Details on this package are located in [344]Section 6.11.4, "Contents of Glibc." 5.7. Adjusting the Toolchain Now that the temporary C libraries have been installed, all tools compiled in the rest of this chapter should be linked against these libraries. In order to accomplish this, the linker and the compiler's specs file need to be adjusted. The linker, adjusted at the end of the first pass of Binutils, is installed by running the following command from within the binutils-build directory: make -C ld install From this point onwards, everything will link only against the libraries in /tools/lib. Note If the earlier warning to retain the Binutils source and build directories from the first pass was missed, ignore the above command. This results in a small chance that the subsequent testing programs will link against libraries on the host. This is not ideal, but it is not a major problem. The situation is corrected when the second pass of Binutils is installed later. Now that the adjusted linker is installed, the Binutils build and source directories should be removed. The next task is to amend the GCC specs file so that it points to the new dynamic linker. A simple sed script will accomplish this: SPECFILE=`gcc --print-file specs` && sed 's@ /lib/ld-linux.so.2@ /tools/lib/ld-linux.so.2@g' \ $SPECFILE > tempspecfile && mv -f tempspecfile $SPECFILE && unset SPECFILE It is recommended that the above command be copy-and-pasted in order to ensure accuracy. Alternatively, the specs file can be edited by hand. This is done by replacing every occurrence of "/lib/ld-linux.so.2" with "/tools/lib/ld-linux.so.2" Be sure to visually inspect the specs file in order to verify the intended changes have been made. Important If working on a platform where the name of the dynamic linker is something other than ld-linux.so.2, replace "ld-linux.so.2" with the name of the platform's dynamic linker in the above commands. Refer back to [345]Section 5.2, "Toolchain Technical Notes," if necessary. There is a possibility that some include files from the host system have found their way into GCC's private include dir. This can happen as a result of GCC's "fixincludes" process, which runs as part of the GCC build. This is explained in more detail later in this chapter. Run the following command to eliminate this possibility: rm -vf /tools/lib/gcc/*/*/include/{pthread.h,bits/sigthread.h} 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 'main(){}' > dummy.c cc dummy.c readelf -l a.out | grep ': /tools' 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: /tools/lib/ld-linux.so.2] Note that /tools/lib appears as the prefix of the dynamic linker. If the output is not shown as above or there was 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 on. First, perform the sanity check again, using gcc instead of cc. If this works, then the /tools/bin/cc symlink is missing. Revisit [346]Section 5.4, "GCC-3.4.3 - Pass 1," and install the symlink. Next, ensure that the PATH is correct. This can be checked by running echo $PATH and verifying that /tools/bin is at the head of the list. If the PATH is wrong it could mean that you are not logged in as user lfs or that something went wrong back in [347]Section 4.4, "Setting Up the Environment." Another option is that something may have gone wrong with the specs file amendment above. In this case, redo the specs file amendment, being careful to copy-and-paste the commands. Once all is well, clean up the test files: rm -v dummy.c a.out Building TCL in the next section will serve as an additional check that the toolchain has been built properly. If TCL fails to build, it is an indication that something has gone wrong with the Binutils, GCC, or Glibc installation, but not with TCL itself. 5.8. Tcl-8.4.9 The Tcl package contains the Tool Command Language. Approximate build time: 0.9 SBU Required disk space: 23.3 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, GCC, Glibc, Grep, Make, and Sed 5.8.1. Installation of Tcl This package and the next two (Expect and DejaGNU) are installed to support running the test suites for GCC and Binutils. Installing three packages for testing purposes may seem excessive, but it is very reassuring, if not essential, to know that the most important tools are working properly. Even if the test suites are not run in this chapter (they are not mandatory), these packages are required to run the test suites in [348]Chapter 6. Prepare Tcl for compilation: cd unix ./configure --prefix=/tools Build the package: make To test the results, issue: TZ=UTC make test. The Tcl test suite is known to experience failures under certain host conditions that are not fully understood. Therefore, test suite failures here are not surprising, and are not considered critical. The TZ=UTC parameter sets the time zone to Coordinated Universal Time (UTC), also known as Greenwich Mean Time (GMT), but only for the duration of the test suite run. This ensures that the clock tests are exercised correctly. Details on the TZ environment variable are provided in [349]Chapter 7. Install the package: make install Warning Do not remove the tcl8.4.9 source directory yet, as the next package will need its internal headers. Set a variable containing the full path of the current directory. The next package, Expect, will use this variable to find Tcl's headers. cd .. export TCLPATH=`pwd` Now make a necessary symbolic link: ln -sv tclsh8.4 /tools/bin/tclsh 5.8.2. Contents of Tcl Installed programs: tclsh (link to tclsh8.4) and tclsh8.4 Installed library: libtcl8.4.so Short Descriptions tclsh8.4 The Tcl command shell tclsh A link to tclsh8.4 libtcl8.4.so The Tcl library 5.9. Expect-5.43.0 The Expect package contains a program for carrying out scripted dialogues with other interactive programs. Approximate build time: 0.1 SBU Required disk space: 4.0 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, GCC, Glibc, Grep, Make, Sed, and Tcl 5.9.1. Installation of Expect First, fix a bug that can result in false failures during the GCC test suite run: patch -Np1 -i ../expect-5.43.0-spawn-1.patch Now prepare Expect for compilation: ./configure --prefix=/tools --with-tcl=/tools/lib \ --with-tclinclude=$TCLPATH --with-x=no The meaning of the configure options: --with-tcl=/tools/lib This ensures that the configure script finds the Tcl installation in the temporary tools location instead of possibly locating an existing one on the host system. --with-tclinclude=$TCLPATH This explicitly tells Expect where to find Tcl's source directory and internal headers. Using this option avoids conditions where configure fails because it cannot automatically discover the location of the Tcl source directory. --with-x=no This tells the configure script not to search for Tk (the Tcl GUI component) or the X Window System libraries, both of which may reside on the host system but will not exist in the temporary environment. Build the package: make To test the results, issue: make test. Note that the Expect test suite is known to experience failures under certain host conditions that are not within our control. Therefore, test suite failures here are not surprising and are not considered critical. Install the package: make SCRIPTS="" install The meaning of the make parameter: SCRIPTS="" This prevents installation of the supplementary expect scripts, which are not needed. Now remove the TCLPATH variable: unset TCLPATH The source directories of both Tcl and Expect can now be removed. 5.9.2. Contents of Expect Installed program: expect Installed library: libexpect-5.43.a Short Descriptions expect Communicates with other interactive programs according to a script libexpect-5.43.a Contains functions that allow Expect to be used as a Tcl extension or to be used directly from C or C++ (without Tcl) 5.10. DejaGNU-1.4.4 The DejaGNU package contains a framework for testing other programs. Approximate build time: 0.1 SBU Required disk space: 6.1 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, GCC, Glibc, Grep, Make, and Sed 5.10.1. Installation of DejaGNU Prepare DejaGNU for compilation: ./configure --prefix=/tools Build and install the package: make install 5.10.2. Contents of DejaGNU Installed program: runtest Short Descriptions runtest A wrapper script that locates the proper expect shell and then runs DejaGNU 5.11. GCC-3.4.3 - Pass 2 Approximate build time: 11.0 SBU Required disk space: 292 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, Findutils, Gawk, Gettext, Glibc, Grep, Make, Perl, Sed, and Texinfo 5.11.1. Re-installation of GCC This package is known to have issues when its default optimization flags (including the -march and -mcpu options) are changed. If any environment variables that override default optimizations have been defined, such as CFLAGS and CXXFLAGS, unset them when building GCC. The tools required to test GCC and Binutils--Tcl, Expect and DejaGNU--are installed now. GCC and Binutils can now be rebuilt, linking them against the new Glibc and testing them properly (if running the test suites in this chapter). Please note that these test suites are highly dependent on properly functioning PTYs which are provided by the host. PTYs are most commonly implemented via the devpts file system. Check to see if the host system is set up correctly in this regard by performing a quick test: expect -c "spawn ls" The response might be: The system has no more ptys. Ask your system administrator to create more. If the above message is received, the host does not have its PTYs set up properly. In this case, there is no point in running the test suites for GCC and Binutils until this issue is resolved. Please consult the LFS FAQ at [350]http://www.linuxfromscratch.org//lfs/faq.html#no-ptys for more information on how to get PTYs working. First correct a known problem and make an essential adjustment: patch -Np1 -i ../gcc-3.4.3-no_fixincludes-1.patch patch -Np1 -i ../gcc-3.4.3-specs-2.patch The first patch disables the GCC fixincludes script. This was briefly mentioned earlier, but a more in-depth explanation of the fixincludes process is warranted here. Under normal circumstances, the GCC fixincludes script scans the system for header files that need to be fixed. It might find that some Glibc header files on the host system need to be fixed, and will fix them and put them in the GCC private include directory. In [351]Chapter 6, after the newer Glibc has been installed, this private include directory will be searched before the system include directory. This may result in GCC finding the fixed headers from the host system, which most likely will not match the Glibc version used for the LFS system. The second patch changes GCC's default location of the dynamic linker (typically ld-linux.so.2). It also removes /usr/include from GCC's include search path. Patching now rather than adjusting the specs file after installation ensures that the new dynamic linker is used during the actual build of GCC. That is, all of the final (and temporary) binaries created during the build will link against the new Glibc. Important The above patches are critical in ensuring a successful overall build. Do not forget to apply them. Create a separate build directory again: mkdir -v ../gcc-build cd ../gcc-build Before starting to build GCC, remember to unset any environment variables that override the default optimization flags. Now prepare GCC for compilation: ../gcc-3.4.3/configure --prefix=/tools \ --libexecdir=/tools/lib --with-local-prefix=/tools \ --enable-clocale=gnu --enable-shared \ --enable-threads=posix --enable-__cxa_atexit \ --enable-languages=c,c++ --disable-libstdcxx-pch The meaning of the new configure options: --enable-clocale=gnu This option ensures the correct locale model is selected for the C++ libraries under all circumstances. If the configure script finds the de_DE locale installed, it will select the correct gnu locale model. However, if the de_DE locale is not installed, there is the risk of building Application Binary Interface (ABI)-incompatible C++ libraries because the incorrect generic locale model may be selected. --enable-threads=posix This enables C++ exception handling for multi-threaded code. --enable-__cxa_atexit This option allows use of __cxa_atexit, rather than atexit, to register C++ destructors for local statics and global objects. This option is essential for fully standards-compliant handling of destructors. It also affects the C++ ABI, and therefore results in C++ shared libraries and C++ programs that are interoperable with other Linux distributions. --enable-languages=c,c++ This option ensures that both the C and C++ compilers are built. --disable-libstdcxx-pch Do not build the pre-compiled header (PCH) for libstdc++. It takes up a lot of space, and we have no use for it. Compile the package: make There is no need to use the bootstrap target now because the compiler being used to compile this GCC was built from the exact same version of the GCC sources used earlier. Compilation is now complete. As previously mentioned, running the test suites for the temporary tools compiled in this chapter is not mandatory. To run the GCC test suite anyway, use the following command: make -k check The -k flag is used to make the test suite run through to completion and not stop at the first failure. The GCC test suite is very comprehensive and is almost guaranteed to generate a few failures. To receive a summary of the test suite results, run: ../gcc-3.4.3/contrib/test_summary For only the summaries, pipe the output through grep -A7 Summ. Results can be compared with those located at [352]http://www.linuxfromscratch.org/lfs/build-logs/6.1.1/. A few unexpected failures cannot always be avoided. The GCC developers are usually aware of these issues, but have not resolved them yet. Unless the test results are vastly different from those at the above URL, it is safe to continue. Install the package: make install Note At this point it is strongly recommended to repeat the sanity check we performed earlier in this chapter. Refer back to [353]Section 5.7, "Adjusting the Toolchain," and repeat the test compilation. If the result is wrong, the most likely reason is that the GCC Specs patch was not properly applied. Details on this package are located in [354]Section 6.14.2, "Contents of GCC." 5.12. Binutils-2.15.94.0.2.2 - Pass 2 The Binutils package contains a linker, an assembler, and other tools for handling object files. Approximate build time: 1.5 SBU Required disk space: 114 MB Installation depends on: Bash, Bison, Coreutils, Diffutils, Flex, GCC, Gettext, Glibc, Grep, M4, Make, Perl, Sed, and Texinfo 5.12.1. Re-installation of Binutils This package is known to have issues when its default optimization flags (including the -march and -mcpu options) are changed. If any environment variables that override default optimizations have been defined, such as CFLAGS and CXXFLAGS, unset them when building Binutils. Create a separate build directory again: mkdir -v ../binutils-build cd ../binutils-build Prepare Binutils for compilation: ../binutils-2.15.94.0.2.2/configure --prefix=/tools \ --disable-nls --enable-shared --with-lib-path=/tools/lib The meaning of the new configure options: --with-lib-path=/tools/lib This tells the configure script to specify the library search path during the compilation of Binutils, resulting in /tools/lib being passed to the linker. This prevents the linker from searching through library directories on the host. Compile the package: make Compilation is now complete. As discussed earlier, running the test suite is not mandatory for the temporary tools here in this chapter. To run the Binutils test suite anyway, issue the following command: make check Install the package: make install Now prepare the linker for the "Re-adjusting" phase in the next chapter: make -C ld clean make -C ld LIB_PATH=/usr/lib:/lib Warning Do not remove the Binutils source and build directories yet. These directories will be needed again in the next chapter in their current state. Details on this package are located in [355]Section 6.13.2, "Contents of Binutils." 5.13. Gawk-3.1.4 The Gawk package contains programs for manipulating text files. Approximate build time: 0.2 SBU Required disk space: 16.4 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, GCC, Gettext, Glibc, Grep, Make, and Sed 5.13.1. Installation of Gawk Prepare Gawk for compilation: ./configure --prefix=/tools Compile the package: make To test the results, issue: make check. Install the package: make install Details on this package are located in [356]Section 6.20.2, "Contents of Gawk." 5.14. Coreutils-5.2.1 The Coreutils package contains utilities for showing and setting the basic system characteristics. Approximate build time: 0.9 SBU Required disk space: 53.3 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, GCC, Gettext, Glibc, Grep, Make, Perl, and Sed 5.14.1. Installation of Coreutils Prepare Coreutils for compilation: DEFAULT_POSIX2_VERSION=199209 ./configure --prefix=/tools This package has an issue when compiled against versions of Glibc later than 2.3.2. Some of the Coreutils utilities (such as head, tail, and sort) will reject their traditional syntax, a syntax that has been in use for approximately 30 years. This old syntax is so pervasive that compatibility should be preserved until the many places where it is used can be updated. Backwards compatibility is achieved by setting the DEFAULT_POSIX2_VERSION environment variable to "199209" in the above command. If you do not want Coreutils to be backwards compatible with the traditional syntax, then omit setting the DEFAULT_POSIX2_VERSION environment variable. It is important to remember that doing so will have consequences, including the need to patch the many packages that still use the old syntax. Therefore, it is recommended that the instructions be followed exactly as given above. Compile the package: make To test the results, issue: make RUN_EXPENSIVE_TESTS=yes check. The RUN_EXPENSIVE_TESTS=yes parameter tells the test suite to run several additional tests that are considered relatively expensive (in terms of CPU power and memory usage) on some platforms, but generally are not a problem on Linux. Install the package: make install Details on this package are located in [357]Section 6.15.2, "Contents of Coreutils." 5.15. Bzip2-1.0.3 The Bzip2 package contains programs for compressing and decompressing files. Compressing text files with bzip2 yields a much better compression percentage than with the traditional gzip. Approximate build time: 0.1 SBU Required disk space: 3.5 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, GCC, Glibc, and Make 5.15.1. Installation of Bzip2 The Bzip2 package does not contain a configure script. Compile and test it with: make Install the package: make PREFIX=/tools install Details on this package are located in [358]Section 6.40.2, "Contents of Bzip2." 5.16. Gzip-1.3.5 The Gzip package contains programs for compressing and decompressing files. Approximate build time: 0.1 SBU Required disk space: 2.2 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, GCC, Glibc, Grep, Make, and Sed 5.16.1. Installation of Gzip Prepare Gzip for compilation: ./configure --prefix=/tools Compile the package: make This package does not come with a test suite. Install the package: make install Details on this package are located in [359]Section 6.46.2, "Contents of Gzip." 5.17. Diffutils-2.8.1 The Diffutils package contains programs that show the differences between files or directories. Approximate build time: 0.1 SBU Required disk space: 5.6 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, GCC, Gettext, Glibc, Grep, Make, and Sed 5.17.1. Installation of Diffutils Prepare Diffutils for compilation: ./configure --prefix=/tools Compile the package: make This package does not come with a test suite. Install the package: make install Details on this package are located in [360]Section 6.41.2, "Contents of Diffutils." 5.18. Findutils-4.2.23 The Findutils package contains programs to find files. These programs are provided to recursively search through a directory tree and to create, maintain, and search a database (often faster than the recursive find, but unreliable if the database has not been recently updated). Approximate build time: 0.2 SBU Required disk space: 8.9 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, GCC, Gettext, Glibc, Grep, Make and Sed 5.18.1. Installation of Findutils Prepare Findutils for compilation: ./configure --prefix=/tools Compile the package: make To test the results, issue: make check. Install the package: make install Details on this package are located in [361]Section 6.19.2, "Contents of Findutils." 5.19. Make-3.80 The Make package contains a program for compiling packages. Approximate build time: 0.2 SBU Required disk space: 7.1 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, GCC, Gettext, Glibc, Grep, and Sed 5.19.1. Installation of Make Prepare Make for compilation: ./configure --prefix=/tools Compile the package: make To test the results, issue: make check. Install the package: make install Details on this package are located in [362]Section 6.49.2, "Contents of Make." 5.20. Grep-2.5.1a The Grep package contains programs for searching through files. Approximate build time: 0.1 SBU Required disk space: 4.5 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, GCC, Gettext, Glibc, Make, Sed, and Texinfo 5.20.1. Installation of Grep Prepare Grep for compilation: ./configure --prefix=/tools \ --disable-perl-regexp The meaning of the configure options: --disable-perl-regexp This ensures that the grep program does not get linked against a Perl Compatible Regular Expression (PCRE) library that may be present on the host but will not be available once we enter the chroot environment. Compile the package: make To test the results, issue: make check. Install the package: make install Details on this package are located in [363]Section 6.44.2, "Contents of Grep." 5.21. Sed-4.1.4 The Sed package contains a stream editor. Approximate build time: 0.2 SBU Required disk space: 8.4 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, GCC, Gettext, Glibc, Grep, Make, and Texinfo 5.21.1. Installation of Sed Prepare Sed for compilation: ./configure --prefix=/tools Compile the package: make To test the results, issue: make check. Install the package: make install Details on this package are located in [364]Section 6.28.2, "Contents of Sed." 5.22. Gettext-0.14.3 The Gettext package contains utilities for internationalization and localization. These allow programs to be compiled with NLS (Native Language Support), enabling them to output messages in the user's native language. Approximate build time: 0.5 SBU Required disk space: 63.0 MB Installation depends on: Bash, Binutils, Bison, Coreutils, Diffutils, Gawk, GCC, Glibc, Grep, Make, and Sed 5.22.1. Installation of Gettext Prepare Gettext for compilation: ./configure --prefix=/tools --disable-libasprintf \ --without-csharp The meaning of the configure options: --disable-libasprintf This flag tells Gettext not to build the asprintf library. Because nothing in this chapter or the next requires this library and Gettext gets rebuilt later, exclude it to save time and space. --without-csharp This ensures that Gettext does not build support for the C# compiler which may be present on the host but will not be available once we enter the chroot environment. Compile the package: make To test the results, issue: make check. This takes quite some time, around 7 SBUs. The Gettext test suite is known to experience failures under certain host conditions, for example when it finds a Java compiler on the host. An experimental patch to disable Java is available from the LFS Patches project at [365]http://www.linuxfromscratch.org/patches/. Install the package: make install Details on this package are located in [366]Section 6.30.2, "Contents of Gettext." 5.23. Ncurses-5.4 The Ncurses package contains libraries for terminal-independent handling of character screens. Approximate build time: 0.7 SBU Required disk space: 27.5 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, Gawk, GCC, Glibc, Grep, Make, and Sed 5.23.1. Installation of Ncurses Prepare Ncurses for compilation: ./configure --prefix=/tools --with-shared \ --without-debug --without-ada --enable-overwrite The meaning of the configure options: --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. --enable-overwrite This tells Ncurses to install its header files into /tools/include, instead of /tools/include/ncurses, to ensure that other packages can find the Ncurses headers successfully. Compile the package: make This package does not come with a test suite. Install the package: make install Details on this package are located in [367]Section 6.21.2, "Contents of Ncurses." 5.24. Patch-2.5.4 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: 1.5 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, GCC, Glibc, Grep, Make, and Sed 5.24.1. Installation of Patch Prepare Patch for compilation: CPPFLAGS=-D_GNU_SOURCE ./configure --prefix=/tools The preprocessor flag -D_GNU_SOURCE is only needed on the PowerPC platform. It can be left out on other architectures. Compile the package: make This package does not come with a test suite. Install the package: make install Details on this package are located in [368]Section 6.51.2, "Contents of Patch." 5.25. Tar-1.15.1 The Tar package contains an archiving program. Approximate build time: 0.2 SBU Required disk space: 12.7 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, GCC, Gettext, Glibc, Grep, Make, and Sed 5.25.1. Installation of Tar Prepare Tar for compilation: ./configure --prefix=/tools Compile the package: make To test the results, issue: make check. Install the package: make install Details on this package are located in [369]Section 6.57.2, "Contents of Tar." 5.26. Texinfo-4.8 The Texinfo package contains programs for reading, writing, and converting info pages. Approximate build time: 0.2 SBU Required disk space: 14.7 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, GCC, Gettext, Glibc, Grep, Make, Ncurses, and Sed 5.26.1. Installation of Texinfo Prepare Texinfo for compilation: ./configure --prefix=/tools Compile the package: make To test the results, issue: make check. Install the package: make install Details on this package are located in [370]Section 6.34.2, "Contents of Texinfo." 5.27. Bash-3.0 The Bash package contains the Bourne-Again SHell. Approximate build time: 1.2 SBU Required disk space: 20.7 MB Installation depends on: Binutils, Coreutils, Diffutils, Gawk, GCC, Glibc, Grep, Make, Ncurses, and Sed. 5.27.1. Installation of Bash Bash has a problem when compiled against newer versions of Glibc, causing it to hang inappropriately. This patch fixes the problem: patch -Np1 -i ../bash-3.0-avoid_WCONTINUED-1.patch Prepare Bash for compilation: ./configure --prefix=/tools --without-bash-malloc The meaning of the configure options: --without-bash-malloc This options 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 To test the results, issue: make tests. Install the package: make install Make a link for the programs that use sh for a shell: ln -vs bash /tools/bin/sh Details on this package are located in [371]Section 6.37.2, "Contents of Bash." 5.28. M4-1.4.3 The M4 package contains a macro processor. Approximate build time: 0.1 SBU Required disk space: 2.8 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, GCC, Gettext, Glibc, Grep, Make, Perl, and Sed 5.28.1. Installation of M4 Prepare M4 for compilation: ./configure --prefix=/tools Compile the package: make To test the results, issue: make check. Install the package: make install Details on this package are located in [372]Section 6.24.2, "Contents of M4." 5.29. Bison-2.0 The Bison package contains a parser generator. Approximate build time: 0.6 SBU Required disk space: 10.0 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, GCC, Gettext, Glibc, Grep, M4, Make, and Sed 5.29.1. Installation of Bison Prepare Bison for compilation: ./configure --prefix=/tools Compile the package: make To test the results, issue: make check. Install the package: make install Details on this package are located in [373]Section 6.25.2, "Contents of Bison." 5.30. Flex-2.5.31 The Flex package contains a utility for generating programs that recognize patterns in text. Approximate build time: 0.6 SBU Required disk space: 22.5 MB Installation depends on: Bash, Binutils, Bison, Coreutils, Diffutils, GCC, Gettext, Glibc, Grep, M4, Make, and Sed 5.30.1. Installation of Flex Flex contains several known bugs. These can be fixed with the following patch: patch -Np1 -i ../flex-2.5.31-debian_fixes-3.patch The GNU autotools will detect that the Flex source code has been modified by the previous patch and tries to update the man page accordingly. This does not work on many systems, and the default page is fine, so make sure it does not get regenerated: touch doc/flex.1 Now prepare Flex for compilation: ./configure --prefix=/tools Compile the package: make To test the results, issue: make check. Install the package: make install Details on this package are located in [374]Section 6.29.2, "Contents of Flex." 5.31. Util-linux-2.12q The Util-linux package contains miscellaneous utility programs. Among them are utilities for handling file systems, consoles, partitions, and messages. Approximate build time: 0.2 SBU Required disk space: 8.9 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, GCC, Gettext, Glibc, Grep, Make, Ncurses, Sed, and Zlib 5.31.1. Installation of Util-linux Util-linux does not use the freshly installed headers and libraries from the /tools directory by default. This is fixed by altering the configure script: sed -i 's@/usr/include@/tools/include@g' configure Prepare Util-linux for compilation: ./configure Compile some support routines: make -C lib Only a few of the utilities contained in this package need to be built: make -C mount mount umount make -C text-utils more This package does not come with a test suite. Copy these programs to the temporary tools directory: cp mount/{,u}mount text-utils/more /tools/bin Details on this package are located in [375]Section 6.59.3, "Contents of Util-linux." 5.32. Perl-5.8.7 The Perl package contains the Practical Extraction and Report Language. Approximate build time: 0.8 SBU Required disk space: 81.6 MB Installation depends on: Bash, Binutils, Coreutils, Diffutils, Gawk, GCC, Glibc, Grep, Make, and Sed 5.32.1. Installation of Perl First adapt some hard-wired paths to the C library by applying the following patch: patch -Np1 -i ../perl-5.8.7-libc-1.patch Prepare Perl for compilation (make sure to get the 'IO Fcntl POSIX' part of the command correct--they are all letters): ./configure.gnu --prefix=/tools -Dstatic_ext='IO Fcntl POSIX' The meaning of the configure options: -Dstatic_ext='IO Fcntl POSIX' This tells Perl to build the minimum set of static extensions needed for installing and testing the Coreutils package in the next chapter. Only a few of the utilities contained in this package need to be built: make perl utilities Although Perl comes with a test suite, it is not recommended to run it at this point. Only part of Perl was built and running make test now will cause the rest of Perl to be built as well, which is unnecessary at this point. The test suite can be run in the next chapter if desired. Install these tools and their libraries: cp -v perl pod/pod2man /tools/bin mkdir -pv /tools/lib/perl5/5.8.7 cp -Rv lib/* /tools/lib/perl5/5.8.7 Details on this package are located in [376]Section 6.33.2, "Contents of Perl." 5.33. Stripping The steps in this section are optional, but if the LFS partition is rather small, it is beneficial to learn that unnecessary items can be removed. The executables and libraries built so far contain about 130 MB of unneeded debugging symbols. Remove those symbols with: strip --strip-debug /tools/lib/* strip --strip-unneeded /tools/{,s}bin/* The last of the above commands will skip some twenty files, reporting that it does not recognize their file format. Most of these are scripts instead of binaries. Take care not to use --strip-unneeded on the libraries. The static ones would be destroyed and the toolchain packages would need to be built all over again. To save another 30 MB, remove the documentation: rm -rf /tools/{info,man} There will now be at least 850 MB of free space on the LFS file system that can be used to build and install Glibc in the next phase. If you can build and install Glibc, you can build and install the rest too. Part III. Building the LFS System Table of Contents * 6. Installing Basic System Software + [377]Introduction + [378]Mounting Virtual Kernel File Systems + [379]Entering the Chroot Environment + [380]Changing Ownership + [381]Creating Directories + [382]Creating Essential Symlinks + [383]Creating the passwd, group, and log Files + [384]Populating /dev + [385]Linux-Libc-Headers-2.6.11.2 + [386]Man-pages-2.01 + [387]Glibc-2.3.4 + [388]Re-adjusting the Toolchain + [389]Binutils-2.15.94.0.2.2 + [390]GCC-3.4.3 + [391]Coreutils-5.2.1 + [392]Zlib-1.2.3 + [393]Mktemp-1.5 + [394]Iana-Etc-1.04 + [395]Findutils-4.2.23 + [396]Gawk-3.1.4 + [397]Ncurses-5.4 + [398]Readline-5.0 + [399]Vim-6.3 + [400]M4-1.4.3 + [401]Bison-2.0 + [402]Less-382 + [403]Groff-1.19.1 + [404]Sed-4.1.4 + [405]Flex-2.5.31 + [406]Gettext-0.14.3 + [407]Inetutils-1.4.2 + [408]IPRoute2-2.6.11-050330 + [409]Perl-5.8.7 + [410]Texinfo-4.8 + [411]Autoconf-2.59 + [412]Automake-1.9.5 + [413]Bash-3.0 + [414]File-4.13 + [415]Libtool-1.5.14 + [416]Bzip2-1.0.3 + [417]Diffutils-2.8.1 + [418]Kbd-1.12 + [419]E2fsprogs-1.37 + [420]Grep-2.5.1a +