Configurez un bon environnement de travail en créant deux nouveaux
fichiers de démarrage pour le shell bash. En étant connecté en tant
qu'utilisateur lfs
, lancez la
commande suivante pour créer un nouveau .bash_profile
:
cat > ~/.bash_profile << "EOF"
exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
EOF
When logged on as user lfs
, or when
switched to the lfs
user using an
su command with the
« -
» option, the
initial shell is a login shell
which reads the /etc/profile
of the
host (probably containing some settings and environment variables)
and then .bash_profile
. The
exec env -i.../bin/bash
command in the .bash_profile
file
replaces the running shell with a new one with a completely empty
environment, except for the HOME
,
TERM
, and PS1
variables. This ensures that no unwanted and potentially hazardous
environment variables from the host system leak into the build
environment.
The new instance of the shell is a non-login shell, which does not read, and
execute, the contents of the /etc/profile
or .bash_profile
files, but rather reads, and
executes, the .bashrc
file instead.
Create the .bashrc
file now:
cat > ~/.bashrc << "EOF"
set +h
umask 022
LFS=/mnt/lfs
LC_ALL=POSIX
LFS_TGT=$(uname -m)-lfs-linux-gnu
PATH=/usr/bin
if [ ! -L /bin ]; then PATH=/bin:$PATH; fi
PATH=$LFS/tools/bin:$PATH
CONFIG_SITE=$LFS/usr/share/config.site
export LFS LC_ALL LFS_TGT PATH CONFIG_SITE
EOF
Voici la signification des paramètres dans .bashrc
set
+h
The set +h
command turns off bash's hash function. Hashing
is ordinarily a useful feature—bash uses a hash table to
remember the full path to executable files to avoid searching
the PATH
time and again to find the
same executable. However, the new tools should be used as soon
as they are installed. Switching off the hash function forces
the shell to search the PATH
whenever a program is to be run. As such, the shell will find
the newly compiled tools in $LFS/tools/bin
as soon as they are available
without remembering a previous version of the same program
provided by the host distro, in /usr/bin
or /bin
.
umask
022
Configurer le masque de création de fichier (umask) à 022 nous
assure que les nouveaux fichiers et répertoires créés sont
modifiables uniquement par leurs propriétaires mais lisibles et
exécutables par tout le monde (en supposant que l'appel système
open(2)
utilise les modes par
défaut, les nouveaux fichiers finiront avec les droits 644 et
les répertoires avec les droits 755).
LFS=/mnt/lfs
La variable LFS
devrait être
configurée avec le point de montage choisi.
LC_ALL=POSIX
The LC_ALL
variable controls the
localization of certain programs, making their messages follow
the conventions of a specified country. Setting LC_ALL
to « POSIX »
or « C » (the two are equivalent) ensures
that everything will work as expected in the cross-compilation
environment.
LFS_TGT=(uname
-m)-lfs-linux-gnu
The LFS_TGT
variable sets a
non-default, but compatible machine description for use when
building our cross-compiler and linker and when cross-compiling
our temporary toolchain. More information is provided by
Notes
techniques sur la chaîne d'outils.
PATH=/usr/bin
Many modern Linux distributions have merged /bin
and /usr/bin
. When this is the case, the standard
PATH
variable should be set to
/usr/bin/
for the
Chapitre 6 environment. When this is not the case, the
following line adds /bin
to the
path.
if [ ! -L /bin ];
then PATH=/bin:$PATH; fi
If /bin
is not a symbolic link,
it must be added to the PATH
variable.
PATH=$LFS/tools/bin:$PATH
By putting $LFS/tools/bin
ahead
of the standard PATH
, the
cross-compiler installed at the beginning of
Chapitre 5 is picked up by the shell immediately after
its installation. This, combined with turning off hashing,
limits the risk that the compiler from the host is used instead
of the cross-compiler.
CONFIG_SITE=$LFS/usr/share/config.site
Dans le
Chapitre 5 et le
Chapitre 6, si cette variable n'est pas initialisée,
les scripts configure peuvent essayer de
charger des bouts de configuration de certaines distributions
dans /usr/share/config.site
sur
le système hôte. Changer ce chemin permet d'éviter une
contamination potentielle par l'hôte.
export
...
While the preceding commands have set some variables, in order to make them visible within any sub-shells, we export them.
Several commercial distributions add an undocumented instantiation
of /etc/bash.bashrc
to the
initialization of bash. This file has the potential
to modify the lfs
user's
environment in ways that can affect the building of critical LFS
packages. To make sure the lfs
user's environment is clean, check for the presence of /etc/bash.bashrc
and, if present, move it out of
the way. As the root
user, run:
[ ! -e /etc/bash.bashrc ] || mv -v /etc/bash.bashrc /etc/bash.bashrc.NOUSE
When the lfs
user is no longer
needed (at the beginning of
Chapitre 7), you may safely restore /etc/bash.bashrc
(if desired).
Remarquez que le paquet Bash de LFS que nous construisons dans la
Section 8.34, « Bash-5.2 »
n'est pas configuré pour charger ou exécuter /etc/bash.bashrc
, donc ce fichier est inutile sur
un système LFS.
Finally, to ensure the environment is fully prepared for building the temporary tools, force the bash shell to read the new user profile:
source ~/.bash_profile