1 AUTHOR: Joseph M. Dupré <dupre avab com>
5 LICENSE: GNU Free Documentation License
7 SYNOPSIS: How to build a LFS 6.1 system using the LFS live CD as your
11 This hint should guide you through the process of building a LFS
12 system using the LFS live CD as the host operating system. You use
13 the LFS live CD to boot the computer instead of loading a pre-
14 packaged linux distribution like Debian or Red Hat. This is the
15 "cleanest" way to build a LFS system, since inconsistancies and
16 idiosyncracies of the various distributions are removed.
22 The prerequisists are the same as that of LFS. You will also need to
23 have the LFS live CD for the version of LFS that you intend to build.
24 I also assume that you know how to create and edit a text file with
25 an editor, rather than using redirected cat or echo commands. This
26 is not a hint on using the live CD, so any problems you encounter
27 using or booting your system with the live CD should be directed to
28 the LFS live CD mailing list.
30 This hint was written for LFS 6.1. Due to the rapidly changing
31 nature of linux, some of the scripts describe herein may break in
32 future versions of LFS. If you understand what the scripts are doing
33 and why, it should not be very difficult to adapt the scripts to
34 match future versions of LFS.
37 It was suggested that this hint could be reduced to "follow the
38 book". Well, almost. You could also use the ALFS profiles which are
39 included on the Live CD. But that is not the point. This hint
40 points out the difference of building LFS when booted up from a "Live
41 CD", specifically the LFS Live CD, as opposed to a pre-installed
42 linux distribution. This hint also provides a couple of scripts that
43 will make your job easier.
45 So yes, please follow the procedures in the LFS book. When something
46 differs when using the live cd environment, it will be pointed below
49 Although not specific to this hint, I do want to point out the
50 following since I assume that most people who will be reading this
51 are building LFS for the first time: When following the LFS book
52 note the difference between the "back-tick" [ ` ] and the single
53 quote [ ' ]. On a US keyboard the back-tick is on the key with the [
54 ~ ] and the single-quote is on the key with the [ " ]. Also,
55 capitalization matters. If you specify a configure or make option in
56 the wrong case, you may not get any warning and the build may fail or
57 exhibit problems later. A wrong charater is a "sed" command can
58 trash files. Think about what each command does before you hit the
59 enter key. If you don't understand what is happening, look it up
60 using the man pages. I learned more about Linux in general by
61 building my first LFS system then I did in several years of
62 administering a popular distribution.
64 In the command examples shown below the leading # is a prompt. Do
65 not type it. However, in the script examples, the leading #
66 indicates a line that is a comment. In this case you must type the #
67 within the script, or ignore the line completely.
69 So, begin at page one of the LFS book. When you get to the chapters
70 noted below, do what it says here...
73 By now you should have booted your system using the LFS live CD. All
74 the tools for creating a partition and creating a filesystem are
75 included in the live CD's operating system.
78 All the source packages and patches should be on the live CD in
79 /sources. You don't have to copy them all once to your lfs partition
80 if you do not have the space, but it makes life easier.
84 Since you create a link on the root of the live CD's filesystem, it
85 will be gone the next time you boot. We will add this link to a
89 Since the OS loaded from the CD can not be permanently damaged, there
90 is no reason to create a lfs user for safety. Ignore this chapter.
93 Read chapter 4.4, but don't do anything yet. The problem with using
94 a live CD to build your system is that everytime you reboot the
95 system, any special settings you have made to your user environment
96 are lost. You can't easily make a lfs user and a special build
97 environment by editing the user's .bash_profile and .bashrc files as
98 specified in this chapter. So instead, we will write a script that
99 sets up a "clean" environment. This script will have to be run each
100 time you leave the special build environment or re-boot the system.
102 The only place you have to store any settings that will remain the
103 next time you boot the live CD is the partion you created for your
104 LFS build. Although there may well be better solutions to this, this
105 is the method I used when building LFS 6.1. I am assuming that you
106 place all of the scripts mentioned in this hint in the root of your
109 cd to $LFS and create the following script using your favorite text
110 editor (provided that your favorite text editor is included on the
111 live cd). At the time of writing, you may use vim, nano or joe.
113 #################################################################
115 # Sets up clean environment for 6.1 Chapter 5
117 # Before this script is run, you must have executed the following
118 # after booting the live CD:
120 # export LFS=/mnt/lfs
122 # mount /dev/xxx $LFS (where xxx is your lfs partition)
124 # Create the link to tools as per Ch 4.2
127 # Set up the environment as per chapter 4.4
128 # This sets up a special environment for root based
129 # on the procedure for the user "lfs" which isn't
130 # necessary when running from the live CD.
132 echo "set +h" > ~/.bashrc
133 echo "LFS=/mnt/lfs" >> ~/.bashrc
134 echo "LC_ALL=POSIX" >> ~/.bashrc
135 echo "PATH=/tools/bin:/bin:/usr/bin" >> ~/.bashrc
136 echo "export LC_ALL PATH" >> ~/.bashrc
138 # This sets up key mapping so the delete key works:
139 cp /etc/inputrc ~/.inputrc
141 # Enter the special build environment
142 exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
145 ###################################################################
147 And now make the script file executable and run it:
148 # chmod 700 setenv.sh
151 Note the difference between the live CD shell prompt and the special
152 "build" environment prompt we have created here. You will be able to
153 easily see which environment you are in.
155 So, to recap, every time you reboot the system you will have to
156 execute the following commands to mount your LFS partition:
158 # export LFS=/mnt/lfs
160 # mount /dev/[xxx] $LFS
162 (Replace [xxx] with the partition that you have created for your LFS
165 Then, run the setenv script to set up a "clean" environment:
168 Now you can continue on with chapter 5...
170 When you are done with chapter 5, you may want to make a backup of
171 this partition using "Ghost" or some other backup tool. (Just in
172 case something goes wrong in the next chapter...) It could also be
173 used for a future build, or on another machine of the same
176 Turn off your machine and take a break. At least type "exit" to
177 leave the temporary build environment.
180 For the procedures in chapter 6 we will no longer be using the
181 setenv.sh script to set up the build environment. Instead we "chroot"
182 into the $LFS directory. This will require running a script to enter
183 the chroot environment, and then another script to configure the
184 temporaty filesystems and devices within that environment.
186 If you are still in the environment set up by setenv.sh, type exit to
187 return to the live CD root prompt. Or to be safe, reboot the live
192 Create the $LFS/proc and $LFS/sys directories, but do not mount the
193 file systems. We will mount the filesystems in the lfschroot.sh
197 It is assumed that during the build process you may want to take a
198 break and turn off your machine to save energy. Rather than retyping
199 all the commands required to chroot when you come back, we will put
200 them all in the following script.
202 ################################################################
204 # Changes root directory for use in LFS 6.1 Chapter 6
206 # Mount required filesystems
207 mount -t proc proc $LFS/proc
208 mount -t sysfs sysfs $LFS/sys
210 # These "fake mounts" are also needed now
211 mount -f -t ramfs ramfs $LFS/dev
212 mount -f -t tmpfs tmpfs $LFS/dev/shm
213 mount -f -t devpts -o gid=4,mode=620 devpts $LFS/dev/pts
216 echo "Do not forget to populate /dev !"
219 # Chroot into the LFS system with a reduced environment
220 chroot "$LFS" /tools/bin/env -i \
221 HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
222 PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
223 /tools/bin/bash --login +h
226 ###################################################################
228 Make the script executable with this command.
229 # chmod 700 lfschroot.sh
231 Enter the lfs chroot environment:
234 Ignore the reminder about populating /dev. I will cover that in
237 Once in the chroot environment a lot of things will be "broken". You
238 no longer have access to the text editors or many of the other tools
239 from the live CD. In fact, all you have to work with is what you
240 have installed in chapter 5.
243 Since we skipped creating the lfs user, you can skip this too. Note
244 that when in the chroot environment the files are allready owned by
245 0:0, whereas outside the in the live CD environment that are owned by
246 root:root. This is because the files are never really owned by
247 "root", they are owned by user 0 group 0. A "normal" OS translates
248 the user and group numbers to the user and group names specified in
249 /etc/passwd and /etc/group. Since we have no passwd or group files,
253 [Optional] I hate typing a bunch of stuff on the command line. I
254 like to make a script file so I can edit it and run it later if
255 necessary. For reasons mentioned above it is a bit difficult to do
256 that now in the chroot environment. You may want to consider exiting
257 now and creating scripts to perform the commands for chapters 6.5
258 through 6.7. (Or think about learning ALFS!)
261 Make the two nodes as decribed in 6.8.1
265 We are going to make a script for this, so that we can populate /dev
266 at will while building the rest of chapter 6. Exit the chroot
267 environment and create the following script in your $LFS directory to
268 load the device nodes.
270 #########################################################
272 # Based on LFS 6.1 Chapter 6.8.2
273 # This mounts a tempfs to /dev and populates
274 # the /dev directories with a minimal set of device nodes.
275 # ONLY RUN AFTER YOU HAVE CHROOTed INTO LFS DIRECTORY!!!
277 mount -n -t tmpfs none /dev
279 mknod -m 622 /dev/console c 5 1
280 mknod -m 666 /dev/null c 1 3
281 mknod -m 666 /dev/zero c 1 5
282 mknod -m 666 /dev/ptmx c 5 2
283 mknod -m 666 /dev/tty c 5 0
284 mknod -m 444 /dev/random c 1 8
285 mknod -m 444 /dev/urandom c 1 9
286 chown root:tty /dev/{console,ptmx,tty}
288 # These symbolic links are required by LFS
289 ln -s /proc/self/fd /dev/fd
290 ln -s /proc/self/fd/0 /dev/stdin
291 ln -s /proc/self/fd/1 /dev/stdout
292 ln -s /proc/self/fd/2 /dev/stderr
293 ln -s /proc/kcore /dev/core
295 # Mount the kernel filesystems within /dev
298 mount -t devpts -o gid=4,mode=620 none /dev/pts
299 mount -t tmpfs none /dev/shm
301 # Test to see if udev is built yet. If so, run it.
302 if [ -f /sbin/usevstart ]; then
307 #################################################################
310 So, for the rest of chapter 6, anytime you reboot, you must run the
313 # export LFS=/mnt/lfs
315 # mount /dev/[xxx] $LFS
319 (Replace [xxx] with the partition that you have created for your LFS
322 If you don't reboot, but only leave the build environment (with the
323 exit command), you may re-enter the chroot environment by running the
324 lfschroot and devpop scripts. Note that you will receive some
325 warnings, since the scripts try to mount filesystems that are
326 allready mounted. These are safe to ignore.
328 So, you can now continue by installing the packages in chapter 6...
331 Now that readline is installed, you can make the delete key work if
332 you want. Just create the files specified in chapters 7.8 & 7.9.
333 (You will have to exit and chroot again to have the changes take
337 If you followed the instructions, and you have not exited the build
338 enviromnent since Chapter 6.37 (Bash), you will be running the newly
339 installed bash executable. If so, exit the build environment and
344 Now you will be running the version of bash from the live CD.
345 Procede with stripping if desired.
348 If desired, remove the /tools directory. If you do this, you must
349 edit lfschroot.sh to remove the references to /tools from the chroot
350 command. And you can remove the +h bash option. Edit the chroot
351 command to look like this:
353 # Chroot into the LFS system with a reduced environment for Chapter 7
354 chroot "$LFS" /usr/bin/env -i \
355 HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
356 PATH=/bin:/usr/bin:/sbin:/usr/sbin \
361 So that's all there is to it.
363 [ This hint was tested with LFS 6.1, using LFS Live CD version x86-
364 6.1-2, the en-US-ISO8859-1 locale, and the US keymap on a Dell sc420
365 (i686) platform. An ext3 boot partition with grub-0.95 was allready
366 in existance created by Fedora Core 4, from which I had previously
367 removed the extended attributes. LFS was installed on a 2GB ext2
372 * Obviously, the creators and maintainers of LFS and the LFS Live