Professional Documents
Culture Documents
6.7. File-5.44
The File package contains a utility for determining the type of a given file or files.
Approximate build time: 0.1 SBU
Required disk space: 36 MB
Remove the libtool archive file because it is harmful for cross compilation:
rm -v $LFS/usr/lib/libmagic.la
62
Linux From Scratch - Version 11.3
6.8. Findutils-4.9.0
The Findutils package contains programs to find files. Programs are provided to search through all the files in a directory
tree and to create, maintain, and search a database (often faster than the recursive find, but unreliable unless the database
has been updated recently). Findutils also supplies the xargs program, which can be used to run a specified command
on each file selected by a search.
Approximate build time: 0.2 SBU
Required disk space: 42 MB
63
Linux From Scratch - Version 11.3
6.9. Gawk-5.2.1
The Gawk package contains programs for manipulating text files.
Approximate build time: 0.1 SBU
Required disk space: 47 MB
64
Linux From Scratch - Version 11.3
6.10. Grep-3.8
The Grep package contains programs for searching through the contents of files.
Approximate build time: 0.2 SBU
Required disk space: 25 MB
65
Linux From Scratch - Version 11.3
6.11. Gzip-1.12
The Gzip package contains programs for compressing and decompressing files.
Approximate build time: 0.1 SBU
Required disk space: 11 MB
66
Linux From Scratch - Version 11.3
6.12. Make-4.4
The Make package contains a program for controlling the generation of executables and other non-source files of a
package from source files.
Approximate build time: less than 0.1 SBU
Required disk space: 15 MB
67
Linux From Scratch - Version 11.3
6.13. Patch-2.7.6
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: 12 MB
68
Linux From Scratch - Version 11.3
6.14. Sed-4.9
The Sed package contains a stream editor.
Approximate build time: 0.2 SBU
Required disk space: 19 MB
69
Linux From Scratch - Version 11.3
6.15. Tar-1.34
The Tar package provides the ability to create tar archives as well as perform various other kinds of archive
manipulation. Tar can be used on previously created archives to extract files, to store additional files, or to update or
list files which were already stored.
Approximate build time: 0.1 SBU
Required disk space: 38 MB
70
Linux From Scratch - Version 11.3
6.16. Xz-5.4.1
The Xz package contains programs for compressing and decompressing files. It provides capabilities for the lzma and
the newer xz compression formats. Compressing text files with xz yields a better compression percentage than with
the traditional gzip or bzip2 commands.
Approximate build time: 0.1 SBU
Required disk space: 20 MB
6.16.1. Installation of Xz
Prepare Xz for compilation:
./configure --prefix=/usr \
--host=$LFS_TGT \
--build=$(build-aux/config.guess) \
--disable-static \
--docdir=/usr/share/doc/xz-5.4.1
Remove the libtool archive file because it is harmful for cross compilation:
rm -v $LFS/usr/lib/liblzma.la
71
Linux From Scratch - Version 11.3
Remove the libtool archive files because they are harmful for cross compilation, and remove unnecessary static libraries:
rm -v $LFS/usr/lib/lib{bfd,ctf,ctf-nobfd,opcodes}.{a,la}
72
Linux From Scratch - Version 11.3
If building on x86_64, change the default directory name for 64-bit libraries to “lib”:
case $(uname -m) in
x86_64)
sed -e '/m64=/s/lib64/lib/' -i.orig gcc/config/i386/t-linux64
;;
esac
Override the building rule of libgcc and libstdc++ headers, to allow building these libraries with POSIX threads support:
sed '/thread_header =/s/@.*@/gthr-posix.h/' \
-i libgcc/Makefile.in libstdc++-v3/include/Makefile.in
Before starting to build GCC, remember to unset any environment variables that override the default optimization flags.
Now prepare GCC for compilation:
../configure \
--build=$(../config.guess) \
--host=$LFS_TGT \
--target=$LFS_TGT \
LDFLAGS_FOR_TARGET=-L$PWD/$LFS_TGT/libgcc \
--prefix=/usr \
--with-build-sysroot=$LFS \
--enable-default-pie \
--enable-default-ssp \
--disable-nls \
--disable-multilib \
--disable-libatomic \
--disable-libgomp \
--disable-libquadmath \
--disable-libssp \
--disable-libvtv \
--enable-languages=c,c++
73
Linux From Scratch - Version 11.3
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:
ln -sv gcc $LFS/usr/bin/cc
74
Linux From Scratch - Version 11.3
and create new device nodes or symlinks, to ease the work of distro maintainers and system administrators. (See
Section 9.3.2.2, “Device Node Creation” for details.) If the host kernel supports devtmpfs, we can simply mount a
devtmpfs at $LFS/dev and rely on the kernel to populate it.
But some host kernels lack devtmpfs support; these host distros use different methods to create the content of /dev. So
the only host-agnostic way to populate the $LFS/dev directory is by bind mounting the host system's /dev directory. A
bind mount is a special type of mount that makes a directory subtree or a file visible at some other location. Use the
following command to do this.
mount -v --bind /dev $LFS/dev
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.
In other host systems /dev/shm is a mount point for a tmpfs. In that case the mount of /dev above will only create /dev/
shm as a directory in the chroot environment. In this situation we must explicitly mount a tmpfs:
if [ -h $LFS/dev/shm ]; then
mkdir -pv $LFS/$(readlink $LFS/dev/shm)
else
mount -t tmpfs -o nosuid,nodev tmpfs $LFS/dev/shm
fi
The -i option given to the env command will clear all the variables in the chroot environment. After that, only the HOME,
TERM, PS1, and PATH variables are set again. The TERM=$TERM construct sets the TERM variable inside chroot to the same
value as outside chroot. This variable is needed so programs like vim and less can operate properly. If other variables
are desired, such as CFLAGS or CXXFLAGS, this is a good place to set them.
From this point on, there is no need to use the LFS variable any more because all work will be restricted to the LFS file
system; the chroot command runs the Bash shell with the root (/) directory set to $LFS.
Notice that /tools/bin is not in the PATH. This means that the cross toolchain will no longer be used.
Note that the bash prompt will say I have no name! This is normal because the /etc/passwd file has not been created yet.
76
Linux From Scratch - Version 11.3
Warning
The FHS does not mandate the existence of the directory /usr/lib64, and the LFS editors have decided not
to use it. For the instructions in LFS and BLFS to work correctly, it is imperative that this directory be non-
existent. From time to time you should verify that it does not exist, because it is easy to create it inadvertently,
and this will probably break your system.
Create a basic /etc/hosts file to be referenced in some test suites, and in one of Perl's configuration files as well:
cat > /etc/hosts << EOF
127.0.0.1 localhost $(hostname)
::1 localhost
EOF
In order for user root to be able to login and for the name “root” to be recognized, there must be relevant entries in
the /etc/passwd and /etc/group files.
Create the /etc/passwd file by running the following command:
cat > /etc/passwd << "EOF"
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/dev/null:/usr/bin/false
daemon:x:6:6:Daemon User:/dev/null:/usr/bin/false
messagebus:x:18:18:D-Bus Message Daemon User:/run/dbus:/usr/bin/false
uuidd:x:80:80:UUID Generation Daemon User:/dev/null:/usr/bin/false
nobody:x:65534:65534:Unprivileged User:/dev/null:/usr/bin/false
EOF
78
Linux From Scratch - Version 11.3
The created groups are not part of any standard—they are groups decided on in part by the requirements of the Udev
configuration in Chapter 9, and in part by common conventions employed by a number of existing Linux distributions.
In addition, some test suites rely on specific users or groups. The Linux Standard Base (LSB, available at https://
refspecs.linuxfoundation.org/lsb.shtml) only recommends that, besides the group root with a Group ID (GID) of 0, a
group bin with a GID of 1 be present. The GID of 5 is widely used for the tty group, and the number 5 is also used in /
etc/fstab for the devpts filesystem. All other group names and GIDs can be chosen freely by the system administrator
since well-written programs do not depend on GID numbers, but rather use the group's name.
The ID 65534 is used by the kernel for NFS and separate user namespaces for unmapped users and groups (those exist
on the NFS server or the parent user namespace, but “do not exist” on the local machine or in the separate namespace).
We assign nobody and nogroup to avoid an unnamed ID. But other distros may treat this ID differently, so any portable
program should not depend on this assignment.
Some tests in Chapter 8 need a regular user. We add this user here and delete this account at the end of that chapter.
echo "tester:x:101:101::/home/tester:/bin/bash" >> /etc/passwd
echo "tester:x:101:" >> /etc/group
install -o tester -d /home/tester
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:
exec /usr/bin/bash --login
79
Linux From Scratch - Version 11.3
7.7. Gettext-0.21.1
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: 1.0 SBU
Required disk space: 287 MB
81