1 TITLE: Keeping chapter 5 and chapter 6 separate (v1.1)
2 LFS VERSION: 3.1 (may need small changes for later versions)
3 AUTHOR: Matthias S. Benkmann <m.s.b@gmx.net>
6 The way LFS is built now, the static programs from chapter 5 are
7 overwritten in chapter 6. So when you begin building your chapter 6
8 system, your $LFS filesystem is populated by hundreds of files you
9 don't want to keep. During the chapter 6 process there is
10 a confusing mix of chapter 5 and chapter 6 files and in the end you
11 can't be sure whether your LFS system is really "clean" or retains
12 some "dirt" from the host distro.
13 When I built my first LFS, my host system was very different from
14 the LFS target (libc5 vs libc6). I ended up with a whole
15 /usr/lib/gcc-lib/<architecture> directory tree remaining and several
16 unreplaced header files. I've had an uneasy feeling regarding the
17 current building method ever since.
18 But this is over now. With a few changes to the book, you can
19 build chapter 5 and chapter 6 completely separate.
23 ##############################################################################
25 ##############################################################################
27 2002-01-30 -added Changelog
28 -create awk symlink in chapter 5 because gcc needs it
31 2002-02-06 -added findutils patch instruction
34 2002-03-16 -added remark that "mv chroot ../sbin" needs to be skipped when
35 installing sh-utils in chapter 5
38 2002-02-19 -changed LFS VERSION header so that I don't have to keep
42 ##############################################################################
44 ##############################################################################
46 The idea behind this hint is simple: Chapter 5 gets built in $LFS/static
47 rather than $LFS. By setting the PATH correctly in chroot, the
48 binaries are still accessible, although they don't "pollute" the main
49 directory tree. The advantages of this approach are the following:
51 - no stale files from chapter 5 remain in the LFS system
53 - you can use the same chapter 5 static tree to build multiple LFS systems
55 - if you forgot a package from chapter 5 you can safely install it to the
56 static tree later, without the risk of overwriting chapter 6 files
58 - you can restart chapter 6 after something went wrong without having to
61 - you can build the chapter 5 system on a different partition or mount it
62 from a CD-ROM, etc. to use less disk space on the target LFS partition
64 - it just feels better
67 ##############################################################################
69 ##############################################################################
72 1. You _DON'T_ create the Unix directory tree in chapter 4. After mounting
73 your new partition you only do the following
74 mkdir -p $LFS/static/usr/src
77 1. There is no need to install chapter 5 as root. Just make $LFS/static
78 (and subdirectories) writeable by an ordinary user account and build with
79 that account. It will prevent you from screwing up your host system.
81 2. Keep and unpack all tarballs in (subdirectories of) $LFS/static/usr/src
82 and install from there.
84 3. Install the packages according to the book, but wherever the book
85 uses $LFS, use $LFS/static instead. To make it easier you could instead do
86 `export LFS=$LFS/static'. But be careful with that as it's easy to get
87 confused that way and the rest of this hint will assume you do *not*
88 put "/static" into $LFS.
90 4. When building GCC, pass `--prefix=/static/usr' to ./configure instead of
92 Do NOT create the cpp symlinks. It is not necessary.
93 The cc symlink is created in $LFS/static/usr/bin.
95 5. Skip the installation of the Linux headers. We'll install them later.
97 6. mawk wants to install a manpage to $LFS/static/usr/share/man/man1 which
98 it doesn't create. You have to create this directory manually before
99 installing mawk. After installing mawk use the command
100 ln -s mawk $LFS/static/usr/bin/awk
101 to create the alias awk for mawk which is needed by GCC in chapter 6.
103 7. When you install sh-utils, skip the command "mv chroot ../sbin".
104 If you install sh-utils as a non-root user you will get a warning
105 message about lack of privileges and the su program will not be
106 installed. Ignore this message. A static su is not needed for building
107 LFS. In chapter 6 we do the sh-utils installation as root and the dynamic
108 su will be properly installed (just to be overwritten by the one from
111 8. Unpack the util-linux package, enter the util-linux-* directory and
112 compile a static version of the mount utility according to the following
113 instructions. The cp command assumes that /static is not part of your
114 $LFS variable. If it is, drop the /static from the cp command.
117 cp defines.h defines.h.old &&
118 sed /ENABLE_NLS/d defines.h.old >defines.h &&
120 make -C mount LDFLAGS=-static &&
121 cp mount/{mount,umount} $LFS/static/bin/
123 9. Build a static version of findutils using the following commands
124 (again I assume /static is not part of $LFS):
126 patch -Np1 -i ../findutils-4.1.patch &&
127 ./configure --prefix=$LFS/static/usr --disable-nls &&
128 make LDFLAGS=-static CPPFLAGS=-Dre_max_failures=re_max_f2 &&
129 make libexecdir=$LFS/static/usr/bin install
132 You have now finished the instructions from the last section in
133 chapter 5 titled "Installing <package>" and have compiled the additional
134 static mount and umount binaries and findutils. The next section in the
135 book would be "Creating passwd and group files", which I refer to as
137 Here is the clean break that this hint gives you. If you keep a copy
138 of your $LFS/static tree you never need to go further back than
139 chapter 5 1/2 when building an LFS system. You can just start reading
140 here at this point in the hint. The following commands do not assume
141 write access to $LFS/static, so you can burn it on a CD and mount it
142 from there. This will help you save a lot space.
144 Unlike the book which creates part of the LFS system from outside the
145 LFS system, if you follow this hint you create everything from inside
146 the LFS system. To achieve this we enter the chroot environment right
147 now, BEFORE creating the Unix directory structure, passwd or group
148 files,... This gives us a completely naked system. Everything from
149 the outside world is contained inside the /static directory tree which
150 can be wiped later. Everything we will keep on our LFS system is created
151 from inside the new LFS system.
153 A little side note: You can avoid chroot altogether and just boot a
156 init=/static/bin/bash root=<new LFS partition>
158 For this to work you will need a directory /dev on <new LFS partition>
159 that contains one or more of the following devices
160 /dev/tty1, /dev/console, /dev/tty
161 [IF SOMEONE KNOWS EXACTLY WHICH IS/ARE NEEDED, MAIL ME]
164 1. Enter the chroot environment using the following command (as root):
167 chroot $LFS /static/usr/bin/env -i HOME=/root TERM=$TERM \
168 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/static/bin:/static/usr/bin \
169 SHELL=/static/bin/bash PS1='\u:\w\$ ' /static/bin/bash --login
171 If you get the error message "--login: No such file or directory"
172 you forgot the space between the PS1='\u:\w\$ ' and /static/bin/bash.
173 It's easy to overlook because of the space before the closing quote.
175 Note that the bash prompt will contain "I have no name!" This is normal
176 because Glibc hasn't been installed yet.
178 "And / was without form, and void; and darkness was upon the face of
179 the prompt. And the Spirit of Root moved upon the face of chroot."
181 2. "And Root said, let there be a directory structure in the midst of chroot."
183 Before we start creating directories, we need to check the base system's
184 umask setting. To do this, we run umask. The result should be 022. If it
185 isn't, then run the following command to ensure that the directories will
186 be created with the correct permissions:
190 We would advise you to make sure that the umask is set to 022 throughout
191 your LFS installation.
193 Let's now create the directory tree on the LFS partition based on the FHS
194 standard, which can be found at http://www.pathname.com/fhs/. Issuing the
195 following commands will create a default directory layout:
197 mkdir -p bin boot dev/pts etc/opt home lib mnt proc root sbin tmp var opt
198 for dirname in /usr /usr/local
202 mkdir bin etc include lib sbin share src var
205 ln -s share/info info
207 mkdir dict doc info locale man nls misc terminfo zoneinfo
208 cd $dirname/share/man
209 mkdir man{1,2,3,4,5,6,7,8}
212 mkdir -p lock log mail run spool tmp opt cache lib/misc local
214 mkdir bin doc include info lib man
218 Normally, directories are created with permission mode 755, which isn't
219 desired for all directories. The first change is a mode 0750 for the
220 /root directory. This is to make sure that not just everybody can
221 enter the /root directory (the same a user would do with /home/username
222 directories). The second change is a mode 1777 for the tmp directories.
223 This way, any user can write data to the /tmp or /var/tmp directory but
224 cannot remove another user's files (the latter is caused by the so-called
225 "sticky bit" - bit 1 of the 1777 bit mask).
229 chmod 1777 tmp var/tmp
231 3. "And Root said, Let the processes of the system be gathered together unto
232 one place, and let the proc filesystem appear: and it was so."
234 mount -n -t proc proc /proc
236 If you ever leave the chroot environment for any reason (when
237 rebooting for example) please remember to re-enter chroot and to
238 remount /proc again before continuing with the book.
240 4. Now we create /etc/passwd and /etc/group
242 echo "root:x:0:0:root:/root:/bin/bash" > /etc/passwd
244 cat > /etc/group << "EOF"
259 5. Right now we have our tarballs in /static/usr/src but we don't want to
260 build inside that directory (if it's mounted from CDROM we couldn't even
261 if we wanted to). We could copy the tarballs to /usr/src/ but that would be
262 a waste of diskspace, so we use symlinks. We do need to have real
263 subdirectories in /usr/src, though, because symlinks would cause us
264 to write to the /static directory. So what we do is to copy the directory
265 structure of /static/usr/src but symlink the files contained therein:
268 for d in $(find /static/usr/src -type d -not -path "/static/usr/src") ;\
269 do mkdir -p ${d#/static/usr/src/} ; done
271 Be careful with the above command. Do NOT forget the "/" before "}" in
272 "${d#/static/usr/src/}". It is significant!!
273 Now we have the directories. Let's create the symlinks:
276 find src -not -type d -exec ln -s /static/usr/{} /usr/{} \;
278 6. There are some additional symlinks we need to create:
280 ln -s /static/bin/bash /bin/bash &&
281 ln -s /static/bin/sh /bin/sh &&
282 ln -s /static/usr/bin/cpp /lib/cpp &&
283 ln -s /static/bin/pwd /bin/pwd
285 Explanation: cpp is needed for glibc compilation,
286 pwd for linux's `make config'
291 0. First a word of warning: Resist the urge to build several packages in
292 parallel, even if it seems to work. Some packages would hardwire paths
293 to programs in the /static tree into their executables or data files.
294 This does not always show in the build output, the compile will be
295 successful. You won't notice until a program fails with a
296 "/static/...: no such file or directory" or similar error message.
298 1. You may create a $LFS/root/.bash_profile as the book instructs but it
299 is not necessary. The chroot command given above already sets the
300 prompt and the PATH correctly. If you do want to create a .bash_profile,
301 do not forget to make the following change:
304 PATH=/bin:/usr/bin:/sbin:/usr/sbin
308 PATH=/bin:/usr/bin:/sbin:/usr/sbin:/static/bin:/static/usr/bin
310 i.e. add "/static/bin:/static/usr/bin" at the _end_ of PATH.
312 2. Before we install glibc, we need to install the Linux kernel headers.
313 If you exited chroot for some reason, enter it again (we're doing
314 everything from inside chroot, remember!) and don't forget to remount
315 /proc if it was unmounted.
317 Now install the Linux kernel headers with the following commands
318 (from inside a freshly untarred /usr/src/linux):
320 yes "" | make config &&
321 make include/linux/version.h &&
323 cp -a linux /usr/include/ &&
324 chown -R 0.0 /usr/include/linux &&
325 mkdir /usr/include/asm &&
326 cp -a asm/* /usr/include/asm &&
327 chown -R 0.0 /usr/include/asm
330 3. Now install the chapter 6 packages in the following order (see
331 Appendix A for details about the changes compared to the standard book):
333 glibc (makedev) gcc man-pages findutils mawk ncurses vim bison less
334 groff textutils sed flex binutils fileutils sh-utils gettext net-tools
335 perl m4 texinfo autoconf automake bash file libtool bin86 bzip2
336 ed kbd diffutils e2fsprogs grep gzip man lilo make modutils
337 netkit-base patch procinfo procps psmisc shadow sysklogd sysvinit
340 The building instructions for some packages have to be changed slightly:
342 - When installing man, replace the line
344 ./configure -default &&
346 with the line (Note that the PATH=... is NOT a separate command!)
348 PATH="$PATH:/usr/bin:/bin" ./configure -default &&
350 Explanation: The paths to some programs get written into man's files.
351 Unfortunately the stupid configure script picks the last
352 location in PATH rather than the first where a program is found.
353 By appending /usr/bin:/bin to PATH for the ./configure command we make
354 sure that man doesn't use the /static versions of our programs.
356 - After installing bash, do the following:
361 Explanation: Replaces the sh symlink that points to the static shell
362 with the a symlink that points to the new bash.
364 Note: You don't need to do `exec /bin/bash' after installing bash (it
365 doesn't hurt, though), because we didn't overwrite the running shell's
368 - After installing GCC, do the following:
371 ln -sf ../usr/bin/cpp &&
377 Explanation: These are the same links as created in chapter 5, but
378 in chapter 5 we created them in /static.
380 - After installing Fileutils, do the following:
383 ln -sf ../../bin/install
385 Explanation: This is the same link as created in chapter 5, but
386 in chapter 5 we created it in /static.
388 - In the installation of bzip2, ignore the line
389 rm /usr/lib/libbz2.a &&
390 because the file has been created in /static/usr/lib during chapter 5,
393 Configuring essential software
395 We are now completely back on track with the book (you may or may not
396 want to remove the /static tree now). Continue with the standard
397 instructions from the book at "Configuring essential software".
400 Resolving the /static symlinks
402 You may want to replace the symlinks in /usr/src that point into the /static
403 tree with the real files after installing the system. The following script
407 find /usr/src -type l -printf "%l %p %u %g\n" |
416 cp -a $1 $2 || exit 1
417 chown $3.$4 $2 || exit 1
426 FINAL NOTE: If you take the time to grep through all your files for
427 "/static" (Be careful to exclude /proc from your scan as reading some files
428 in /proc can cause disk corruption) you will notice that "/static/*" paths
429 are still found in many libraries, such as libc.a.
430 Don't panic. Your system will not break if you delete the /static tree.
431 This is only debugging information. If you do
432 strip --strip-debug /lib/* /usr/lib/*
433 , these paths will disappear and there will remain no trace of the
438 Appendix A The package ordering changes (compared to LFS-3.0) in detail:
440 Installing GCC as soon as possible is just a good idea. It is not
441 related to this hint.
443 You must install textutils before man, before perl and before bash,
444 because man hardwires cat's location into its executable and because
445 perl and bash have the path to cat hardwired as /bin/cat or /usr/bin/cat
446 in some configure scripts so that they don't find the /static version.
447 Note that textutils will output a warning if it doesn't find Perl. As
448 the warning says, this is only relevant if you change the textutils
451 You must install sed before Perl because Perl hardwires its location into
453 You must install binutils before Perl because Perl writes the path to
456 Install fileutils before Perl because the path to ln gets written to
458 Note that fileutils will output another one of those warning messages
459 that are only relevant if you change the sources
460 (or want to use `make check').
462 Perl writes the location of hostname to Config.pm, so net-tools should
463 be installed before Perl. Because net-tools has /usr/bin/env hardwired
464 into its configure script, sh-utils must be installed before net-tools.
465 This means that sh-utils is also installed before Perl and will
466 output one of those annoying but harmless warnings.
467 I am aware of the fact that you could install sh-utils before Perl and
468 install net-tools later, because sh-utils has hostname, too.
469 However, it is a mistake that the book does not have a sed command to
470 suppress sh-utils hostname and instead relies on the overwriting of
471 hostname by net-tools later. If the book had this sed, fewer people would
472 encounter the "Why is my machine suddenly called `-f'" problem. People
473 who write install scripts that are supposed to work for reinstalling
474 a package later, MUST suppress sh-utils' hostname and consequently
475 have to install net-tools before Perl.
477 You must install fileutils before kbd because the latter has
478 /usr/bin/install hardwired so that it doesn't find the /static version.
480 sh-utils must be installed before net-tools, because the latter has
481 /usr/bin/env hardwired. The LFS package order already has sh-utils
482 before net-tools but impatient people might try to start building
483 net-tools in a different console before sh-utils has finished. Don't
486 gettext needs to be installed before net-tools if you want i18n.
488 Install binutils before libtool because libtool hardwires the paths
489 to ld and nm into its executable.
491 Install sed before e2fsprogs because the latter hardwires sed's location
494 You must install gzip, bzip2, textutils and diffutils before man because
495 man writes their paths into several of its files.
497 Flex is installed before binutils to avoid a warning. As this is another
498 warning that is only relevant if you changed the binutils sources,
499 this is just a cosmetic issue.