Linux From Scratch HOWTO Gerard Beekmans Version 1.3, February 2000 This document describes the process of creating your own Linux system from scratch from an already installed Linux distribution, using noth- ing but the source code of software that we need ______________________________________________________________________ Table of Contents 1. Introduction 1.1 What's this all about? 1.2 New versions 1.3 Version history 1.4 Current Projects 1.5 TODO 1.6 Mailinglists 1.6.1 Subscribing 1.6.2 Unsubscribing 1.7 Contact info 2. Software packages you need to download 2.1 Mandatory software 2.2 Optional software 3. Preparing the new system 3.1 How we are going to do things 3.2 Creating a new partition 3.3 Creating an ext2 file system on the new partition 3.4 Adding an entry to LILO 3.5 Creating directories 3.6 Copying the /dev directory 4. Installing Sysvinit 4.1 Preparing Sysvinit 4.2 Configuring Sysvinit 4.3 Copying passwd & group files 4.4 Installing a root shell 4.5 Testing the system 5. Installing a kernel 5.1 Note on ftp.kernel.org 5.2 Configuring the kernel 5.3 Updating LILO 5.4 Testing the system 6. Installing the GNU C and C++ Libraries 6.1 Preparing the system for the GNU C Library installation 6.1.1 Installing Make 6.1.2 Installing Sed 6.1.3 Installing Shell Utils 6.1.4 Installing File Utils 6.1.5 Installing Util Linux 6.1.6 Installing Text Utils 6.1.7 Installing Tar 6.1.8 Installing Gzip 6.1.9 Installing Binutils 6.1.10 Installing Grep 6.1.11 Installing Bison 6.1.12 Installing Mawk 6.1.13 Installing Find Utils 6.1.14 Installing Diff Utils 6.1.15 Installing Ld.so 6.1.16 Installing Perl 6.1.17 Installing M4 6.1.18 Installing Texinfo 6.1.19 Installing Automake 6.1.20 Installing Autoconf 6.2 Installing the GNU C Library 6.3 Installing the GNU C++ Library 6.3.1 Installing the libstdc++2.9_2.91.66-0slink2.deb package 6.3.2 Installing the libstdc++2.9-dev_2.91.66-0slink2.deb package 7. Installing the GNU C and C++ compilers 7.1 Making two small test programs 7.2 Installing GCC 2.7.2.3 7.3 Installing the g++_2.91.66-0slink2.deb package 7.4 Creating necessary symlinks 7.5 Testing the compilers 8. Installing login utilities 8.1 Installing agetty + login 8.2 Modifying $LFS/etc/inittab 8.3 Creating the UTMP record file 8.4 Testing the system 9. Installing Vim 9.1 Preparing the system for the Vim installation 9.1.1 Installing Ncurses 9.2 Installing Vim 10. Creating initial boot scripts 10.1 Preparing the directories and master files 10.2 Creating the reboot script 10.3 Creating the halt script 10.4 Creating the mountfs script 10.5 Creating the umountfs script 10.6 Creating the sendsignals script 10.7 Set file permissions and create symlinks 10.8 Creating the /etc/fstab file 10.9 Testing the system 11. Reinstalling statically linked software 11.1 Reinstaling GCC-2.7.2.3 11.2 Installing the Termcap library 11.3 Installing the Readline library 11.4 Reinstalling Bash 11.5 Reinstalling Sysvinit 11.6 Reinstalling Make 11.7 Reinstalling Sed 11.8 Reinstalling Shell Utils 11.9 Reinstalling File Utils 11.10 Reinstalling + Installing Util Linux 11.11 Reinstalling Text Utils 11.12 Reinstalling Tar 11.13 Reinstalling Gzip 11.14 Reinstalling Bison 11.15 Installing Flex 11.16 Reinstalling Binutils 11.17 Reinstalling Grep 11.18 Reinstalling Mawk 11.19 Reinstalling Find Utils 11.20 Reinstalling Diff Utils 11.21 Installing Less 11.22 Reinstalling Perl 11.23 Reinstalling M4 11.24 Reinstalling Texinfo 12. Installing the rest of the basic system software 12.1 Installing E2fsprogs 12.1.1 Installing E2fsprogs 12.1.2 Creating the checkroot bootscript 12.1.3 Updating /etc/init.d/umountfs 12.1.4 Creating proper permissions and creating symlink 12.2 Installing File 12.3 Installing Libtool 12.4 Installing Modutils 12.5 Installing Linux86 12.6 Installing Lilo 12.6.1 Installing Lilo 12.6.2 Configuring Lilo 12.6.3 Copying kernel image files 12.7 Installing DPKG 12.8 Installing Sysklogd 12.8.1 Installing Sysklogd 12.8.2 Configuring Sysklogd 12.8.3 Creating the Sysklogd bootscript 12.8.4 Setting up symlinks and permissions 12.9 Installing Groff 12.10 Installing Man-db 12.11 Installing Procps 12.12 Installing Procinfo 12.13 Installing Procmisc 12.14 Installing Shadow Password 13. Setting up basic networking 13.1 Installing Netkit-base 13.2 Installing Net-tools 13.2.1 Creating the /etc/init.d/localnet bootscript 13.2.2 Setting up permissions and symlink 13.2.3 Creating the /etc/hostname file 13.2.4 Creating the /etc/hosts file 13.2.5 Creating the /etc/init.d/ethnet file 13.2.6 Setting up permissions and symlink for /etc/init.d/ethnet 13.2.7 Testing the network setup 14. Setting up Email sub system 14.1 Preparing system for Email sub system 14.1.1 Creating extra groups and user 14.1.2 Creating directories 14.2 Installing Procmail 14.3 Installing Sendmail 14.3.1 Installing Sendmail 14.3.2 Configuring Sendmail 14.4 Installing Mailx 14.5 Creating /etc/init.d/sendmail bootscript 14.6 Setting up permissions and symlinks 14.7 Installing Mutt 14.8 Installing Fetchmail 14.9 Testing the Email sub system 15. Installing Internet Servers 15.1 Installing telnet daemon + client 15.2 Installing Proftpd 15.3 Installing Netkit-ftp 15.4 Installing Apache 15.5 Installing Slang Library 15.6 Installing Zlib 15.7 Installing Lynx 15.8 Configuring the daemons 15.9 Configuring telnetd 15.9.1 Creating the /etc/inetd.conf configuration file 15.9.2 Creating the /etc/init.d/inetd bootscript 15.9.3 Setting up permissions and symlinks 15.10 Configuring proftpd 15.10.1 Creating necessary groups and users 15.10.2 Creating the /etc/init.d/proftpd bootscript 15.10.3 Setting up permissions and symlinks 15.11 Configuring apache 15.11.1 Editing apache configuration file 15.11.2 Creating /etc/init.d/apache bootscript 15.11.3 Setting up permissions and symlinks 15.12 Testing the daemons 16. Installing X Window System 16.1 Installing X 16.2 Creating /etc/ld.so.conf 16.3 Modifying /etc/man_db.config 16.4 Creating the /usr/include/X11 symlink 16.5 Creating the /usr/X11 symlink 16.6 Adding /usr/X11/bin to the $PATH environment variable 16.7 Configuring X 16.8 Testing X 17. Installing Window Maker 17.1 Preparing the system for the Window Maker installation 17.1.1 Installing libPropList 17.1.2 Installing libXpm 17.1.3 Installing libpng 17.1.4 Installing libtiff 17.1.5 Installing libjpeg 17.1.6 Installing libungif 17.1.7 Installing WindowMaker 17.2 Updating dynamic loader cache 17.3 Configuring WindowMaker 17.4 Testing WindowMaker 18. Configuring system for Internet 18.1 Configuring Kernel 18.2 Creating groups and directories 18.3 Installing PPP 18.4 Creating /etc/resolv.conf 18.5 Creating the connect and disconnect scripts 18.6 Creating /etc/ppp/peers/provider 18.7 Creating /etc/chatscripts/provider 18.8 Note on password authentication 18.9 Other resources 19. Migrations from old to new setups 19.1 Migrating from old C++ Library setup to the new setup 19.2 Migrating from old compiler setup to the new setup 20. Copyright & Licensing Information ______________________________________________________________________ 11.. IInnttrroodduuccttiioonn 11..11.. WWhhaatt''ss tthhiiss aallll aabboouutt?? I started this document around May 1999. I tried a few Linux distributions and came to the conclusion that there's wasn't a distribution I totally liked. Every distribution has it's own advantages and disadvantages, but I was never satisfied with what I had (although Debian comes very close to what I want), so I decided to explore the possibility of building my own Linux distribution using nothing but source code of programs. As I found out there's quite a bit of work involved, but it's also a lot of fun and you really learn a lot by doing it, since you need to configure every single aspect of the system. This forces you to read a lot of manuals on how to configure various software. It also gives you total control over your system (well, that's the idea). You know exactly what software is installed, how it is configured and where all the configuration files reside. I started writing a series of articles for a Dutch/Belgium E-zine on this subject. Not soon after I got stuck getting a compiler to work. I decided to give this project a rest at that point, since a lot of things at that time needed my attention (I was about to move from The Netherlands to Canada to get married. There were a lot of things to arrange regarding the move abroad and a lot of immigration stuff to sort out). A few months after my arrival in Canada and getting married, I decided to continue my work on this project. Pretty much starting all over again from scratch and following a different approach, I got things to work out finally. The end result is what you are reading right now. 11..22.. NNeeww vveerrssiioonnss The latest version of the document can always be found at http://huizen.dds.nl/~glb/ 11..33.. VVeerrssiioonn hhiissttoorryy 1.3 - February 11th, 2000 +o Two mailinglists are available. Read section 1.6 for more details +o Changed the compiler setup. Gcc-2.95.2 no longer is being used. In stead gcc-2.7.2.3 is the new C compiler and egcs-2.91.60 is the C++ compiler. +o Updated sections that contained compile instructions by running make CC=/usr/gcc2723/bin/gcc. A simple 'make' suffices now since gcc-2.7.2.3 is our default C compiler now. +o Changed the 'abstract' line to be more accurate. +o Fixed typos that were left behind in the previous versions +o Moved section 1.4 (TODO) to section 1.5. +o Section 2: Added the version numbers of the software that are known to work with this document. +o Section 2: Mawk link was broken (thanks to David McCauley (and various other people) for informing me about this). +o Section 2: Sysklogd link was broken (thanks to David McCauley for informing me about this). +o Section 2: divided the list into mandatory and optional software (the separation is software for section 13 and above) +o Inserted new section 1.4: Current projects. +o Inserted new section 3.1: How we are going to do things. In this section I briefly explain that you need to already have Linux installed to use this HOWTO and also explained there is no need for any kind of boot disk. +o Section 3.3: Clarified the currently used kernel image is to be used (thanks to Andrew Blais for pointing this out). +o Section 3.4: Added the usr/share directory to the list of directories that need to be created. +o Section 5: Clarified that the kernel source tree must be copied to the LFS partition +o Section 6.1.2: Pointed out availability of fixed package in case compilation fails +o Section 6.1.4: Rather than renaming ginstall to install we create a symlink install +o Section 6.1.8: Pointed out availability of fixed package in case compilation fails +o Section 6.1.10: Pointed out availability of fixed package in case compilation fails +o Section 6.1.13: Pointed out availability of fixed package in case compilation fails +o Section 6.1.14: Pointed out availability of fixed package in case compilation fails +o Section 6.1.17: Pointed out availability of fixed package in case compilation fails +o Section 6.1.18: Pointed out availability of fixed package in case compilation fails +o Section 7.2: The gcc-2.7.2.3 compiler needs to be linked statically at first (to avoid possible Library conflicts between the normal and LFS system). +o Inserted section 11.1: Reinstalling GCC 2.7.2.3 +o Section 11.13: Pointed out availability of fixed package in case compilation fails +o Section 11.19: Pointed out availability of fixed package in case compilation fails +o Section 14.4: Failed to mention that the package needs to be configured prior to compilation. +o Section 15.2: Failed to mention that the package needs to be configured prior to compilation. +o Inserted a new section 19 (old section 19 has become section 20) that contains migrating information, in case you need to do some re-modeling to change a setup (like migrating to the new compiler setup in this version). 1.2 - January 9th, 2000 +o Section 2: Owen Cook pointed out that the link for the sysvinit package was wrong. It said cistron.nl. It should be ftp.cistron.nl +o Section 3.4: Added the usr/include directory to the list of directories that need to be created +o Section 4.3: Made a notion of the possibility that somebody's system might be using shadowed passwords. +o Section 6.1.3: The majority of the files that need to be copied was missing (the files that need to be copied to $LFS/usr/bin). +o Section 6.1.4: Forgot to mention that the mv program needs to be copied as well +o Section 6.1.14: Forgot to mention that the cmp program needs to be copied as well +o Section 7: Just to make sure nobody runs into problems, I added the comment that all file systems must be unmounted and the root file system must be mounted read-only before the computer is rebooted +o Section 7.2: Added the --local-prefix=/usr/gcc2723 switch to the configure command line +o Section 11.7: Fixed a typo in one of the programs: patchchk should be pathchk +o Section 11.9: Added compilation and copying of the mkswap program 1.1 - December 20th, 1999 +o Fixed a few typos +o Modified section 18 (Configuring system for Internet) from just a reference to the ISP-Hookup-HOWTO to a basic explanation on how to setup Internet +o Fixed error in /etc/syslog.conf (in section 12.8.2) 1.0 - December 16th, 1999 +o Initial release 11..44.. CCuurrrreenntt PPrroojjeeccttss Projects related to this HOWTO that are currently underway. +o The HOWTO is under the process of being translated into Spanish 11..55.. TTOODDOO Things that need to be done for future releases. If you feel you want to help out on one of these items, let me know first (in case you end up doing something somebody else is doing already or is already finished). +o Translate the HOWTO into Dutch. Although I'm Dutch myself, I can't seem to find time to do the work myself. 11..66.. MMaaiilliinngglliissttss There are two mailinglists you can subscribe to. The lfs-discuss and the lfs-announce list. The former is an open non-moderated list discussing anything that has got anything to do with this HOWTO (asking questions, inform about mistakes in this HOWTO and so on). The latter is an open moderated list. Anybody can subscribe to it, but you cannot post messages to it (only the moderator(s) can). This list is primarily used for announcements of new versions of the HOWTO. If you're subscribed to the lfs-discuss list you don't need to be subscribed to the lfs-announce list as well. Everything that is sent over the lfs-announce list is also sent over the lfs-discuss list. 11..66..11.. SSuubbssccrriibbiinngg To subscribe to a list, send an email to majordomo@fist.org and type in the body either _s_u_b_s_c_r_i_b_e _l_f_s_-_d_i_s_c_u_s_s or _s_u_b_s_c_r_i_b_e _l_f_s_-_a_n_n_o_u_n_c_e Majordomo will send you a confirmation-request email. This email will contain an authentication code. Once you send this email back to Majordomo (instructions are provided in that email) you will be subscribed. 11..66..22.. UUnnssuubbssccrriibbiinngg To unsubscribe from a list, send an email to majordomo@fist.org and type in the the body either _u_n_s_u_b_s_c_r_i_b_e _l_f_s_-_d_i_s_c_u_s_s or _u_n_s_u_b_s_c_r_i_b_e _l_f_s_-_a_n_n_o_u_n_c_e 11..77.. CCoonnttaacctt iinnffoo You can reach me, Gerard Beekmans, at tts-sol@dds.nl 22.. SSooffttwwaarree ppaacckkaaggeess yyoouu nneeeedd ttoo ddoowwnnllooaadd Below is a list of all the software that you need to download for use in this document. I display the sites and directories where you can download the software, but it is up to you to make sure you download the source archive and the latest version. The version numbers correspondent to versions of the software that is known to work. 22..11.. MMaannddaattoorryy ssooffttwwaarree Sysvinit (2.78) : ftp://ftp.cistron.nl/pub/people/miquels/sysvinit/ Bash (2.03) : ftp://ftp.gnu.org/gnu/bash/ Linux Kernel (2.2.14) : ftp://ftp.kernel.org/ Make (3.77) : ftp://ftp.gnu.org/gnu/make/ Sed (3.02) : ftp://ftp.gnu.org/gnu/sed/ Shell Utils (2.0) : ftp://ftp.gnu.org/gnu/sh-utils/ File Utils (4.0) : ftp://ftp.gnu.org/gnu/fileutils/ Util Linux (2.9z) : ftp://ftp.win.tue.nl/pub/linux/utils/util-linux/ Text Utils (1.22) : ftp://ftp.gnu.org/gnu/textutils/ Tar (1.12) : ftp://ftp.gnu.org/gnu/tar/ Gzip (1.2.4) : ftp://ftp.gnu.org/gnu/gzip/ Binutils (2.9.1.0) : ftp://ftp.gnu.org/gnu/binutils/ Grep (2.2) : ftp://ftp.gnu.org/gnu/grep/ Bison (1.25) : ftp://ftp.gnu.org/gnu/bison/ Mawk (1.3.3) : ftp://ftp.whidbey.net/pub/brennan/ Find Utils (4.1) : ftp://ftp.gnu.org/gnu/findutils/ Diff Utils (2.7) : ftp://ftp.gnu.org/gnu/diffutils/ Ld.so (1.9.10) : ftp://tsx-11.mit.edu/pub/linux/packages/GCC/ Perl (5.005_03) : ftp://ftp.gnu.org/gnu/perl/ M4 (1.4) : ftp://ftp.gnu.org/gnu/m4/ Texinfo (4.0) : ftp://ftp.gnu.org/gnu/texinfo/ Automake (1.3) : ftp://ftp.gnu.org/gnu/automake/ Autoconf (2.13) : ftp://ftp.gnu.org/gnu/autoconf/ Glibc (2.0.7pre6) : ftp://ftp.gwdg.de/pub/linux/glibc/2.0.7pre6/ Glibc-crypt (2.0.pre6) : ftp://ftp.gwdg.de/pub/linux/glibc/2.0.7pre6/ Glibc-linuxthreads (2.0.7pre6) : ftp://ftp.gwdg.de/pub/linux/glibc/2.0.7pre6/ Libstdc++-2.91.60 : ftp://ftp.debian.org/debian/dists/slink/main/binary-i386/base/ Libstdc++-2.91.660-dev : ftp://ftp.debian.org/debian/dists/slink/main/binary-i386/devel/ GCC (2.7.2.3) : ftp://ftp.gnu.org/gnu/gcc/ G++-2.91.60 : ftp://ftp.debian.org/debian/dists/slink/main/binary- i386/devel/ Ncurses (4.2) : ftp://ftp.gnu.org/gnu/ncurses/ Vim (5.5) : ftp://ftp.vim.org/pub/vim/ Readline Library (4.0) : ftp://ftp.gnu.org/gnu/readline/ Termcap Library (1.3) : ftp://ftp.gnu.org/gnu/termcap/ Flex (2.5.4a) : ftp://ftp.gnu.org/gnu/flex/ Less (332) : ftp://ftp.gnu.org/gnu/less/ E2fsprogs (1.12) : ftp://tsx-11.mit.edu/pub/linux/packages/ext2fs/ File (3.26) : ftp://ftp.debian.org/debian/dists/slink/main/source/utils/ Libtool (1.2) : ftp://ftp.gnu.org/gnu/libtool/ Modutils (2.3.7) : ftp://ftp.ocs.com.au/pub/modutils/v2.3/ Linux86 (0.14.3) : ftp://ftp.debian.org/debian/dists/slink/main/source/devel Lilo (21) : ftp://sunsite.unc.edu/pub/Linux/system/boot/lilo/ DPKG (1.4.0.35) : ftp://ftp.debian.org/debian/dists/slink/main/source/base/ Sysklogd (1.3.31) : ftp://sunsite.unc.edu/pub/Linux/system/daemons/ Groff (1.11.1) : ftp://ftp.gnu.org/gnu/groff/ Man-db (2.3.10) : ftp://ftp.debian.org/debian/dists/slink/main/source/doc/ Procps (2.0.6) : ftp://tsx-11.mit.edu/pub/linux/sources/usr.bin/ Procinfo (17) : ftp://ftp.cistron.nl/pub/people/svm/ Procmisc (19) : ftp://lrcftp.epfl.ch/pub/linux/local/psmisc/ Shadow Password Suite (19990827) : ftp://piast.t19.ds.pwr.wroc.pl/pub/linux/shadow/ 22..22.. OOppttiioonnaall ssooffttwwaarree All software below is used in sections 13 and above and are not strictly necessary. You have to determine for yourself if you want to install certain packages. If, for example, you don't intend to go online with the LFS system, you might not want to install the email, telnet, ftp, www, etc. utilities. You can omit those. I suggest you read the sections 13 and above first to determine which software packages you want and which software packages you don't want to install. Netkit-base : ftp://ftp.uk.linux.org/pub/linux/Networking/netkit- devel/ Net-tools (1.53) : http://www.tazenda.demon.co.uk/phil/net-tools/ Procmail (3.13.1) : ftp://ftp.procmail.org/pub/procmail/ Sendmail (8.9.3) : ftp://ftp.sendmail.org/pub/sendmail/ Mailx (8.1.1) : ftp://ftp.debian.org/debian/dists/slink/main/source/mail/ Mutt (1.0i) : ftp://ftp.mutt.org/pub/mutt/ Fetchmail (5.2.0) : http://www.tuxedo.org/~esr/fetchmail/ Netkit-telnet : ftp://ftp.uk.linux.org/pub/linux/Networking/netkit- devel/ Proftpd (1.2.0pre9) : ftp://ftp.tos.net/pub/proftpd/ Netkit-ftp : ftp://ftp.uk.linux.org/pub/linux/Networking/netkit-devel/ Apache (1.3.3) : http://www.apache.org/dist/ Slang Library (1.3.10) : ftp://space.mit.edu/pub/davis/slang/ Zlib Library (1.1.3) : http://www.cdrom.com/pub/infozip/zlib/ Lynx (2.8.1) : http://www.slcc.edu/lynx/release/ Xfree86 (3.3.2.3) : ftp://ftp.xfree86.org/pub/XFree86/ libPropList (0.9.1) : ftp://ftp.windowmaker.org/pub/libs/ libXpm (4.7) : ftp://sunsite.unc.edu/pub/Linux/libs/X/ libpng (1.0.3) : http://www.cdrom.com/pub/png/ libtiff (3.4) : ftp://ftp.sgi.com/graphics/tiff/ libjpeg (6b) : http://www.ijg.org/ libungif (4.1.0) : ftp://prtr-13.ucsc.edu/pub/libungif/ WindowMaker (0.61.1) : ftp://ftp.windowmaker.org/pub/release/ PPP (2.3.10) : ftp://cs.anu.edu.au/pub/software/ppp/ 33.. PPrreeppaarriinngg tthhee nneeww ssyysstteemm 33..11.. HHooww wwee aarree ggooiinngg ttoo ddoo tthhiinnggss We are going to build the LFS system using an already installed Linux distribution such as Debian, SuSe, Slackware, Mandrake, RedHat, etc. You don't need to have any kind of bootdisk. We will use an existing Linux system as the base (since we need a compiler, linker, text editor and other tools). If you don't have Linux installed yet, you won't be able to put this HOWTO to use right away. I suggest you first install a Linux distribution. It really doesn't matter which one you install. It also doesn't need to be the latest version (though it shouldn't be a too old one. If it is about a year old or newer it'll do just fine). 33..22.. CCrreeaattiinngg aa nneeww ppaarrttiittiioonn Before we can build our new Linux system, we need to have an empty Linux partition on which we can build our new system. If you already have a Linux Native partition available, you can skip this subsection. Start the fdisk program (or cfdisk if you prefer that program) with the appropriate hard disk as the option (like /dev/hda if you want to create a new partition on the primary master IDE disk). Create a Linux Native partition, write the partition table and exit the (c)fdisk program. If you get the message that you need to reboot your system to ensure that that partition table is updated, then please reboot your system now before continuing. 33..33.. CCrreeaattiinngg aann eexxtt22 ffiillee ssyysstteemm oonn tthhee nneeww ppaarrttiittiioonn Once the partition is created, we have to create a new ext2 file system on that partition. From now on I'll refer to this newly created partition as $LFS. $LFS should be substituted with the partition you have created. If you created your partition on /dev/hda4, you mounted it on /mnt/hda4 and this document tells you to copy a file to $LFS/usr/bin then you need to copy that file to /mnt/hda4/usr/bin. To create a new ext2 file system we use the mke2fs command. Give $LFS as the only option and the file system will be created. 33..44.. AAddddiinngg aann eennttrryy ttoo LLIILLOO In order to be able to boot from this partition later on, we need to update our /etc/lilo.conf file. Add the following lines to lilo.conf: image= label=