Preparing the LFS system for installing basic system software

Installing Bash

Install Bash by running the following commands:



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

Installing Binutils

Install Binutils by running the following commands:



root:/mnt/hda5/usr/src/binutils-2.9.5.0.37# ./configure \
> --prefix=/usr
root:/mnt/hda5/usr/src/binutils-2.9.5.0.37# make -e \
> LDFLAGS=-all-static
root:/mnt/hda5/usr/src/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:/mnt/hda5/usr/src/bzip2-0.9.5d# make -e LDFLAGS=-static
root:/mnt/hda5/usr/src/bzip2-0.9.5d# make -e PREFIX=$LFS/usr \
> install
root:/mnt/hda5/usr/src/bzip2-0.9.5d# cd $LFS/usr/bin
root:/mnt/hda5/usr/bin# mv bunzip2 bzip2 $LFS/bin

Installing Diffutils

Install Diffutils by running the following commands:



root:/mnt/hda5/usr/src/diffutils-2.7# ./configure --prefix=/usr
root:/mnt/hda5/usr/src/diffutils-2.7# make -e LDFLAGS=-static
root:/mnt/hda5/usr/src/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:/mnt/hda5/usr/src/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:/mnt/hda5/usr/src/fileutils-4.0# ./configure \
> --disable-nls --prefix=/usr
root:/mnt/hda5/usr/src/fileutils-4.0# make -e LDFLAGS=-static
root:/mnt/hda5/usr/src/fileutils-4.0# make -e prefix=$LFS/usr \
> install
root:/mnt/hda5/usr/src/fileutils-4.0# cd $LFS/usr/bin
root:/mnt/hda5/usr/bin# mv chgrp chmod chown cp dd df ln $LFS/bin
root:/mnt/hda5/usr/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).

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.

Install GCC by running the following commands:



root:/mnt/hda5/usr/src# mkdir $LFS/usr/src/gcc-build
root:/mnt/hda5/usr/src# cd $LFS/usr/src/gcc-build
root:/mnt/hda5/usr/src/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:/mnt/hda5/usr/src/gcc-build# make bootstrap
root:/mnt/hda5/usr/src/gcc-build# make install

Installing GCC on the LFS system

Install GCC by running the following commands:



root:/mnt/hda5/usr/src# mkdir $LFS/usr/src/gcc-build
root:/mnt/hda5/usr/src# cd $LFS/usr/src/gcc-build
root:/mnt/hda5/usr/src/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:/mnt/hda5/usr/src/gcc-build# make -e LDFLAGS=-static bootstrap
root:/mnt/hda5/usr/src/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:/mnt/hda5/lib# ln -s ../usr/lib/gcc-lib/<host>/2.95.2/cpp cpp
root:/mnt/hda5/lib# cd $LFS/usr/lib
root:/mnt/hda5/usr/lib# ln -s gcc-lib/<host>/2.95.2/cpp cpp
root:/mnt/hda5/usr/lib# cd $LFS/usr/bin
root:/mnt/hda5/usr/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

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-build directory and install Glibc by running the following commands if your system already had a suitable GCC version installed:



root:/mnt/hda5/usr/src/glibc-build# ../glibc-2.1.3/configure \
> --prefix=/usr --enable-add-ons
root:/mnt/hda5/usr/src/glibc-build# make
root:/mnt/hda5/usr/src/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:/mnt/hda5/usr/src/glibc-build# CC=/usr/local/gcc2952/bin/gcc \
> ../glibc-2.1.3/configure --prefix=/usr \
> --enable-add-ons
root:/mnt/hda5/usr/src/glibc-build# make
root:/mnt/hda5/usr/src/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:/mnt/hda5/usr/src/grep-2.4.2# ./configure --prefix=/usr \
> --disable-nls
root:/mnt/hda5/usr/src/grep-2.4.2# make -e LDFLAGS=-static
root:/mnt/hda5/usr/src/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:/mnt/hda5/usr/src/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:/mnt/hda5/usr/src/gzip-1.2.4a# ./configure --prefix=/usr
root:/mnt/hda5/usr/src/gzip-1.2.4a# make -e LDFLAGS=-static
root:/mnt/hda5/usr/src/gzip-1.2.4a# make -e prefix=$LFS/usr install
root:/mnt/hda5/usr/src/gzip-1.2.4a# cd $LFS/usr/bin
root:/mnt/hda5/usr/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:/usr/src/# patch -Np1 \
> -i ../findutils-4.1.patch.gz

Now recompile the package using the same commands as above.

Installing Make

Install Make by running the following commands:



root:/mnt/hda5/usr/src/make-3.78.1# ./configure --prefix=/usr
root:/mnt/hda5/usr/src/make-3.78.1# make -e LDFLAGS=-static
root:/mnt/hda5/usr/src/make-3.78.1# make -e prefix=$LFS/usr install

Installing Sed

Install Sed by running the following commands:



root:/mnt/hda5/usr/src/sed-3.02# ./configure --prefix=/usr
root:/mnt/hda5/usr/src/sed-3.02# make -e LDFLAGS=-static
root:/mnt/hda5/usr/src/sed-3.02# make -e prefix=$LFS/usr install
root:/mnt/hda5/usr/src/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:/usr/src/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:/mnt/hda5/usr/src/sh-utils-2.0# ./configure --prefix=/usr \
> --disable-nls
root:/mnt/hda5/usr/src/sh-utils-2.0# make -e LDFLAGS=-static
root:/mnt/hda5/usr/src/sh-utils-2.0# make -e prefix=$LFS/usr \
> install
root:/mnt/hda5/usr/src/sh-utils-2.0# cd $LFS/usr/bin
root:/mnt/hda5/usr/bin# mv date echo false pwd stty $LFS/bin
root:/mnt/hda5/usr/bin# mv su true uname hostname $LFS/bin

Installing Tar

Install Tar by running the following commands:



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

Installing Textutils

Install Textutils by running the following commands:



root:/mnt/hda5/usr/src/textutils-2.0# ./configure --prefix=/usr \
> --disable-nls
root:/mnt/hda5/usr/src/textutils-2.0# make -e LDFLAGS=-static
root:/mnt/hda5/usr/src/textutils-2.0# make -e prefix=$LFS/usr \
> install
root:/mnt/hda5/usr/src/textutils-2.0# mv $LFS/usr/bin/cat $LFS/bin

Creating passwd and group files

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



# Begin /etc/passwd
root:kRKb4s/LH8yDQ:0:0:root:/root:/bin/bash
# End /etc/passwd

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



# Begin /etc/group
root::0:
# End /etc/group

The encoded password above is: lfs123