From 490dc15317e18e4f87d2a2555adc6ce2c2a774ba Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Sat, 5 Feb 2022 11:36:39 +0800 Subject: [PATCH] remove "+h" in bash commands in chroot (#4998) In the new cross-compilation approach, the $PATH in chroot does not contain '/tools/bin'. So "+h" is useless in chroot as the newly installed tools always replace the temporary counterpart at the same location. "+h" in chapter4/settingenviron.xml is kept deliberately. Currently $LFS/tools/bin only contains programs prefixed with "x86_64-lfs-linux-gnu-", and it's highly unlikely that any distro will ever ship a program named with such prefix. So it may seems that we can remove this "+h" as well. However, the situation may change in future and we can take this oppertunity to teach the advantage and disvantage of bash hash feature. --- chapter01/changelog.xml | 5 +++++ chapter04/settingenviron.xml | 8 +++++--- chapter07/chroot.xml | 7 ++----- chapter07/createfiles.xml | 9 +-------- chapter08/bash.xml | 8 +------- chapter08/revisedchroot.xml | 22 ---------------------- 6 files changed, 14 insertions(+), 45 deletions(-) diff --git a/chapter01/changelog.xml b/chapter01/changelog.xml index 155b12f50..217aad0d1 100644 --- a/chapter01/changelog.xml +++ b/chapter01/changelog.xml @@ -42,6 +42,11 @@ 2022-02-04 + + [xry111] - Rename bash + +h directives in chroot. Fixes + #4998. + [xry111] - Update to man-db-2.10.0. Fixes #5002. diff --git a/chapter04/settingenviron.xml b/chapter04/settingenviron.xml index 4c419d00a..b0c3441e5 100644 --- a/chapter04/settingenviron.xml +++ b/chapter04/settingenviron.xml @@ -64,9 +64,11 @@ EOF be used as soon as they are installed. By switching off the hash function, the shell will always search the PATH when a program is to be run. As such, the shell will find the newly compiled tools in - $LFS/tools as soon as they are - available without remembering a previous version of the same program in a - different location. + $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. diff --git a/chapter07/chroot.xml b/chapter07/chroot.xml index d018cb218..6404c0625 100644 --- a/chapter07/chroot.xml +++ b/chapter07/chroot.xml @@ -23,7 +23,7 @@ TERM="$TERM" \ PS1='(lfs chroot) \u:\w\$ ' \ PATH=/usr/bin:/usr/sbin \ - /bin/bash --login +h + /bin/bash --login The -i option given to the env command will clear all variables of the chroot environment. After that, only @@ -44,10 +44,7 @@ Notice that /tools/bin is not in the PATH. This means that the cross toolchain will no longer be - used in the chroot environment. This occurs when the shell does not - remember the locations of executed binaries—for this - reason, hashing is switched off by passing the +h option - to bash. + used in the chroot environment. Note that the bash prompt will say I have no name! This is normal because the diff --git a/chapter07/createfiles.xml b/chapter07/createfiles.xml index 9c4f6ac54..009806b3f 100644 --- a/chapter07/createfiles.xml +++ b/chapter07/createfiles.xml @@ -184,14 +184,7 @@ install -o tester -d /home/tester files have been created, user name and group name resolution will now work: -exec /usr/bin/bash --login +h - - Note the use of the +h directive. This tells - bash not to use its internal path hashing. Without this - directive, bash would remember the paths to binaries it has - executed. To ensure the use of the newly compiled binaries as soon as they are - installed, the +h directive will be used for the duration - of this and the next chapter. +exec /usr/bin/bash --login The login, agetty, and init programs (and others) use a number of log diff --git a/chapter08/bash.xml b/chapter08/bash.xml index 36bbcf0d9..787882b59 100644 --- a/chapter08/bash.xml +++ b/chapter08/bash.xml @@ -94,13 +94,7 @@ EOF Run the newly compiled bash program (replacing the one that is currently being executed): - exec /usr/bin/bash --login +h - - - The parameters used make the bash - process an interactive login shell and continues to disable hashing so - that new programs are found as they become available. - + exec /usr/bin/bash --login diff --git a/chapter08/revisedchroot.xml b/chapter08/revisedchroot.xml index bc519d491..52c74a381 100644 --- a/chapter08/revisedchroot.xml +++ b/chapter08/revisedchroot.xml @@ -14,28 +14,6 @@ rm -rf /tmp/* - Now log out and reenter the chroot environment with an updated - chroot command. From now on, use this updated chroot command any time - you need to reenter the chroot environment after exiting: - -logout - -chroot "$LFS" /usr/bin/env -i \ - HOME=/root TERM="$TERM" \ - PS1='(lfs chroot) \u:\w\$ ' \ - PATH=/usr/bin:/usr/sbin \ - /usr/bin/bash --login - - Here the +h option is not used anymore, since - all the previous programs have been replaced: hashing is therefore - possible. - - If the virtual kernel file systems have been unmounted, either manually - or through a reboot, ensure that the virtual kernel file systems are mounted - when reentering the chroot. This process was explained in and . - There are also several files installed in the /usr/lib and /usr/libexec directories with a file name extension of .la. These are "libtool archive" files. As already said, they are only useful when linking with static