Keeping chapter 5 and chapter 6 separate

Matthias Benkmann haferfrost at web.de
Sun Oct 21 04:22:42 PDT 2001


A while ago I suggested to build chapter 5 in a separate directory /static 
to avoid mixing chapter 5 and 6 files. I have successfully built a system 
with this (instructions attached to this mail) and suggest that the LFS 
book adopt this method.
With this method I suggest moving the creation of directories, mounting of 
/proc, copying of NSS files and linux headers and creating of passwd and 
group to chapter 6. This would allow someone to do

find $LFS -maxdepth 1 -not -path "*/static" -exec rm -r \{\} \;

and then start with chapter 6 again without having to look at anything in 
earlier chapters. In other words we would get a clean restart point, 
something that LFS currently doesn't have. Right now the only safe way 
when you discover problems in chapter 6 is to wipe everything and start 
with chapter 5 again which wastes considerable time. There are other 
advantages, too (see the attached file).

MSB

----
In allen Kulturen haben Muetter ihre Babys mit Vorgekautem
von Mund zu Mund gefuettert.
Bis vor kurzem sogar noch in Schleswig-Holstein.

Irenaeus Eibl-Eibesfeldt im SZ Magazin, No.28


-------------- next part --------------
TITLE:		Keeping chapter 5 and chapter 6 separate
LFS VERSION:	3.0 (probably works for others, too)
AUTHOR:		Matthias S. Benkmann <m.s.b at gmx.net>

SYNOPSIS:
	The way LFS is built now, the static programs from chapter 5 are
	overwritten in chapter 6. So when you begin building your chapter 6
	system, your $LFS filesystem is populated by hundreds of files you
	don't want to keep. During the chapter 6 process there is
	a confusing mix of chapter 5 and chapter 6 files and in the end you
	can't be sure whether your LFS system is really "clean" or retains
	some "dirt" from the host distro.
	When I built my first LFS, my host system was very different from 
	the LFS target (libc5 vs libc6). I ended up with a whole 
	/usr/lib/gcc-lib/<architecture> directory tree remaining and several
	unreplaced header files. I've had an uneasy feeling regarding the
	current building method ever since.
	But this is over now. With a few changes to the book, you can
	build chapter 5 and chapter 6 completely separate.

HINT:

The idea behind this hint is simple: Chapter 5 gets built in $LFS/static
rather than $LFS. By setting the PATH correctly in chroot, the
binaries are still accessible, although they don't "pollute" the main
directory tree. The advantages of this approach are the following:

- no stale files from chapter 5 remain in the LFS system

- you can use the same chapter 5 static tree to build multiple LFS systems

- you can restart chapter 6 after something went wrong without having to
  redo chapter 5
  
- you can build the chapter 5 system on a different partition or mount it
  from a CD-ROM, etc. to save space on the target LFS partition
  
- it just feels better


##############################################################################
                           How to do it 
##############################################################################

Chapter 4:
  1. The directory is created in $LFS as usual. In addition to this you do
       mkdir $LFS/static
     to create the directory for the chapter 5 build. 
     NOTE: There is *no* need to create the Unix directory structure in
     $LFS/static, too. The chapter 5 packages will create the necessary
     directories themselves.
     
Chapter 5:
  1. There is no need to install chapter 5 as root. Just make $LFS/static
     writeable by an ordinary user account and build as that account.
     It will prevent you from screwing up your host system.
          
  2. You need not do it like this but I recommend that you create the directory
     $LFS/static/src and keep and unpack all tarballs in there (possibly
     in subdirectories). If you decide to wipe out and restart chapter 6 later,
     you won't have to worry about accidentaly wiping your sources. 
     If you follow my advice from 1., you have no choice but to use a 
     directory that is writeable by your user account. You could make
     $LFS/usr/src writeable by that account but this is not pretty once you
     enter chroot where that account doesn't exist.
     
  3. Install the packages according to the book, but wherever the book
     uses $LFS, use $LFS/static instead. To make it easier you could instead do
     `export LFS=$LFS/static'.
     
  4. There is one exception from rule 3. The kernel header files must be
     installed in $LFS/usr/include and the kernel sources must be unpacked
     in $LFS/usr/src/include. Both must be owned by root, so install the
     kernel as root according to the book *without* substituting $LFS/static
     for $LFS.
  
  5. When building GCC, pass `--prefix=/static/usr' to ./configure instead of
     `--prefix=/usr'
     
  6. There is one binary that is not found through path and that is /bin/sh,
     because it is hardwired in shell scripts. Therefore you need to do
        ln -sf ../static/bin/bash $LFS/bin/sh
     (be careful if you include the /static in your LFS variable. If you do
     that you have to use ln -sf ../static/bin/bash $LFS/../bin/sh)
     
   7. passwd and group must be created in $LFS/etc, *not* $LFS/static/etc.
      The NSS library files, if you need to copy them, must also go to $LFS
      and *not* $LFS/static.
      The /proc filesystem must be mounted at $LFS, *not* $LFS/static.  
     
Chapter 6:
   1. /root/.bash_profile must be created in $LFS/root, *not* $LFS/static/root.
      Instead of 
           PATH=/bin:/usr/bin:/sbin:/usr/sbin
      you have to put
           PATH=/bin:/usr/bin:/sbin:/usr/sbin:/static/bin:/static/usr/bin
      into /root/.bash_profile.
      
   2. Enter the chroot environment as follows (note that this is $LFS,
      *not* $LFS/static)

           cd $LFS &&
           chroot $LFS /static/usr/bin/env -i HOME=/root \
           TERM=$TERM /static/bin/bash --login
   
   3. I installed GCC right after GLIBC (and creating the devices) when I 
      did the /static build and I recommend, you do that, too. 
      This may require that you build a static version of findutils in 
      chapter 5 (I don't know if it's really necessary. I always do it 
      because I need find for other things.)
      If you don't recompile GCC right after GLIBC, and any of the packages 
      compiled in the book before gcc have the path to gcc hardwired, 
      they will fail. If that is the case please report it to me.
 
   4. You must install textutils before bash. I didn't write down why and I
      don't remember but I guess it's because bash's configure or Makefile 
      has some path hardwired
      so that it doesn't find the /static version of a certain utility.
      
   5. The bash instructions in LFS 3.0 don't repeat the creating of the sh 
      symlink but because if you follow this hint, /bin/sh is still the
      static shell you have to do
        ln -sf bash /bin/sh
      after the installation of bash.  
   
   6. You can skip the `exec /bin/bash --login' after the installation of bash.
   
   7. You must install fileutils before kbd because the latter has
      /usr/bin/install hardwired so that it doesn't find the /static version.

   


More information about the hints mailing list