Milestone 3 (Chapter 6 and 7)

Chapter 6 Cross Compiling Temporary Tools

6.2.1. Installation of M4

Prepare M4 for compilation:

./configure --prefix=/usr   \
            --host=$LFS_TGT \
            --build=$(build-aux/config.guess)

Compile the package:

make

Install the package:

make DESTDIR=$LFS install

6.3.1. Installation of Ncurses

First, ensure that gawk is found first during configuration:

sed -i s/mawk// configure

Then, run the following commands to build the “tic” program on the build host:

mkdir build
pushd build
  ../configure
  make -C include
  make -C progs tic
popd

Prepare Ncurses for compilation:

Compile the package:

Install the package:

6.4.1. Installation of Bash

Prepare Bash for compilation:

Compile the package:

Install the package:

Make a link for the programs that use sh for a shell:

6.5.1. Installation of Coreutils

Prepare Coreutils for compilation:

Compile the package:

Install the package:

Move programs to their final expected locations. Although this is not necessary in this temporary environment, we must do so because some programs hardcode executable locations:

6.6.1. Installation of Diffutils

Prepare Diffutils for compilation:

Compile the package:

Install the package:

6.7.1. Installation of File

The file command on the build host needs to be the same version as the one we are building in order to create the signature file. Run the following commands to make a temporary copy of the file command:

Prepare File for compilation:

Compile the package:

Install the package:

Remove the libtool archive file because it is harmful for cross compilation:

6.8.1. Installation of Findutils

Prepare Findutils for compilation:

Compile the package:

Install the package:

6.9.1. Installation of Gawk

First, ensure some unneeded files are not installed:

Prepare Gawk for compilation:

Compile the package:

Install the package:

6.10.1. Installation of Grep

Prepare Grep for compilation:

Compile the package:

Install the package:

6.11.1. Installation of Gzip

Prepare Gzip for compilation:

Compile the package:

Install the package:

6.12.1. Installation of Make

First, fix an issue identified upstream:

Prepare Make for compilation:

Compile the package:

Install the package:

6.13.1. Installation of Patch

Prepare Patch for compilation:

Compile the package:

Install the package:

6.14.1. Installation of Sed

Prepare Sed for compilation:

Compile the package:

Install the package:

6.15.1. Installation of Tar

Prepare Tar for compilation:

Compile the package:

Install the package:

6.16.1. Installation of Xz

Prepare Xz for compilation:

Compile the package:

Install the package:

Remove the libtool archive file because it is harmful for cross compilation:

6.17. Binutils-2.39 - Pass 2

Delete contents of the build folder

Prepare Binutils for compilation:

Compile the package:

Install the package:

Remove the libtool archive files because they are harmful for cross compilation, and remove unnecessary static libraries:

6.18. GCC-12.2.0 - Pass 2

Delete contents of the build folder

As in the first build of GCC, the GMP, MPFR, and MPC packages are required. Unpack the tarballs and move them into the required directories:

If building on x86_64, change the default directory name for 64-bit libraries to “lib”:

Override the building rule of libgcc and libstdc++ headers, to allow building these libraries with POSIX threads support:

Create a separate build directory again:

Now prepare GCC for compilation:

Compile the package:

Install the package:

As a finishing touch, create a utility symlink. Many programs and scripts run cc instead of gcc, which is used to keep programs generic and therefore usable on all kinds of UNIX systems where the GNU C compiler is not always installed. Running cc leaves the system administrator free to decide which C compiler to install:

Chapter 7 Entering Chroot and Building Additional Temporary Tools

7.2. Changing Ownership

ls -l $LFS

7.3. Preparing Virtual Kernel File Systems

creating directories onto which the file systems will be mounted

7.3.1. Mounting and Populating /dev

7.3.2. Mounting Virtual Kernel File Systems

Now mount the remaining virtual kernel filesystems:

In some host systems, /dev/shm is a symbolic link to /run/shm. The /run tmpfs was mounted above so in this case only a directory needs to be created.

7.4. Entering the Chroot Environment

Chroot Environment

7.5. Creating Directories

Create some root-level directories that are not in the limited set required in the previous chapters by issuing the following command:

Create the required set of subdirectories below the root-level by issuing the following commands:

Create a basic /etc/hosts file to be referenced in some test suites, and in one of Perl's configuration files as well:

Create the /etc/passwd file by running the following command:

The actual password for root will be set later.

Create the /etc/group file by running the following command:

We add this user here and delete this account at the end of that chapter.

To remove the “I have no name!” prompt, start a new shell. Since the /etc/passwd and /etc/group files have been created, user name and group name resolution will now work:

The login, agetty, and init programs (and others) use a number of log files to record information such as who was logged into the system and when.

7.7. Gettext-0.21

7.7.1. Installation of Gettext

For our temporary set of tools, we only need to install three programs from Gettext.

Prepare Gettext for compilation:

Compile the package:

Install the msgfmt, msgmerge, and xgettext programs:

7.8. Bison-3.8.2

7.8.1. Installation of Bison

Prepare Bison for compilation:

Compile the package:

Install the package:

7.9. Perl-5.36.0

7.9.1. Installation of Perl

Prepare Perl for compilation:

The meaning of the new Configure options:

-des

This is a combination of three options: -d uses defaults for all items; -e ensures completion of all tasks; -s silences non-essential output.

Compile the package:

Install the package:

7.10. Python-3.10.6

7.10.1. Installation of Python

Prepare Python for compilation:

Compile the package:

Install the package:

7.11. Texinfo-6.8

7.11.1. Installation of Texinfo

Prepare Texinfo for compilation:

Compile the package:

Install the package:

7.12. Util-linux-2.38.1

7.12.1. Installation of Util-linux

The FHS recommends using the /var/lib/hwclock directory instead of the usual /etc directory as the location for the adjtime file. Create this directory with:

Prepare Util-linux for compilation:

Compile the package:

Install the package:

7.13. Cleaning up and Saving the Temporary System

7.13.1. Cleaning

First, remove the currently installed documentation to prevent them from ending up in the final system, and to save about 35 MB:

Second, the libtool .la files are only useful when linking with static libraries.

It uses about 1 GB of disk space.

Last updated