Note

The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.

User:Seedofonan/CLFS Notes

From Funtoo
Jump to navigation Jump to search

Instructions from LFS 11.1

These instructions work on a Funtoo stage3-amd64-k10-1.4-release-std-2022-03-11.tar.xz system with nothing further installed except fchroot. A low-privilege account with a suitably hygenic environment is used, such as the "lfs" user. Additionally, all LFS packages/patches are already downloaded and located in $LFSHOWTO/sources. To demonstrate that this recipe works for targeting an arbitrary system, I've chosen the Raspberry Pi 4B but everything compiled as thumb2. TBD: Show diffs from original recipe to alternate targets (it's not much, really).

user $ export LFS_TGT=armv7l-linux-gnueabihf
user $ export LFSHOWTO=~/Documents/LFS-HowTo/thumb-r11.1
user $ export LFS=/tmp/lfs
user $ export LC_ALL=POSIX
user $ export PATH=$LFS/tools/bin:/bin:/usr/bin
user $ export CONFIG_SITE=$LFS/usr/share/config.site
user $ export MAKEFLAGS='-j4' #tailor for your number of processor cores
user $ set +h #turns off bash's hash function
user $ umask 022 #anyone can read but only this user can modify

# ====
# 2.7. Mounting the New Partition
# ====
user $ mkdir -v $LFS

# ====
# 3.1. Introduction
# ====
user $ cp -rv $LFSHOWTO/sources $LFS

# ====
# 4.2. Creating a limited directory layout in LFS filesystem
# ====
user $ mkdir -v $LFS/{etc,tools,usr,var} $LFS/usr/{bin,lib,sbin}

user $ for i in bin lib sbin; do
user $   ln -sv usr/$i $LFS/$i
user $ done

LFS Chapter 5 & 6 - Temporary tools

In the beginning of Chapter 5 the LFS recipe first compiles a cross gcc toolchain and installs it into $LFS/tools.

5.2. Binutils-2.38 - Pass 1
5.3. GCC-11.2.0 - Pass 1

Then for the remainder of Chapter 5 and all of Chapter 6 this cross-compiler is used to create everything the target needs to (f)chroot and build all the LFS packages. Note that everything built by the cross compiler gets re-compiled and replaced in Chapter 8, as indicated in square brackets.

5.4. Linux-5.16.9 API Headers
5.5.[8.5] Glibc-2.35
5.6.[7.7] Libstdc++ from GCC-11.2.0, Pass 1
6.2.[8.12] M4-1.4.19
6.3.[8.28] Ncurses-6.3
6.4.[8.34] Bash-5.1.16
6.5.[8.53] Coreutils-9.0
6.6.[8.55] Diffutils-3.8
6.7.[8.10] File-5.41
6.8.[8.57] Findutils-4.9.0
6.9.[8.56] Gawk-5.1.1
6.10.[8.33] Grep-3.7
6.11.[8.60] Gzip-1.11
6.12.[8.64] Make-4.3
6.13.[8.65] Patch-2.7.6
6.14.[8.29] Sed-4.8
6.15.[8.66] Tar-1.34
6.16.[8.8] Xz-5.2.5
6.17.[8.18] Binutils-2.38 - Pass 2
6.18.[GMP:8.19 MPFR:8.20 MPC:8.21 GCC:8.26] GCC-11.2.0 - Pass 2
   LFSr11.1-chapter5and6.sh (bash source code) - Chapter 5 and Chapter 6

LFS Chapter 7 - Chroot

At this point, the cross-compiler folder $LFS/tools can be deleted. The remainder of packages in Chapter 7 and all of those in Chapter 8 are built while (f)chroot'ed and so have no way to execute anything other than those built above.

7.7. Libstdc++ from GCC-11.2.0, Pass 2
7.8.[8.31] Gettext-0.21
7.9.[8.32] Bison-3.8.2
7.10. Perl-5.34.0
7.11.[8.50] Python-3.10.2
7.12.[8.67] Texinfo-6.8
7.13.[8.72] Util-linux-2.37.4
user $ rm -r $LFS/tools
user $ su - root #because no sudo
# ==========
# Chapter 7. Entering Chroot and Building Additional Temporary Tools
# ==========
root # export LFS=/tmp/lfs/ #NOTE trailing '/'
root # export LFS_TGT=armv7l-linux-gnueabihf
# 7.2. Changing Ownership
root # chown -R root:root "$LFS"{usr,lib,var,etc,bin,sbin}
# 7.3. Preparing Virtual Kernel File Systems
root # mkdir -pv "$LFS"{dev,proc,sys,run}
# 7.3.1. Creating Initial Device Nodes
root # mknod -m 600 "$LFS"dev/console c 5 1
root # mknod -m 666 "$LFS"dev/null c 1 3
# 7.3.2. Mounting and Populating /dev
root # mount -v --bind /dev "$LFS"dev #unnecessary, done by fchroot
root # 7.3.3. Mounting Virtual Kernel File Systems
root # mount -v --bind /dev/pts "$LFS"dev/pts #unnecessary, done by fchroot
root # mount -vt proc proc "$LFS"proc #unnecessary, done by fchroot
root # mount -vt sysfs sysfs "$LFS"sys #unnecessary, done by fchroot
root # mount -vt tmpfs tmpfs "$LFS"run
# 7.4. Entering the Chroot Environment
root # fchroot "$LFS" /usr/bin/env -i  \
root #     HOME=/root                  \
root #     TERM="$TERM"                \
root #     PS1='(lfs chroot) \u:\w\$ ' \
root #     PATH=/usr/bin:/usr/sbin     \
root #     LFS_TGT="$LFS_TGT"          \
root #     /bin/bash --login
chroot # export MAKEFLAGS='-j4' #tailor for your number of processor cores
chroot # cd /sources
   LFSr11.1-chapter7.sh (bash source code) - Chapter 7

