1 TITLE: LFS-BARE-BUILD hint
2 LFS VERSION: Any recent LFS with kernel > 2.2 glibc-2.2 gcc 2.95.3
3 AUTHOR: Frank Schafer <frank.schafer@setuza.cz>
5 SYNOPSIS: This hint is a collection of the experience I made during the
6 build of a LFS system on a machine with no OS installed and
7 some information from different INSTALL-HOWTOs with some
15 Most of the recent Linux distributions provide an easy way to make a machine
16 running this wonderful OS -- but there are some disadvantages:
17 1'st: Nearly all ( all ) distributors package things together, so one has the
18 possibility to choose, which of the ( distribution ) packages to install,
19 but probably ( mostly ) get things installed she don't wamt to.
20 2'nd: Using a lane and plain distribution install-CD one will never understand
21 in deep, how things work under *NIX.
22 3'rd: Using a binary distribution one doesn't know, how the single packages
24 4'th: Binary distributions have to ensure, that they can be installed on every
25 machine ( assuming INTEL ). So they build their packages without any
26 subtarget options applied to the compiler, and end up with i386 code.
27 Of course, a PENTIUM IV is able to run this code, but it'll run it faster,
28 if the compiler made real PENTIUM-IV-instructons.
29 Thanks to Gerard and friends - LFS came in turn. The LFS people did a great
30 work, supplying the knowledge of how to build a custom Linux "distribution" to
31 almost everybody. Such a custom build has the advantages, that one can choose
32 fine grained what will run on her machine, that we know how the packages
33 are configured ( we configure ourselves ;-), adding the -march switch to our
34 Makefiles can be used, to create code for the processor one has on her
35 machine instead if the default i386 code, and last but not least one will
36 win a lot of knowledge doing this all.
37 The only disadvantage of LFS as-is is, that it is build on a machine with Linux
38 already installed into a seperate partition on the harddisk. Mostly there won't
39 be so much unused disk space, to create a new partition which is sufficient for
40 the task of building a whole system. Furthermore this way we can't plan a
41 layout for the filesystem ( we simply have everything in one large partition ).
42 Using a PC with only the BIOS installed, to build the LFS system can solve this.
43 In fact, as the time of this writing I've dropped all binary distributions and
44 use the LFS style to install ( or better build ? ) new hosts.
49 You cannot build an operating system using only the BIOS of a PC - of course. So
50 we will need a machine, where all the nesessary tools are available. You can use
51 every PC with linux installed for this task. In my first case I used a Slackware7.1 distribution with glibc-2.1.3, kernel 2.2.16 and gcc-2.91.66. I'll call this
52 machine the MOTHER further on.
53 I intended to build an LFS system with glibc-2.2.3, kernel 2.4.8 and gcc-2.95.3.
54 I'll call this machine the CHILD further on.
55 The first trouble, I ran into was the upgrades of glibc and of the kernel, so be
58 First preparation steps ( MOTHER )
59 We need the tools we need to build the system, and what we are using the MOTHER
60 for, on the CHILD too. First we use the MOTHER, to build them.
61 You will have to look for a filesystem, which has enough free space to build.
66 gives you this output:
68 Filesystem 1k-blocks Used Available Use% Mounted on
69 /dev/hda1 101089 20516 75354 22% /
70 /dev/hdb1 1035692 731688 251392 75% /usr
71 /dev/hdb3 101089 17 95853 1% /tmp
72 /dev/hdb5 101089 2931 92939 4% /var/spool
73 /dev/hdb6 497829 260506 211621 56% /opt
74 /dev/hdb7 2158384 1110060 1048324 51% /v_dsk
76 Then you have enough space in /v_dsk.
78 Note: If You plan ( like I did ) to reuse the static part of the build, you
79 should NOT add any -march switches to your Makefiles. So you ensure to
80 have code, which runs on every machine.
82 If you want to reuse the static build for further LFS builds I suggest you to
83 create a "private" version of glibc and ncurses ( the only libs we need for
84 this ). First make a backup of the static libs in /usr/lib and /lib. We could
85 of course use the -nostdlib switch to cc and to add all the libs manually, but
86 we'd have to do this for every package from chapter 5. That's why I've choosen
88 The following is "stolen" from the lfs-3.0pre3-upgrade hint.
90 You will need to unpack glibc and glibc-linuxthreads, and create the
91 glibc-build directory in your source directory. Then change into glibc-build
93 # ../glibc-2.2.1/configure \
100 # make install_root=/v_dsk/static-libs install
101 # cd /v_dsk/static-libs/usr/lib
103 Doing this and following my note above, you will end up with i386 code, which
104 don't use a hardware FPU.
106 Unpack the ncurses package you want to use, change into the ncurses directory
109 --with-install-prefix=/v_dsk/static-libs \
118 # cd /v_dsk/static-libs/lib
120 This links the ncurses libs against the glibc without FPU usage.
122 Now we can create a directory for the LFS static build in /v_dsk.
128 # export LFS=/v_dsk/lfs
130 you can follow exactly the instructions of chapter 5 of the LFS-BOOK, to build
131 all necessary tools for the build of the final LFS system.
132 There is one exception: You don't need the kernel header files ( in $LFS ) for
133 this build, so leave this step alown.
134 Too, at this point, you shouldn't do the steps after ''Installing Textutils''.
135 Once you finished with chapter 5 of the book, you should burn out
138 # rm -rf $LFS/usr/include
140 Everything we need is now in $LFS.
142 If you have made the "private" build for the libs above, you now should restore
143 them from the backup you made.
145 At this point we have all we need to make the final build, but we have it on the
146 MOTHER, which is definitively the wrong machine.
147 So we'll now need to bring the CHILD to life. Again we use the MOTHER. Now we
148 will make a set of floppy disks, which we will boot the CHILD with. This is
149 taken from the Bootdisk-HOWTO. So if something I describe here remains unclear,
150 use this as a reference.
151 There are still some things, we still havent built, which are nesessary for a
152 system boot. We'll need a kernel, of course, init and login must be available
153 on a rootdisk, we will need to mount filesystems, we will need to partition the
154 disk on the CHILD ( fdisk ) and we will need to create filesystems ( mke2fs )
155 and, because we won't be able to build without, we need to create and turn on
156 swap on the CHILD ( mkswap, swapon ). Because we'll use NFS during the build
157 we'll need to configure our NIC ( ifconfig, route ).
159 Let's now populate the filesystem for our root-disk. We'll create first a
162 # mkdir /v_dsk/rootfs
164 The root filesystem will have all programs in /bin or /sbin and all libraries in
165 /lib for simplicity. So:
167 # mkdir /v_dsk/rootfs/{bin,dev,etc,lib,mnt,proc,sbin,var,MOTHER}
170 The /MOTHER directory will be used later on the CHILD, to mount the directory,
171 which contains the static binaries via NFS from the MOTHER.
175 # mkdir /v_dsk/rootfs/var/{log,run}
176 # touch /v_dsk/rootfs/var/run/utmp
178 Because these directoties/files are needed by login.
180 Next we'll create the devices ( in /dev of course ). I'll use the traditional
183 # cd /v_dsk/rootfs/dev
185 You could copy all the devices from /dev to here of course, and delete, what you
186 don't need, but on the rootdisk we need only a few, so we do:
188 # mknod -m 660 console c 5 1
189 # mknod -m 660 fd0 b 2 0
190 # mknod -m 660 hda b 3 0
191 # mknod -m 660 hda1 b 3 1
194 Which HD devices you want to create depends on, how many partitions you plan to
195 create on your HDs and what disk(s) you have. More information on the commands
196 above you find in the manual for mknod, and in the devices.txt file, which is
197 part of the kernel distribution.
199 # mknod -m 660 initrd b 1 250
200 # mknod -m 660 kmem c 1 2
201 # mknod -m 666 null c 1 3
204 # mknod -m 660 ram0 b 1 0
205 # mknod -m 644 random b 1 8
206 # mknod -m 666 tty c 5 0
207 # mknod -m 600 tty0 c 4 0
208 # mknod -m 600 tty1 c 4 1 # 2 virtual consoles are enough
209 # mknod -m 600 tty2 c 4 2 # for a rootdisk floppy
210 # mknod -m 644 urandom c 1 9
211 # mknod -m 666 zero c 1 5
213 The next diectory we'll have to populate is /etc. So let's go there;
215 # cd /v_dsk/rootfs/etc
217 First, we need an rc-script. The one we use is fairly simple.
222 /sbin/ifconfig lo 127.0.0.1
223 /sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo
224 /sbin/ifconfig eth0 IP.OF.THE.CLD broadcast BROADCAST \
226 /bin/mount -t nfs IP.OF.THE.MTR:/v_dsk/lfs /MOTHER
230 Replace ``IP.OF.THE.CLD'' with the IP-address, you have choosen for the CHILD,
231 and BROADCAST and NETMASK with the broadcast address and netmask of your site
233 The same way replace ``IP.OF.THE.MTR'' with the IP-address of the MOTHER.
235 Now we'll create the fstab file.
238 /dev/ram0 / ext2 defaults
239 /dev/fd0 / ext2 defaults
240 /proc /proc proc defaults
243 Here is the inittab file for our rootdisk.
248 1:12:respawn:/sbin/agetty tty1 9600
249 2:2:respawn:/sbin/agetty tty2 9600
252 All services on our boot/rootdisk booted CHILD are provided by local files. So
253 the creation of the nsswitch.conf looks like this:
255 # cat > nsswitch.conf
273 Oh, and somebody needs to be able to log into the CHILD. This should be the
274 person who builds it, what is done by the administrator ( of course ). So we'll
275 create passwd and group this way:
278 root::0:0:The cruely admin:/:bin/sh
284 Be aware, that root doesn't have a password this way, so have the floppies on a
287 We'll use bash, so the profile could have the following form:
290 PS1='LFS-BUILD : \w \$ '
292 PATH=/MOTHER/sbin:/MOTHER/bin:/MOTHER/usr/bin:/bin:/sbin
296 The floppy system will be dynamically linked, that's why we'll need ld.so.conf
302 # touch ld.so.cache # ( this is needed by ldconfig )
304 In the case, the MOTHER uses ``termcap'' one will have to copy the termcap file.
308 In this case I advise, to delete all but the linux entry in this file.
310 In the case the MOTHER uses terminfo, one will have to copy the terminfo
311 database ( and create the appropriate directories ). For that case it should be
314 # mkdir -p /v_dsk/rootfs/usr/lib/terminfo/l
315 # cp /usr/lib/terminfo/l/linux /v_dsk/rootfs/usr/lib/terminfo/l
317 The location on the MOTHER obove is only an example.
319 This is all we need in /etc, and next we'll provide the programs in /bin and
320 /sbin. We'll "borrow" all the programs, which we need to boot and which are not
321 available from the static build, from the mother. I've already mentioned theese
324 # cd /v_dsk/rootfs/sbin
327 # cp /sbin/ifconfig .
329 # cp /sbin/ldconfig .
332 # cp /sbin/mkfs.ext2 .
334 # cp /sbin/modprobe .
338 # cd /v_dsk/rootfs/bin
345 More we don't need to boot. Some of the utils above could be located in other
346 directories on YOUR MOTHER. You should use ``which'' to see where they are and
347 copy them to the appropriate location in /v_dsk/rootfs.
348 Note, that THIS part of your floppy system is dynamically linked, so we have
351 # cd /v_dsk/rootfs/lib
353 To see, which libs we need, we will have a look at every of the above programs
354 using ldd. Here is an example:
357 libc.so.6 => /lib/libc.so.6 (0x4001d000)
358 /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
359 # ls -l /lib/libc.so.6
360 lrwxrwxrwx 1 root root 13 Jul 13 16:15 /lib/libc.so.6 -> libc-2.2.3.so
361 # ls -l /lib/libc-2.2.3.so
362 -rwxr-xr-x 1 root root 1191848 Jul 13 10:59 /lib/libc-2.2.3.so
363 # cp /lib/libc-2.2.3.so .
364 # ln libc-2.2.3.so libc.so.6
365 # ls -l /lib/ld-linux.so.2
366 lrwxrwxrwx 1 root root 11 Jul 13 16:15 /lib/ld-linux.so.2 -> ld-2.2.3.so
367 # ls -l /lib/ld-2.2.3.so
368 -rwxr-xr-x 1 root root 94888 Jul 13 10:59 /lib/ld-2.2.3.so
369 # cp /lib/ld-2.2.3.so .
370 # ln ld-2.2.3.so ld-linux.so.2
372 This must be done for all the programs in /bin and /sbin. One don't need to copy
373 libs already copied of course. In the example above, I used ``ls -l'' to see, if
374 this is a link or the lib itself. For the latter case I've copied it, in the
375 former case, I created a link too. Note that I use hardlinks. This saves a lot
376 of inodes on the floppy ( BTW: on a production system this speeds up library
378 Don't forget to do the ``ldd''s for the libs too.
379 This part of the population of the filesystem is ( due to my experiences ) most
380 error prone. So be careful to not forget anything.
381 One library needed we probably won't find using the technique above: the NSS
382 library. We put ``files'' for everything into nsswitch.conf. So we need only:
384 # cp /lib/libnss_files-2.2.3.so .
385 # ln libnss_files-2.2.3.so libnss_files.so.2
387 One cuold have another version, so the name of the files is - again - only an
390 On MY example - MOTHER the content of /lib looks like this:
393 210671 ld-2.2.3.so 210672 libext2fs.so.2
394 210671 ld-linux.so.2 210672 libext2fs.so.2.4
395 210670 libc-2.2.3.so 210676 libncurses.so
396 210670 libc.so.6 210676 libncurses.so.5
397 210673 libcom_err.so.2 210676 libncurses.so.5.2
398 210673 libcom_err.so.2.0 210680 libnss_files-2.2.3.so
399 210679 libcrypt-2.2.3.so 210680 libnss_files.so.2
400 210679 libcrypt.so.1 210678 libshadow.so.0
401 210677 libdl-2.2.3.so 210678 libshadow.so.0.0.0
402 210677 libdl.so.2 210675 libuuid.so.1
403 210674 libe2p.so.2 210675 libuuid.so.1.2
406 At this point we could provide kernel modules. I don't do this, because I'll
407 build a special kernel for the bootdisk, which everything needed has directly
408 built in, and everything not needed ( FOR THE BOOTDISK ) disabled.
410 At this point we are done with the population of the directory structure for
411 the root filesystem. So let's make it a real filesystem. First we'll create a
414 # dd if=/dev/zero of=/v_dsk/FSFILE bs=1k count=4096
416 The initial ram-disk of the kernel is 4 MB, so I've created a file of this size.
418 # mke2fs -m 0 /v_dsk/FSFILE
420 Here we'll get a warning about the fact, that we create a filesystem not using
421 a special block device, but that's exactly what we intend to do, and we can
422 ignore this ( say Y to the question mke2fs asks ).
424 # mount -t ext2 -o loop /v_dsk/FSFILE /mnt
426 Possibly the kernel of your MOTHER doesn't provide loopdevice support. In this
427 case you'll have to rebuild your kernel before running the last command.
432 # chroot /mnt /sbin/ldconfig
436 Now put a newly formatted floppy disk into your mechanic and do:
438 # dd if=FSFILE bs=1k | gzip -v9 > rootfs.gz
439 # dd if=rootfs.gz of=/dev/fd0 bs=1k # ... and
441 umpf, we have our rootdisk.
443 Next we make the bootdisk. This contains only the kernel. I've coosen this way
444 for simplicity again. We could make a combined boot/rootdisk but we'd have to
445 take care for more aspects.
446 Making the kernel, we do the same procedure as with every kernel rebuild. The
447 kernel MUST support RAM-Disk, INITRD and MUST have support for the NIC built
448 in. Due to the fact, that we will mount the MOTHER via NFS, we need NFS support
449 of course. It MUST NOT have devfs support, and it SHOULD NOT support things not
450 necessary for a bootdisk ( sound, isdn, NLS, ... ).
452 Next we make a bare bootdisk without LILO. Again, put a newly formatted floppy
453 into your drive. From your kernel source directory do:
456 # dd if=bzImage of=/dev/fd0 bs=1k
458 The kernel make built a kernel set up for your harddisk. We have to change
459 this to have a kernel for the floppy.
461 # rdev /dev/fd0 /dev/fd0
464 The last step for the bootdisk is to set up the ramdisk word. Bit 14 indicates
465 the kernel, that a ramdisk is to be load. Bit 15 indicates, that the kernel
466 should prompt for the insertion of the root floppy disk.
468 # echo $(( 2 ** 14 + 2 ** 15 ))
470 # rdev -r /dev/fd0 49152
472 At this point we have nearly everything prepared for our CHILD. The last we do
473 sitting on the MOTHER is to share /v_dsk/lfs to the child.
474 If your MOTHER doesn't support NFS server, you'll have to recompile the kernel
476 Now make sure, that the portmapper is started before inetd, and that rpc.nfsd
477 and rpc.mountd is started after inetd.
478 We have to edit /etc/exports now, to enable the export we want. Evtl. we have to
482 /v_dsk/lfs ADR.OF.THE.CLD(ro,insecure,no_root_squash)
485 Change ``ADR.OF.THE.CLD'' with the IP address, you have choosen for the CHILD.
486 Now we apply the changes in /etc/exports.
488 # ps ax | grep mountd
489 132 ? S 0:00 rpc.mountd
491 135 ? S 0:00 rpc.nfsd
494 O.K., I know ... I could use some killall* or pidof here, but THIS works too
497 The packages needed to build the system are naturally stored on the disks of
498 the MOTHER. It should be a good choice, to copy these to a location, the CHILD
499 will see later. On the example MOTHER these were in /usr/src/pkgs.
502 # cp -a pkgs /v_dsk/lfs
504 This way, the CHILD will see the packages in /MOTHER/pkgs.
506 Finally we've reached the point, we can lift our ass from the chair in front of
509 Before you sit down again ( this time in front of the CHILD ), you should have
510 a cup or glass or bottle of some drink you prefer.
512 NOTE: If you choose bottle and your preferred drink is Whisky, I suggest you
513 NOT to continue before next day afternoon.
515 Welcome back to the server - center. Take now the floppies made above and sit
516 down in front of the CHILD.
517 Put the boo .... I think we know how to start a Linux box from floppies.
523 That's o.k., we don't have a hostname yet. If login as ``root'' you should get
524 a prompt without supplying a password.
528 There is still one thing, what could be wrong at this point -- the connection to
531 LFS-BUILD : / # mount
534 /MOTHER IP.OF.THE.MTR/v_dsk/lfs
536 If you see something like this, everything is fine.
538 We still don't have any space, to make the final build of the LFS to. So we
539 have to plan our filesystem layout now.
540 How this layout looks like, depends of course heavily from the main tasks the
541 machine is planned for.
542 A size of the ``/'' filesystem of about 100MB is more than sufficient for Linux.
543 With about 1GB for /usr we can build the whole system including X there, and
544 will still have some reserve. How much ``/tmp'' you plan is server dependent. I
545 suggest NOT to leave it on ``/''. This directory is word writeable, and having
546 something world writeable on ``/'' could lead to some kind of ``ROOT FILESYSTEM
547 FULL''. I usually plan about 500MB for ``/opt'' ( There I use to have things
548 like Netscape, GNOME, Windowmanagers etc. ). If there shall run something with
549 heavy logging or spooling, it's not a bad choice, to plan en extra fs for
550 ``/var''. One could plan some space for ``/usr/local''. I do so, because I
551 configure all subsystems special for a host ( proxy, webserver, dhcp, dns ... )
553 I'll give the fs-layout which I use to set up for an experimantal server as an
558 hdb2 /usr/local 500 MB
562 hdb7 /v_dsk what remains on the HD I have
564 I use to use a 100MB disk ( I have a couple of them ) as root-disks. hdb4 is
565 an extended partition, and the swap is on hdb8.
566 If you say: "I don't wanna wonder about this. So I'll place everything into one
567 large partition." however, nobody will bite you.
568 Don't forget to plan some swap space and to create a partition for it.
570 Having the fiilesystem layout planned, we create the partitions with ``fdisk''
571 and the filesystems and swap on them with ``mke2fs'' and ``mkswap''. Last we
572 can ( and should ) activate the swap space.
574 Onesmore we populate a filesystem, but this time the FINAL for the LFS system.
575 I'll do this due to the example above, thus this could differ for you.
577 # mount /dev/hda1 /mnt
578 # mkdir /mnt/{usr,tmp,var,opt,root,v_dsk}
579 # mount /dev/hdb1 /mnt/usr
580 # mkdir /mnt/usr/local
581 # mount /dev/hdb2 /mnt/usr/local
582 # mount /dev/hdb3 /mnt/tmp
583 # mount /dev/hdb5 /mnt/var
584 # mount /dev/hdb6 /mnt/opt
585 # mount /dev/hdb7 /mnt/v_dsk
588 # swapon /dev/hdb8 # if not already done
590 Now set the LFS environment variable for the CHILD.
593 # mkdir $LFS/usr/include
595 I've choosen this point to install the kernel header files ( from chapter 5 ).
596 This way we have only things NEEDED in $LFS, and we can SECURE say, that the
597 base system and the new system aren't wired in any kind.
599 # mkdir $LFS{etc,lib}
601 Here You should complete chapter 5. Remember, we still didn't the points
602 ``Creating passwd and group files'' to the end of this chapter.
604 The ``.profile'' ( or bash_profile due to the book ) remains in $LFS/root and
607 # cat > $LFS/root/.profile
608 PS1='LFS-BUILD : \w \$ '
610 PATH=/MOTHER/sbin:/MOTHER/bin:/MOTHER/usr/bin
614 Here we are in a pinch a bit. We need ``chroot'', which is amongst the tools
615 imported from the MOTHER, but inside the chroot'ed environment we'll loose all
620 # cp /MOTHER/usr/bin/chroot /bin
622 # mount -t nfs ADR.OF.THE.MTR:/v_dsk/lfs /mnt/MOTHER
623 # chroot $LFS /MOTHER/usr/bin/env -i HOME=/root TERM=$TERM \
624 /MOTHER/bin/bash --login
626 ... will solve this problem.
628 >From here on You can follow the instructions of the LFS-BOOK chapter 4 ( except
629 the things already done ) and the remainder of chapter 6 to The End ...
631 ... and You are done.
633 Some final suggestion:
634 I broke the instructions of chapter 4 a bit. I didn't make the link
635 between ``/usr/doc'' and ``/usr/share/doc''. Instead I've created
636 both directories. In ``/usr/doc'' I create for every package I install
637 a directory ``package-ver.s.ion'', and in these directory 2 files,
638 NOTES and URL. URL should be clear, and in NOTES I remember, how I've
639 configured the package. O.K., one could say: "Leave the source tree
640 intact, and use config.status!", but I don't have the TB disk, required
641 for this, at hand just now :o(. One can choose another location for this
642 of course, but doing this at all will ease your administration later.
643 Sure you know situations, when you read in a manpage: "... If thisprog
644 is configured with superfeature enabled, you can use the --sf switch
645 to do superious things". Or one plans to build and install newprog, and
646 the INSTALL instructions say, that dependprog with neededfeature
647 enabled has to be installed first. In these cases this helps a lot.
648 All the real doc goes to ``/usr/share/doc''.
649 If you add --with-info-dir=/usr/share/info to every package you install,
650 you'll get probably the most complete info directory you have ever
652 If You'd choose this way to build Your LFS system, it's not a bad choice
653 to have a hardcopy of the LFS-BOOK at hand.
655 You don't need to use NFS. Of course it is possible, to use floppies to
656 transfer the statics from the MOTHER to the CHILD. In this case you will
657 need some more tools on your rootdisk.
658 Once ( To say the truth, I did it twice. ) done this I changed NFS to
659 CD-ROM, having the static part on a CD and only the kernel on a combined
661 It's - too - possible to make a complete system upgrade this way.
662 Simply replace the NFS mount with a mount of the partiton containing
663 the lfs directory, and change the paths in the profile on the rootdisk
664 and in the chroot'ed environment accordingly. Then burn out all other
665 partitions and build.
667 END OF LFS-BARE-BUILD hint