Linux From Scratch Version 7.7 Created by Gerard Beekmans Edited by Matthew Burgess and Bruce Dubbs Linux From Scratch: Version 7.7 by Created by Gerard Beekmans and Edited by Matthew Burgess and Bruce Dubbs Copyright © 1999-2015 Gerard Beekmans Copyright © 1999-2015, Gerard Beekmans All rights reserved. This book is licensed under a Creative Commons License. Computer instructions may be extracted from the book under the MIT License. Linux® is a registered trademark of Linus Torvalds. Linux From Scratch - Version 7.7 iii Table of Contents Preface ......................................................................................................................................................................... viii i. Foreword ............................................................................................................................................................ viii ii. Audience ........................................................................................................................................................... viii iii. LFS Target Architectures .................................................................................................................................. ix iv. LFS and Standards ............................................................................................................................................. x v. Rationale for Packages in the Book ................................................................................................................... xi vi. Prerequisites ..................................................................................................................................................... xvi vii. Host System Requirements ............................................................................................................................ xvi viii. Typography .................................................................................................................................................... xix ix. Structure ............................................................................................................................................................ xx x. Errata .................................................................................................................................................................. xx I. Introduction ................................................................................................................................................................. 1 1. Introduction .......................................................................................................................................................... 2 1.1. How to Build an LFS System .................................................................................................................... 2 1.2. What's new since the last release ............................................................................................................... 2 1.3. Changelog ................................................................................................................................................... 4 1.4. Resources .................................................................................................................................................... 8 1.5. Help ............................................................................................................................................................. 9 II. Preparing for the Build ........................................................................................................................................... 11 2. Preparing a New Partition ................................................................................................................................. 12 2.1. Introduction ............................................................................................................................................... 12 2.2. Creating a New Partition .......................................................................................................................... 12 2.3. Creating a File System on the Partition ................................................................................................... 13 2.4. Mounting the New Partition ..................................................................................................................... 14 2.5. Setting The $LFS Variable ....................................................................................................................... 15 3. Packages and Patches ........................................................................................................................................ 16 3.1. Introduction ............................................................................................................................................... 16 3.2. All Packages ............................................................................................................................................. 16 3.3. Needed Patches ......................................................................................................................................... 23 4. Final Preparations .............................................................................................................................................. 25 4.1. Introduction ............................................................................................................................................... 25 4.2. Creating the $LFS/tools Directory ........................................................................................................... 25 4.3. Adding the LFS User ............................................................................................................................... 25 4.4. Setting Up the Environment ..................................................................................................................... 26 4.5. About SBUs .............................................................................................................................................. 27 4.6. About the Test Suites ............................................................................................................................... 28 5. Constructing a Temporary System .................................................................................................................... 30 5.1. Introduction ............................................................................................................................................... 30 5.2. Toolchain Technical Notes ....................................................................................................................... 30 5.3. General Compilation Instructions ............................................................................................................. 32 5.4. Binutils-2.25 - Pass 1 ............................................................................................................................... 33 5.5. GCC-4.9.2 - Pass 1 ................................................................................................................................... 35 5.6. Linux-3.19 API Headers ........................................................................................................................... 38 5.7. Glibc-2.21 ................................................................................................................................................. 39 5.8. Libstdc++-4.9.2 ......................................................................................................................................... 42 Linux From Scratch - Version 7.7 iv 5.9. Binutils-2.25 - Pass 2 ............................................................................................................................... 44 5.10. GCC-4.9.2 - Pass 2 ................................................................................................................................. 46 5.11. Tcl-8.6.3 .................................................................................................................................................. 49 5.12. Expect-5.45 ............................................................................................................................................. 51 5.13. DejaGNU-1.5.2 ....................................................................................................................................... 53 5.14. Check-0.9.14 ........................................................................................................................................... 54 5.15. Ncurses-5.9 .............................................................................................................................................. 55 5.16. Bash-4.3.30 ............................................................................................................................................. 56 5.17. Bzip2-1.0.6 .............................................................................................................................................. 57 5.18. Coreutils-8.23 .......................................................................................................................................... 58 5.19. Diffutils-3.3 ............................................................................................................................................. 59 5.20. File-5.22 .................................................................................................................................................. 60 5.21. Findutils-4.4.2 ......................................................................................................................................... 61 5.22. Gawk-4.1.1 .............................................................................................................................................. 62 5.23. Gettext-0.19.4 .......................................................................................................................................... 63 5.24. Grep-2.21 ................................................................................................................................................ 64 5.25. Gzip-1.6 ................................................................................................................................................... 65 5.26. M4-1.4.17 ................................................................................................................................................ 66 5.27. Make-4.1 ................................................................................................................................................. 67 5.28. Patch-2.7.4 ............................................................................................................................................... 68 5.29. Perl-5.20.2 ............................................................................................................................................... 69 5.30. Sed-4.2.2 ................................................................................................................................................. 70 5.31. Tar-1.28 ................................................................................................................................................... 71 5.32. Texinfo-5.2 .............................................................................................................................................. 72 5.33. Util-linux-2.26 ......................................................................................................................................... 73 5.34. Xz-5.2.0 ................................................................................................................................................... 74 5.35. Stripping .................................................................................................................................................. 75 5.36. Changing Ownership .............................................................................................................................. 75 III. Building the LFS System ...................................................................................................................................... 76 6. Installing Basic System Software ...................................................................................................................... 77 6.1. Introduction ............................................................................................................................................... 77 6.2. Preparing Virtual Kernel File Systems .................................................................................................... 77 6.3. Package Management ............................................................................................................................... 78 6.4. Entering the Chroot Environment ............................................................................................................ 81 6.5. Creating Directories .................................................................................................................................. 82 6.6. Creating Essential Files and Symlinks ..................................................................................................... 83 6.7. Linux-3.19 API Headers ........................................................................................................................... 87 6.8. Man-pages-3.79 ......................................................................................................................................... 88 6.9. Glibc-2.21 ................................................................................................................................................. 89 6.10. Adjusting the Toolchain ......................................................................................................................... 96 6.11. Zlib-1.2.8 ................................................................................................................................................. 98 6.12. File-5.22 .................................................................................................................................................. 99 6.13. Binutils-2.25 .......................................................................................................................................... 100 6.14. GMP-6.0.0a ........................................................................................................................................... 102 6.15. MPFR-3.1.2 ........................................................................................................................................... 104 6.16. MPC-1.0.2 ............................................................................................................................................. 105 6.17. GCC-4.9.2 ............................................................................................................................................. 106 Linux From Scratch - Version 7.7 v 6.18. Bzip2-1.0.6 ............................................................................................................................................ 111 6.19. Pkg-config-0.28 ..................................................................................................................................... 113 6.20. Ncurses-5.9 ............................................................................................................................................ 114 6.21. Attr-2.4.47 ............................................................................................................................................. 117 6.22. Acl-2.2.52 .............................................................................................................................................. 118 6.23. Libcap-2.24 ........................................................................................................................................... 120 6.24. Sed-4.2.2 ............................................................................................................................................... 121 6.25. Shadow-4.2.1 ......................................................................................................................................... 122 6.26. Psmisc-22.21 ......................................................................................................................................... 126 6.27. Procps-ng-3.3.10 ................................................................................................................................... 127 6.28. E2fsprogs-1.42.12 ................................................................................................................................. 129 6.29. Coreutils-8.23 ........................................................................................................................................ 132 6.30. Iana-Etc-2.30 ......................................................................................................................................... 137 6.31. M4-1.4.17 .............................................................................................................................................. 138 6.32. Flex-2.5.39 ............................................................................................................................................ 139 6.33. Bison-3.0.4 ............................................................................................................................................ 140 6.34. Grep-2.21 .............................................................................................................................................. 141 6.35. Readline-6.3 .......................................................................................................................................... 142 6.36. Bash-4.3.30 ........................................................................................................................................... 144 6.37. Bc-1.06.95 ............................................................................................................................................. 146 6.38. Libtool-2.4.6 .......................................................................................................................................... 147 6.39. GDBM-1.11 .......................................................................................................................................... 148 6.40. Expat-2.1.0 ............................................................................................................................................ 149 6.41. Inetutils-1.9.2 ........................................................................................................................................ 150 6.42. Perl-5.20.2 ............................................................................................................................................. 152 6.43. XML::Parser-2.44 ................................................................................................................................. 155 6.44. Autoconf-2.69 ....................................................................................................................................... 156 6.45. Automake-1.15 ...................................................................................................................................... 158 6.46. Diffutils-3.3 ........................................................................................................................................... 160 6.47. Gawk-4.1.1 ............................................................................................................................................ 161 6.48. Findutils-4.4.2 ....................................................................................................................................... 162 6.49. Gettext-0.19.4 ........................................................................................................................................ 164 6.50. Intltool-0.50.2 ........................................................................................................................................ 166 6.51. Gperf-3.0.4 ............................................................................................................................................ 167 6.52. Groff-1.22.3 ........................................................................................................................................... 168 6.53. Xz-5.2.0 ................................................................................................................................................. 171 6.54. GRUB-2.02~beta2 ................................................................................................................................ 173 6.55. Less-458 ................................................................................................................................................ 175 6.56. Gzip-1.6 ................................................................................................................................................. 176 6.57. IPRoute2-3.19.0 .................................................................................................................................... 178 6.58. Kbd-2.0.2 ............................................................................................................................................... 180 6.59. Kmod-19 ............................................................................................................................................... 182 6.60. Libpipeline-1.4.0 ................................................................................................................................... 184 6.61. Make-4.1 ............................................................................................................................................... 185 6.62. Patch-2.7.4 ............................................................................................................................................. 186 6.63. Sysklogd-1.5.1 ....................................................................................................................................... 187 6.64. Sysvinit-2.88dsf .................................................................................................................................... 188 Linux From Scratch - Version 7.7 vi 6.65. Tar-1.28 ................................................................................................................................................. 189 6.66. Texinfo-5.2 ............................................................................................................................................ 190 6.67. Eudev-2.1.1 ........................................................................................................................................... 192 6.68. Util-linux-2.26 ....................................................................................................................................... 194 6.69. Man-DB-2.7.1 ....................................................................................................................................... 199 6.70. Vim-7.4 ................................................................................................................................................. 202 6.71. About Debugging Symbols .................................................................................................................. 205 6.72. Stripping Again ..................................................................................................................................... 205 6.73. Cleaning Up .......................................................................................................................................... 206 7. System Configuration and Bootscripts ............................................................................................................ 207 7.1. Introduction ............................................................................................................................................. 207 7.2. LFS-Bootscripts-20150222 ..................................................................................................................... 208 7.3. Overview of Device and Module Handling ........................................................................................... 210 7.4. Managing Devices .................................................................................................................................. 213 7.5. General Network Configuration ............................................................................................................. 216 7.6. System V Bootscript Usage and Configuration ..................................................................................... 218 7.7. The Bash Shell Startup Files .................................................................................................................. 228 7.8. Creating the /etc/inputrc File .................................................................................................................. 230 7.9. Creating the /etc/shells File .................................................................................................................... 232 8. Making the LFS System Bootable .................................................................................................................. 233 8.1. Introduction ............................................................................................................................................. 233 8.2. Creating the /etc/fstab File ...................................................................................................................... 233 8.3. Linux-3.19 ............................................................................................................................................... 235 8.4. Using GRUB to Set Up the Boot Process ............................................................................................. 239 9. The End ............................................................................................................................................................ 241 9.1. The End ................................................................................................................................................... 241 9.2. Get Counted ............................................................................................................................................ 241 9.3. Rebooting the System ............................................................................................................................. 241 9.4. What Now? ............................................................................................................................................. 243 IV. Appendices ........................................................................................................................................................... 244 A. Acronyms and Terms ..................................................................................................................................... 245 B. Acknowledgments ........................................................................................................................................... 248 C. Dependencies ................................................................................................................................................... 251 D. Boot and sysconfig scripts version-20150222 ............................................................................................... 262 D.1. /etc/rc.d/init.d/rc ...................................................................................................................................... 262 D.2. /lib/lsb/init-functions .............................................................................................................................. 266 D.3. /etc/rc.d/init.d/mountvirtfs ...................................................................................................................... 280 D.4. /etc/rc.d/init.d/modules ........................................................................................................................... 281 D.5. /etc/rc.d/init.d/udev ................................................................................................................................. 283 D.6. /etc/rc.d/init.d/swap ................................................................................................................................ 284 D.7. /etc/rc.d/init.d/setclock ............................................................................................................................ 285 D.8. /etc/rc.d/init.d/checkfs ............................................................................................................................ 287 D.9. /etc/rc.d/init.d/mountfs ............................................................................................................................ 289 D.10. /etc/rc.d/init.d/udev_retry ..................................................................................................................... 291 D.11. /etc/rc.d/init.d/cleanfs ........................................................................................................................... 292 D.12. /etc/rc.d/init.d/console .......................................................................................................................... 294 D.13. /etc/rc.d/init.d/localnet .......................................................................................................................... 296 Linux From Scratch - Version 7.7 vii D.14. /etc/rc.d/init.d/sysctl .............................................................................................................................. 298 D.15. /etc/rc.d/init.d/sysklogd ........................................................................................................................ 299 D.16. /etc/rc.d/init.d/network .......................................................................................................................... 300 D.17. /etc/rc.d/init.d/sendsignals .................................................................................................................... 302 D.18. /etc/rc.d/init.d/reboot ............................................................................................................................ 303 D.19. /etc/rc.d/init.d/halt ................................................................................................................................. 304 D.20. /etc/rc.d/init.d/template ......................................................................................................................... 304 D.21. /etc/sysconfig/modules ......................................................................................................................... 305 D.22. /etc/sysconfig/createfiles ...................................................................................................................... 306 D.23. /etc/sysconfig/udev-retry ...................................................................................................................... 306 D.24. /sbin/ifup ............................................................................................................................................... 307 D.25. /sbin/ifdown .......................................................................................................................................... 309 D.26. /lib/services/ipv4-static ......................................................................................................................... 311 D.27. /lib/services/ipv4-static-route ............................................................................................................... 313 E. Udev configuration rules ................................................................................................................................. 316 E.1. 55-lfs.rules .............................................................................................................................................. 316 F. LFS Licenses ................................................................................................................................................... 317 F.1. Creative Commons License ................................................................................................................... 317 F.2. The MIT License .................................................................................................................................... 321 Index ........................................................................................................................................................................... 322 Linux From Scratch - Version 7.7 viii Preface Foreword My journey to learn and better understand Linux began over a decade ago, back in 1998. I had just installed my first Linux distribution and had quickly become intrigued with the whole concept and philosophy behind Linux. There are always many ways to accomplish a single task. The same can be said about Linux distributions. A great many have existed over the years. Some still exist, some have morphed into something else, yet others have been relegated to our memories. They all do things differently to suit the needs of their target audience. Because so many different ways to accomplish the same end goal exist, I began to realize I no longer had to be limited by any one implementation. Prior to discovering Linux, we simply put up with issues in other Operating Systems as you had no choice. It was what it was, whether you liked it or not. With Linux, the concept of choice began to emerge. If you didn't like something, you were free, even encouraged, to change it. I tried a number of distributions and could not decide on any one. They were great systems in their own right. It wasn't a matter of right and wrong anymore. It had become a matter of personal taste. With all that choice available, it became apparent that there would not be a single system that would be perfect for me. So I set out to create my own Linux system that would fully conform to my personal preferences. To truly make it my own system, I resolved to compile everything from source code instead of using pre-compiled binary packages. This “perfect” Linux system would have the strengths of various systems without their perceived weaknesses. At first, the idea was rather daunting. I remained committed to the idea that such a system could be built. After sorting through issues such as circular dependencies and compile-time errors, I finally built a custom-built Linux system. It was fully operational and perfectly usable like any of the other Linux systems out there at the time. But it was my own creation. It was very satisfying to have put together such a system myself. The only thing better would have been to create each piece of software myself. This was the next best thing. As I shared my goals and experiences with other members of the Linux community, it became apparent that there was a sustained interest in these ideas. It quickly became plain that such custom-built Linux systems serve not only to meet user specific requirements, but also serve as an ideal learning opportunity for programmers and system administrators to enhance their (existing) Linux skills. Out of this broadened interest, the Linux From Scratch Project was born. This Linux From Scratch book is the central core around that project. It provides the background and instructions necessary for you to design and build your own system. While this book provides a template that will result in a correctly working system, you are free to alter the instructions to suit yourself, which is, in part, an important part of this project. You remain in control; we just lend a helping hand to get you started on your own journey. I sincerely hope you will have a great time working on your own Linux From Scratch system and enjoy the numerous benefits of having a system that is truly your own. -- Gerard Beekmans gerard@linuxfromscratch.org Audience There are many reasons why you would want to read this book. One of the questions many people raise is, “why go through all the hassle of manually building a Linux system from scratch when you can just download and install an existing one?” Linux From Scratch - Version 7.7 ix One important reason for this project's existence is to help you learn how a Linux system works from the inside out. Building an LFS system helps demonstrate what makes Linux tick, and how things work together and depend on each other. One of the best things that this learning experience can provide is the ability to customize a Linux system to suit your own unique needs. Another key benefit of LFS is that it allows you to have more control over the system without relying on someone else's Linux implementation. With LFS, you are in the driver's seat and dictate every aspect of the system. LFS allows you to create very compact Linux systems. When installing regular distributions, you are often forced to install a great many programs which are probably never used or understood. These programs waste resources. You may argue that with today's hard drive and CPUs, such resources are no longer a consideration. Sometimes, however, you are still constrained by size considerations if nothing else. Think about bootable CDs, USB sticks, and embedded systems. Those are areas where LFS can be beneficial. Another advantage of a custom built Linux system is security. By compiling the entire system from source code, you are empowered to audit everything and apply all the security patches desired. It is no longer necessary to wait for somebody else to compile binary packages that fix a security hole. Unless you examine the patch and implement it yourself, you have no guarantee that the new binary package was built correctly and adequately fixes the problem. The goal of Linux From Scratch is to build a complete and usable foundation-level system. If you do not wish to build your own Linux system from scratch, you may not entirely benefit from the information in this book. There are too many other good reasons to build your own LFS system to list them all here. In the end, education is by far the most powerful of reasons. As you continue in your LFS experience, you will discover the power that information and knowledge truly bring. LFS Target Architectures The primary target architectures of LFS are the AMD/Intel x86 (32-bit) and x86_64 (64-bit) CPUs. On the other hand, the instructions in this book are also known to work, with some modifications, with the Power PC and ARM CPUs. To build a system that utilizes one of these CPUs, the main prerequisite, in addition to those on the next few pages, is an existing Linux system such as an earlier LFS installation