LFS Chapter 8 - (re-)Build Everything (except Libstdc++ and perl)

In Chapter 8 LFS begins the testing of packages before installing them. Note that the final cross-compiled package isn't replaced until 8.66, nearly at the end and only right after other important tools like make and patch. TBD: Eliminate unneded packages.

8.3. Man-pages-5.13
8.4. Iana-Etc-20220207
8.5. Glibc-2.35
8.6. Zlib-1.2.11
8.7. Bzip2-1.0.8
8.8. Xz-5.2.5
8.9. Zstd-1.5.2
8.10. File-5.41
8.11. Readline-8.1.2
8.12. M4-1.4.19
8.13. Bc-5.2.2
8.14. Flex-2.6.4
8.15. Tcl-8.6.12
8.16. Expect-5.45.4
8.17. DejaGNU-1.6.3
8.18. Binutils-2.38 - Pass 3
8.19. GMP-6.2.1
8.20. MPFR-4.1.0
8.21. MPC-1.2.1
8.22. Attr-2.5.1
8.23. Acl-2.3.1
8.24. Libcap-2.63
8.25. Shadow-4.11.1
8.26. GCC-11.2.0
8.27. Pkg-config-0.29.2
8.28. Ncurses-6.3
8.29. Sed-4.8
8.30. Psmisc-23.4
8.31. Gettext-0.21
8.32. Bison-3.8.2
8.33. Grep-3.7
8.34. Bash-5.1.16
8.35. Libtool-2.4.6
8.36. GDBM-1.23
8.37. Gperf-3.1
8.38. Expat-2.4.6
8.39. Inetutils-2.2
8.40. Less-590
8.42. XML::Parser-2.46
8.43. Intltool-0.51.0
8.44. Autoconf-2.71
8.45. Automake-1.16.5
8.46. OpenSSL-3.0.1
8.47. Kmod-29
8.48. Libelf from Elfutils-0.186
8.49. Libffi-3.4.2
8.50. Python-3.10.2
8.51. Ninja-1.10.2
8.52. Meson-0.61.1
8.53. Coreutils-9.0
8.54. Check-0.15.2
8.55. Diffutils-3.8
8.56. Gawk-5.1.1
8.57. Findutils-4.9.0
8.58. Groff-1.22.4
8.59. GRUB-2.06
8.60. Gzip-1.11
8.61. IPRoute2-5.16.0
8.62. Kbd-2.4.0
8.63. Libpipeline-1.5.5
8.64. Make-4.3
8.65. Patch-2.7.6
8.66. Tar-1.34
8.67. Texinfo-6.8
8.68. Vim-8.2.4383
8.69. Eudev-3.2.11
8.70. Man-DB-2.10.1
8.71. Procps-ng-3.3.17
8.72. Util-linux-2.37.4
8.73. E2fsprogs-1.46.5
8.74. Sysklogd-1.5.1
8.75. Sysvinit-3.01
   LFSr11.1-chapter8.sh (bash source code) - Chapter 8
# =====
# 8.77. Stripping
# =====
chroot # save_usrlib="$(cd /usr/lib; ls ld-linux*)
chroot #              libc.so.6
chroot #              libthread_db.so.1
chroot #              libquadmath.so.0.0.0
chroot #              libstdc++.so.6.0.29
chroot #              libitm.so.1.0.0
chroot #              libatomic.so.1.2.0"

chroot # cd /usr/lib

chroot # for LIB in $save_usrlib; do
chroot #     objcopy --only-keep-debug $LIB $LIB.dbg
chroot #     cp $LIB /tmp/$LIB
chroot #     strip --strip-unneeded /tmp/$LIB
chroot #     objcopy --add-gnu-debuglink=$LIB.dbg /tmp/$LIB
chroot #     install -vm755 /tmp/$LIB /usr/lib
chroot #     rm /tmp/$LIB
chroot # done

chroot # online_usrbin="bash find strip"
chroot # online_usrlib="libbfd-2.38.so
chroot #                libhistory.so.8.1
chroot #                libncursesw.so.6.3
chroot #                libm.so.6
chroot #                libreadline.so.8.1
chroot #                libz.so.1.2.11
chroot #                $(cd /usr/lib; find libnss*.so* -type f)"

chroot # for BIN in $online_usrbin; do
chroot #     cp /usr/bin/$BIN /tmp/$BIN
chroot #     strip --strip-unneeded /tmp/$BIN
chroot #     install -vm755 /tmp/$BIN /usr/bin
chroot #     rm /tmp/$BIN
chroot # done

chroot # for LIB in $online_usrlib; do
chroot #     cp /usr/lib/$LIB /tmp/$LIB
chroot #     strip --strip-unneeded /tmp/$LIB
chroot #     install -vm755 /tmp/$LIB /usr/lib
chroot #     rm /tmp/$LIB
chroot # done

chroot # for i in $(find /usr/lib -type f -name \*.so* ! -name \*dbg) \
chroot #          $(find /usr/lib -type f -name \*.a)                 \
chroot #          $(find /usr/{bin,sbin,libexec} -type f); do
chroot #     case "$online_usrbin $online_usrlib $save_usrlib" in
chroot #         *$(basename $i)* )
chroot #             ;;
chroot #         * ) strip --strip-unneeded $i
chroot #             ;;
chroot #     esac
chroot # done

chroot # unset BIN LIB save_usrlib online_usrbin online_usrlib
chroot # cd ../..

TBD: Build missing stuff & Portage

chroot # exit
root # umount -v "$LFS"run
root # exit
user $ cd $LFS