Preparing the LFS system for installing basic system software

Installing Bash

Install Bash by running the following commands:



root:bash-2.04# ./configure --enable-static-link
root:bash-2.04# make
root:bash-2.04# make -e prefix=$LFS/usr install
root:bash-2.04# mv $LFS/usr/bin/bash $LFS/bin
root:bash-2.04# cd $LFS/bin
root:bin# ln -s bash sh

Installing Binutils

Install Binutils by running the following commands:



root:binutils-2.9.5.0.37# ./configure --prefix=/usr
root:binutils-2.9.5.0.37# make -e LDFLAGS=-all-static
root:binutils-2.9.5.0.37a make -e prefix=$LFS/usr install

Installing Bzip2

Before we can install Bzip2 we need to modify the Makefile file. Open the Makefile file in a text editor and find the lines that start with $(CC) $(CFLAGS) -o

Replace those parts with: $(CC) $(CFLAGS) $(LDFLAGS) -o

Now install Bzip2 by running the following commands:


root:bzip2-0.9.5d# make -e LDFLAGS=-static
root:bzip2-0.9.5d# make -e PREFIX=$LFS/usr install
root:bzip2-0.9.5d# cd $LFS/usr/bin
root:bin# mv bunzip2 bzip2 $LFS/bin

Installing Diffutils

Install Diffutils by running the following commands:



root:diffutils-2.7# ./configure --prefix=/usr
root:diffutils-2.7# make -e LDFLAGS=-static
root:diffutils-2.7# make -e prefix=$LFS/usr install

This package is known to cause static link problems on certain platforms. If you're having trouble compiling this package as well, you can download a patch from http://www.linuxfromscratch.org/download/diffutils-2.7.patch.gz

Install this patch by running the following command:



root:diffutils-2.7# patch -Np1 -i ../diffutils-2.7.patch

Now recompile the package using the same commands as above.

Installing Fileutils

Install Fileutils by running the following commands:



root:fileutils-4.0# ./configure --disable-nls --prefix=/usr
root:fileutils-4.0# make -e LDFLAGS=-static
root:fileutils-4.0# make -e prefix=$LFS/usr install
root:fileutils-4.0# cd $LFS/usr/bin
root:bin# mv chgrp chmod chown cp dd df ln $LFS/bin
root:bin# mv ls mkdir mknod mv rm rmdir sync $LFS/bin

Installing GCC on the normal system if necessary

