Linux From Scratch

Version 6.1.1

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

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 http://axiom.anu.edu.au/~okeefe/p2b/ or on The Linux Documentation Project's (TLDP) website at 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:

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

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

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 http://www.linuxfromscratch.org/livecd/.

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. 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. Chapter 4 discusses the setup for an appropriate working environment. Please read Chapter 4 carefully as it explains several important issues the developer should be aware of before beginning to work through Chapter 5 and beyond.

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 Chapter 6. Some of these packages are needed to resolve circular dependencies—for example, to compile a compiler, you need a compiler.

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 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 Section 5.2, “Toolchain Technical Notes”.

In 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 Chapter 7, and the kernel and boot loader are set up in Chapter 8. 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 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 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 http://www.linuxfromscratch.org/search.html.

For information on the different lists, how to subscribe, archive locations, and additional information, visit 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 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 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 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: http://www.linuxfromscratch.org/hints/downloads/files/errors.txt.

If you cannot find your problem listed in the FAQ, search the mailing lists at 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 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 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

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 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 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 (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 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):

http://ftp.gnu.org/gnu/autoconf/

Automake (1.9.5) - 748 KB:

http://ftp.gnu.org/gnu/automake/

Bash (3.0) - 1,824 KB:

http://ftp.gnu.org/gnu/bash/

Bash Documentation (3.0) - 1,994 KB:

http://ftp.gnu.org/gnu/bash/

Binutils (2.15.94.0.2.2) - 11,056 KB:

http://www.kernel.org/pub/linux/devel/binutils/

Bison (2.0) - 916 KB:

http://ftp.gnu.org/gnu/bison/

Bzip2 (1.0.3) - 596 KB:

http://www.bzip.org/

Coreutils (5.2.1) - 4,184 KB:

http://ftp.gnu.org/gnu/coreutils/

DejaGNU (1.4.4) - 852 KB:

http://ftp.gnu.org/gnu/dejagnu/

Diffutils (2.8.1) - 648 KB:

http://ftp.gnu.org/gnu/diffutils/

E2fsprogs (1.37) - 3,100 KB:

http://prdownloads.sourceforge.net/e2fsprogs/

Expect (5.43.0) - 416 KB:

http://expect.nist.gov/src/

File (4.13) - 324 KB:

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: http://www.linuxfromscratch.org/lfs/download.html#ftp.

Findutils (4.2.23) - 784 KB:

http://ftp.gnu.org/gnu/findutils/

Flex (2.5.31) - 672 KB:

http://prdownloads.sourceforge.net/lex/

Gawk (3.1.4) - 1,696 KB:

http://ftp.gnu.org/gnu/gawk/

GCC (3.4.3) - 26,816 KB:

http://ftp.gnu.org/gnu/gcc/

Gettext (0.14.3) - 4,568 KB:

http://ftp.gnu.org/gnu/gettext/

Glibc (2.3.4) - 12,924 KB:

http://ftp.gnu.org/gnu/glibc/

Glibc-Linuxthreads (2.3.4) - 236 KB:

http://ftp.gnu.org/gnu/glibc/

Grep (2.5.1a) - 520 KB:

http://ftp.gnu.org/gnu/grep/

Groff (1.19.1) - 2,096 KB:

http://ftp.gnu.org/gnu/groff/

GRUB (0.96) - 768 KB:

ftp://alpha.gnu.org/gnu/grub/

Gzip (1.3.5) - 284 KB:

ftp://alpha.gnu.org/gnu/gzip/

Hotplug (2004_09_23) - 40 KB:

http://www.kernel.org/pub/linux/utils/kernel/hotplug/

Iana-Etc (1.04) - 176 KB:

http://www.sethwklein.net/projects/iana-etc/downloads/

Inetutils (1.4.2) - 752 KB:

http://ftp.gnu.org/gnu/inetutils/

IPRoute2 (2.6.11-050330) - 276 KB:

http://developer.osdl.org/dev/iproute2/download/

Kbd (1.12) - 624 KB:

http://www.kernel.org/pub/linux/utils/kbd/

Less (382) - 216 KB:

http://ftp.gnu.org/gnu/less/

LFS-Bootscripts (3.2.1) - 32 KB:

http://downloads.linuxfromscratch.org/

Libtool (1.5.14) - 1,604 KB:

http://ftp.gnu.org/gnu/libtool/

Linux (2.6.11.12) - 35,792 KB:

http://www.kernel.org/pub/linux/kernel/v2.6/

Linux-Libc-Headers (2.6.11.2) - 2,476 KB:

http://ep09.pld-linux.org/~mmazur/linux-libc-headers/

M4 (1.4.3) - 304 KB:

http://ftp.gnu.org/gnu/m4/

Make (3.80) - 904 KB:

http://ftp.gnu.org/gnu/make/

Man (1.5p) - 208 KB:

http://www.kernel.org/pub/linux/utils/man/

Man-pages (2.01) - 1,640 KB:

http://www.kernel.org/pub/linux/docs/manpages/

Mktemp (1.5) - 68 KB:

ftp://ftp.mktemp.org/pub/mktemp/

Module-Init-Tools (3.1) - 128 KB:

http://www.kernel.org/pub/linux/utils/kernel/module-init-tools/

Module-Init-Tools-Testsuite (3.1) - 34 KB:

http://www.kernel.org/pub/linux/utils/kernel/module-init-tools/

Ncurses (5.4) - 1,556 KB:

ftp://invisible-island.net/ncurses/

Patch (2.5.4) - 156 KB:

http://ftp.gnu.org/gnu/patch/

Perl (5.8.7) - 9,628 KB:

http://ftp.funet.fi/pub/CPAN/src/

Procps (3.2.5) - 224 KB:

http://procps.sourceforge.net/

Psmisc (21.6) - 188 KB:

http://prdownloads.sourceforge.net/psmisc/

Readline (5.0) - 1,456 KB:

http://ftp.gnu.org/gnu/readline/

Sed (4.1.4) - 632 KB:

http://ftp.gnu.org/gnu/sed/

Shadow (4.0.9) - 1,084 KB:

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: http://www.linuxfromscratch.org/lfs/download.html#ftp.

Sysklogd (1.4.1) - 72 KB:

http://www.infodrom.org/projects/sysklogd/download/

Sysvinit (2.86) - 88 KB:

ftp://ftp.cistron.nl/pub/people/miquels/sysvinit/

Tar (1.15.1) - 1,580 KB:

http://ftp.gnu.org/gnu/tar/

Tcl (8.4.9) - 2,748 KB:

http://prdownloads.sourceforge.net/tcl/

Texinfo (4.8) - 1,492 KB:

http://ftp.gnu.org/gnu/texinfo/