In order to compile Glibc-2.1.3 later on you need to have gcc-2.95.2 installed. Although any GCC version above 2.8 would do, 2.95.2 is the highly recommended version to use. Many glibc-2.0 based systems have gcc-2.7.2.3 installed and you can't compile glibc-2.1.3 with that compiler. Many glibc-2.1 based systems have egcs-2.95.x installed and that version doesn't work too well either (sometimes it works fine, sometimes it doesn't depending on various circumstances).

To find out whether your system uses gcc-2.95.2 or not, run the following command:



root:~# gcc --version

If you normal Linux system does not have gcc-2.95.2 installed you need to install it now. We won't replace the current compiler on your system, but instead we will install gcc in a separate directory (/usr/local/gcc2952). This way no binaries or header files will be replaced.

After you unpacked the gcc-2.95.2 archive don't enter the newly created gcc-2.95.2 directory but stay in the $LFS/usr/src directory. Install GCC by running the following commands:



root:src# mkdir $LFS/usr/src/gcc-build
root:src# cd $LFS/usr/src/gcc-build
root:gcc-build# ../gcc-2.95.2/configure --prefix=/usr/local/gcc2952 \
> --with-local-prefix=/usr/local/gcc2952 \
> --with-gxx-include-dir=/usr/local/gcc2952/include/g++ \
> --enable-shared --enable-languages=c,c++
root:gcc-build# make bootstrap
root:gcc-build# make install

Installing GCC on the LFS system

After you unpacked the gcc-2.95.2 archive don't enter the newly created gcc-2.95.2 directory but stay in the $LFS/usr/src directory. Install GCC by running the following commands:



root:src# mkdir $LFS/usr/src/gcc-build
root:src# cd $LFS/usr/src/gcc-build
root:gcc-build# ../gcc-2.95.2/configure \
> --prefix=/usr --with-local-prefix=/usr \
> --with-gxx-include-dir=/usr/include/g++ \
> --enable-languages=c,c++ --disable-nls
root:gcc-build# make -e LDFLAGS=-static bootstrap
root:gcc-build# make -e prefix=$LFS/usr local_prefix=$LFS/usr \
gxx_include_dir=$LFS/usr/include/g++ \
> install

Creating necessary symlinks

The system needs a few symlinks to ensure every program is able to find the compiler and the pre-processor. Some programs run the cc program, others run the gcc program. Some programs expect the cpp program in /lib and others expect to find it in /usr/bin. Create those symlinks by running:



root:~# cd $LFS/lib
root:lib# ln -s ../usr/lib/gcc-lib/<host>/2.95.2/cpp cpp
root:lib# cd $LFS/usr/lib
root:lib# ln -s gcc-lib/<host>/2.95.2/cpp cpp
root:lib# cd $LFS/usr/bin
root:bin# ln -s gcc cc

Replace <host> with the directory where the gcc-2.95.2 files are installed (which is i686-unknown-linux in my case).

Installing Glibc

A note on the glibc-crypt package

An excerpt from the README file that is distributed with the glibc-crypt package:

The add-on is not included in the main distribution of the GNU C library because some governments, most notably those of France, Russia, and the US, have very restrictive rules governing the distribution and use of encryption software. Please read the node "Legal Problems" in the manual for more details.

In particular, the US does not allow export of this software without a licence, including via the Internet. So please do not download it from the main FSF FTP site at ftp.gnu.org if you are outside the US. This software was completely developed outside the US.

"This software" refers to the glibc-crypt package at ftp://ftp.gwdg.de/pub/linux/glibc/. This law only affects people who don't live in the US. It's not prohibited to import DES software, so if you live in the US you can import the file safely from Germany without breaking cryptographic laws. This law is changing lately and I don't know what the status of it is at the moment. Better be safe than sory.

Installing Glibc

Copy the Glibc-crypt and Glibc-linuxthreads archives into the unpacked glibc directory. Copy the glibc-2.1.3-ctype.patch file to $LFS/usr/src

Unpack the glibc-crypt and glibc-linuxthreads archives there, but don't enter the created directories. Just unpack and leave it with that.

A few default parameters of Glibc need to be changed, such as the directory where the shared libraries are supposed to be installed in and the directory that contains the system configuration files. For this purpose you need to create the $LFS/usr/src/glibc-build directory and in that directory you create a new file configparms containing:



# Begin configparms

slibdir=/lib
sysconfdir=/etc

# End configparms

Change to the $LFS/usr/src/glibc-2.1.3 directory and install Glibc by running the following commands if your system already had a suitable GCC version installed:



root:glibc-2.1.3# patch -p1 < ../glibc-2.1.3-ctype.patch
root:glibc-2.1.3# cd ../glibc-build
root:glibc-build# ../glibc-2.1.3/configure \
> --prefix=/usr --enable-add-ons
root:glibc-build# make
root:glibc-build# make install_root=$LFS install

Change to the $LFS/usr/src/glibc-build directory and install Glibc by running the following command if your system did not already have a suitable GCC version installed and you just installed GCC-2.95.2 on your normal Linux system a little while ago:



root:glibc-2.1.3# patch -p1 < ../glibc-2.1.3-ctype.patch
root:glibc-2.1.3# cd ../glibc-build
root:glibc-build# CC=/usr/local/gcc2952/bin/gcc \
> ../glibc-2.1.3/configure --prefix=/usr \
> --enable-add-ons
root:glibc-build# make
root:glibc-build# make install_root=$LFS install

Copying old NSS library files

If your normal Linux system runs glibc-2.0, you need to copy the NSS library files to the LFS partition. Certain statically linked programs still depend on the NSS library, especially programs that need to lookup usernames,userid's and groupid's. You can check which C library version your normal Linux system uses by running:



root:~# ls /lib/libc*

Your system uses glib-2.0 if there is a file that looks like libc-2.0.7.so

Your system uses glibc-2.1 if there is a file that looks like libc-2.1.3.so

Of course, the micro version number can be different (you could have libc-2.1.2 or libc-2.1.1 for example).

If you have a libc-2.0.x file copy the NSS library files by running:



root:~# cp -av /lib/libnss* $LFS/lib

There are a few distributions that don't have files from which you can see which version of the C Library it is. If that's the case, it will be hard to determine which C library version you exactly have. Try to obtain this information using your distribution's installation tool. It often says which version it has available. If you can't figure out at all which C Library version is used, then copy the NSS files anyway and hope for the best. That's the best advise I can give I'm afraid.

Installing Grep

Install Grep by running the following commands:



root:grep-2.4.2# ./configure --prefix=/usr --disable-nls
root:grep-2.4.2# make -e LDFLAGS=-static
root:grep-2.4.2# make -e prefix=$LFS/usr install

This package is known to cause static linking problems on certain platforms. If you're having trouble compiling this package as well, you can download a patch from http://www.linuxfromscratch.org/download/grep-2.4.2.patch.gz

Install this patch by running the following command:



root:grep-2.4.2# patch -Np1 -i ../grep-2.4.2.patch

Now recompile the package using the same commands as above.

Installing Gzip

Install Gzip by running the following commands:



root:gzip-1.2.4a# ./configure --prefix=/usr
root:gzip-1.2.4a# make -e LDFLAGS=-static
root:gzip-1.2.4a# make -e prefix=$LFS/usr install
root:gzip-1.2.4a# cd $LFS/usr/bin
root:bin# mv gunzip gzip $LFS/bin

This package is known to cause compilation problems on certain platforms. If you're having trouble compiling this package as well, you can download a fixed package from http://www.linuxfromscratch.org/download/gzip-1.2.4a.patch.gz

Install this patch by running the following command:



root:gzip-1.2.4a# patch -Np1 -i ../gzip-1.2.4a.patch.gz

Now recompile the package using the same commands as above.

Installing Make

Install Make by running the following commands:



root:make-3.78.1# ./configure --prefix=/usr --disable-nls
root:make-3.78.1# make -e LDFLAGS=-static
root:make-3.78.1# make -e prefix=$LFS/usr install

Installing Sed

Install Sed by running the following commands:



root:sed-3.02# ./configure --prefix=/usr
root:sed-3.02# make -e LDFLAGS=-static
root:sed-3.02# make -e prefix=$LFS/usr install
root:sed-3.02# mv $LFS/usr/bin/sed $LFS/bin

This package is known to cause static linking problems on certain platforms. If you're having trouble compiling this package as well, you can download a patch from http://www.linuxfromscratch.org/download/sed-3.02.patch.gz

Install this patch by running the following command:



root:sed-3.02# patch -Np1 -i ../sed-3.02.patch.gz

Now recompile the package using the same commands as above.

Installing Shellutils

Install Shellutils by running the following commands:



root:sh-utils-2.0# ./configure --prefix=/usr --disable-nls
root:sh-utils-2.0# make -e LDFLAGS=-static
root:sh-utils-2.0# make -e prefix=$LFS/usr install
root:sh-utils-2.0# cd $LFS/usr/bin
root:/bin# mv date echo false pwd stty $LFS/bin
root:bin# mv su true uname hostname $LFS/bin

Installing Tar

Install Tar by running the following commands:



root:tar-1.13# ./configure --prefix=/usr --disable-nls
root:tar-1.13# make -e LDFLAGS=-static
root:tar-1.13# make -e prefix=$LFS/usr install
root:tar-1.13# mv $LFS/usr/bin/tar $LFS/bin

Installing Textutils

Install Textutuils by running the following commands:



root:textutils-2.0# ./configure --prefix=/usr
root:textutils-2.0# make
root:textutils-2.0# make install
root:textutils-2.0# mv /usr/bin/cat /bin

Creating passwd and group files

Create a new file $LFS/etc/passwd containing the following:



root::0:0:root:/root:/bin/bash

Create a new file $LFS/etc/group containing the following:



root::0: