linux_dist
Markdown

Part 07 Full System Build

Part 7: Building the Full LFS System

Overview

Inside chroot, you'll now build all ~70 packages that comprise the complete LFS system. This is Chapter 8 of the LFS book.

Prerequisites

  • Inside chroot environment
  • Completed Part 6
  • Working directory: /sources

Build Order

The packages must be built in this specific order due to dependencies:

Core System Libraries (1-20)

  1. Man-pages
  2. Iana-Etc
  3. Glibc
  4. Zlib
  5. Bzip2
  6. Xz
  7. Lz4
  8. Zstd
  9. File
  10. Readline
  11. M4
  12. Bc
  13. Flex
  14. Tcl
  15. Expect
  16. DejaGNU
  17. Pkgconf
  18. Binutils
  19. GMP
  20. MPFR

Compiler and Build Tools (21-30)

  1. MPC
  2. Attr
  3. Acl
  4. Libcap
  5. Libxcrypt
  6. Shadow
  7. GCC
  8. Ncurses
  9. Sed
  10. Psmisc

Core Utilities (31-50)

  1. Gettext
  2. Bison
  3. Grep
  4. Bash
  5. Libtool
  6. GDBM
  7. Gperf
  8. Expat
  9. Inetutils
  10. Less
  11. Perl
  12. XML::Parser
  13. Intltool
  14. Autoconf
  15. Automake
  16. OpenSSL
  17. Kmod
  18. Libelf (from Elfutils)
  19. Libffi
  20. Python

Additional Tools (51-70)

  1. Flit-Core
  2. Wheel
  3. Setuptools
  4. Ninja
  5. Meson
  6. Coreutils
  7. Diffutils
  8. Gawk
  9. Findutils
  10. Groff
  11. GRUB
  12. Gzip
  13. IPRoute2
  14. Kbd
  15. Libpipeline
  16. Make
  17. Patch
  18. Tar
  19. Texinfo
  20. Vim

System Tools (71-80)

  1. MarkupSafe
  2. Jinja2
  3. Systemd/Sysvinit
  4. Man-DB
  5. Procps-ng
  6. Util-linux
  7. E2fsprogs
  8. Sysklogd
  9. Sysvinit (or Systemd)
  10. About Debugging Symbols

Standard Build Pattern

Most packages follow this pattern:

cd /sources
tar -xf <package>.tar.xz
cd <package>

./configure --prefix=/usr <other-options>
make
make check  # Run tests (optional but recommended)
make install

cd /sources
rm -rf <package>

Critical Packages - Detailed Instructions

1. Man-pages-6.15

cd /sources
tar -xf man-pages-6.15.tar.xz
cd man-pages-6.15

rm -v man3/crypt*
make prefix=/usr install

cd /sources
rm -rf man-pages-6.15

2. Iana-Etc-20250807

cd /sources
tar -xf iana-etc-20250807.tar.gz
cd iana-etc-20250807

cp services protocols /etc

cd /sources
rm -rf iana-etc-20250807

3. Glibc-2.42 (Critical!)

Build Time: 14 SBU Disk Space: 3 GB

cd /sources
tar -xf glibc-2.42.tar.xz
cd glibc-2.42

# Apply patch if needed
patch -Np1 -i ../glibc-2.42-fhs-1.patch

# Fix hardcoded path
sed '/MAKEINFO/s/info/makeinfo/' -i Makefile

mkdir -v build
cd build

# Ensure correct library directory
echo "rootsbindir=/usr/sbin" > configparms

../configure --prefix=/usr \
             --disable-werror \
             --enable-kernel=5.4 \
             --enable-stack-protector=strong \
             --disable-nscd \
             libc_cv_slibdir=/usr/lib

make
make check  # Important - check for failures

# Known test failures: nptl/tst-thread-affinity-{pthread,pthread2,sched}
# These can be ignored

touch /etc/ld.so.conf

sed '/test-installation/s@$(PERL)@echo not running@' -i ../Makefile

make install

sed '/RTLDLIST=/s@/usr@@g' -i /usr/bin/ldd

# Install locale data
mkdir -pv /usr/lib/locale
localedef -i C -f UTF-8 C.UTF-8
localedef -i cs_CZ -f UTF-8 cs_CZ.UTF-8
localedef -i de_DE -f ISO-8859-1 de_DE
localedef -i de_DE@euro -f ISO-8859-15 de_DE@euro
localedef -i de_DE -f UTF-8 de_DE.UTF-8
localedef -i el_GR -f ISO-8859-7 el_GR
localedef -i en_GB -f ISO-8859-1 en_GB
localedef -i en_GB -f UTF-8 en_GB.UTF-8
localedef -i en_HK -f ISO-8859-1 en_HK
localedef -i en_PH -f ISO-8859-1 en_PH
localedef -i en_US -f ISO-8859-1 en_US
localedef -i en_US -f UTF-8 en_US.UTF-8
localedef -i es_ES -f ISO-8859-15 es_ES@euro
localedef -i es_MX -f ISO-8859-1 es_MX
localedef -i fa_IR -f UTF-8 fa_IR
localedef -i fr_FR -f ISO-8859-1 fr_FR
localedef -i fr_FR@euro -f ISO-8859-15 fr_FR@euro
localedef -i fr_FR -f UTF-8 fr_FR.UTF-8
localedef -i is_IS -f ISO-8859-1 is_IS
localedef -i is_IS -f UTF-8 is_IS.UTF-8
localedef -i it_IT -f ISO-8859-1 it_IT
localedef -i it_IT -f ISO-8859-15 it_IT@euro
localedef -i it_IT -f UTF-8 it_IT.UTF-8
localedef -i ja_JP -f EUC-JP ja_JP
localedef -i ja_JP -f SHIFT_JIS ja_JP.SJIS
localedef -i ja_JP -f UTF-8 ja_JP.UTF-8
localedef -i nl_NL@euro -f ISO-8859-15 nl_NL@euro
localedef -i ru_RU -f KOI8-R ru_RU.KOI8-R
localedef -i ru_RU -f UTF-8 ru_RU.UTF-8
localedef -i se_NO -f UTF-8 se_NO.UTF-8
localedef -i ta_IN -f UTF-8 ta_IN.UTF-8
localedef -i tr_TR -f UTF-8 tr_TR.UTF-8
localedef -i zh_CN -f GB18030 zh_CN.GB18030
localedef -i zh_HK -f BIG5-HKSCS zh_HK.BIG5-HKSCS
localedef -i zh_TW -f UTF-8 zh_TW.UTF-8

# Configure dynamic linker
cat > /etc/ld.so.conf << "EOF"
# Begin /etc/ld.so.conf
/usr/local/lib
/opt/lib

EOF

cd /sources
rm -rf glibc-2.42

4-17. Core Libraries (Quick Build)

# Zlib
tar -xf zlib-1.3.1.tar.gz
cd zlib-1.3.1
./configure --prefix=/usr
make && make check && make install
rm -fv /usr/lib/libz.a
cd /sources && rm -rf zlib-1.3.1

# Bzip2
tar -xf bzip2-1.0.8.tar.gz
cd bzip2-1.0.8
patch -Np1 -i ../bzip2-1.0.8-install_docs-1.patch
sed -i 's@\(ln -s -f \)$(PREFIX)/bin/@\1@' Makefile
sed -i "s@(PREFIX)/man@(PREFIX)/share/man@g" Makefile
make -f Makefile-libbz2_so
make clean
make && make PREFIX=/usr install
cp -av libbz2.so.* /usr/lib
ln -sv libbz2.so.1.0.8 /usr/lib/libbz2.so
cp -v bzip2-shared /usr/bin/bzip2
for i in /usr/bin/{bzcat,bunzip2}; do
  ln -sfv bzip2 $i
done
rm -fv /usr/lib/libbz2.a
cd /sources && rm -rf bzip2-1.0.8

# Xz
tar -xf xz-5.8.1.tar.xz
cd xz-5.8.1
./configure --prefix=/usr \
            --disable-static \
            --docdir=/usr/share/doc/xz-5.8.1
make && make check && make install
cd /sources && rm -rf xz-5.8.1

# Continue for remaining libraries...

18. Binutils-2.45

Build Time: 2.2 SBU

cd /sources
tar -xf binutils-2.45.tar.xz
cd binutils-2.45

mkdir -v build
cd build

../configure --prefix=/usr \
             --sysconfdir=/etc \
             --enable-gold \
             --enable-ld=default \
             --enable-plugins \
             --enable-shared \
             --disable-werror \
             --enable-64-bit-bfd \
             --enable-new-dtags \
             --with-system-zlib \
             --enable-default-hash-style=gnu

make tooldir=/usr

make -k check  # Some failures expected

make tooldir=/usr install

# Remove useless static libraries
rm -fv /usr/lib/lib{bfd,ctf,ctf-nobfd,gprofng,opcodes,sframe}.a

cd /sources
rm -rf binutils-2.45

27. GCC-15.2.0 (Critical!)

Build Time: 42 SBU Disk Space: 5.6 GB

cd /sources
tar -xf gcc-15.2.0.tar.xz
cd gcc-15.2.0

# Extract prerequisites
tar -xf ../mpfr-4.2.2.tar.xz
mv -v mpfr-4.2.2 mpfr
tar -xf ../gmp-6.3.0.tar.xz
mv -v gmp-6.3.0 gmp
tar -xf ../mpc-1.3.1.tar.gz
mv -v mpc-1.3.1 mpc

# For x86_64
case $(uname -m) in
  x86_64)
    sed -e '/m64=/s/lib64/lib/' \
        -i.orig gcc/config/i386/t-linux64
  ;;
esac

mkdir -v build
cd build

../configure --prefix=/usr \
             LD=ld \
             --enable-languages=c,c++ \
             --enable-default-pie \
             --enable-default-ssp \
             --enable-host-pie \
             --disable-multilib \
             --disable-bootstrap \
             --disable-fixincludes \
             --with-system-zlib

make

# Run tests (takes ~3 hours)
ulimit -s -H unlimited
sed -e '/cpython/d' -i ../gcc/testsuite/gcc.dg/plugin/plugin.exp
sed -e 's/no-pic /&-no-pie /' -i ../gcc/testsuite/gcc.target/i386/pr113689-1.c
sed -e 's/300000/(1|300000)/' -i ../libgomp/testsuite/libgomp.c-c++-common/pr96390.c
sed -e 's/{ target nonpic } //' \
    -e '/GOTPCREL/d' -i ../gcc/testsuite/gcc.target/i386/fentryname3.c

chown -R tester .
su tester -c "PATH=$PATH make -k check"

# View summary
../contrib/test_summary

make install

chown -v -R root:root \
    /usr/lib/gcc/$(gcc -dumpmachine)/15.2.0/include{,-fixed}

ln -svr /usr/bin/cpp /usr/lib
ln -sv gcc.1 /usr/share/man/man1/cc.1

ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/15.2.0/liblto_plugin.so \
        /usr/lib/bfd-plugins/

# Verify installation
echo 'int main(){}' > dummy.c
cc dummy.c -v -Wl,--verbose &> dummy.log
readelf -l a.out | grep ': /lib'
# Should show: [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]

# Check search paths
grep -E -o '/usr/lib.*/S?crt[1in].*succeeded' dummy.log
# Should show:
# /usr/lib/gcc/x86_64-pc-linux-gnu/15.2.0/../../../../lib/Scrt1.o succeeded
# /usr/lib/gcc/x86_64-pc-linux-gnu/15.2.0/../../../../lib/crti.o succeeded
# /usr/lib/gcc/x86_64-pc-linux-gnu/15.2.0/../../../../lib/crtn.o succeeded

grep 'SEARCH.*/usr/lib' dummy.log |sed 's|; |\n|g'
# Should include /usr/lib

grep "/lib.*/libc.so.6 " dummy.log
# Should show: attempt to open /usr/lib/libc.so.6 succeeded

grep found dummy.log
# Should show: found ld-linux-x86-64.so.2 at /usr/lib/ld-linux-x86-64.so.2

rm -v dummy.c a.out dummy.log

mkdir -pv /usr/share/gdb/auto-load/usr/lib
mv -v /usr/lib/*gdb.py /usr/share/gdb/auto-load/usr/lib

cd /sources
rm -rf gcc-15.2.0

Continuing the Build

For the remaining 40+ packages, follow the LFS 12.4 book Chapter 8 instructions. Each package has specific build instructions that should be followed carefully.

Key packages to pay special attention to:

  • Glibc - Already built above
  • GCC - Already built above
  • Binutils - Already built above
  • Shadow - Sets up user/password system
  • Systemd/Sysvinit - Init system choice
  • Util-linux - Essential system utilities
  • E2fsprogs - Filesystem utilities

Quick Build Script Template

For simpler packages:

#!/bin/bash
# build-package.sh

PKG_NAME=$1
PKG_VERSION=$2

cd /sources
tar -xf ${PKG_NAME}-${PKG_VERSION}.tar.*
cd ${PKG_NAME}-${PKG_VERSION}

./configure --prefix=/usr
make
make check
make install

cd /sources
rm -rf ${PKG_NAME}-${PKG_VERSION}

Stripping Debug Symbols

After all packages are installed:

save_usrlib="$(cd /usr/lib; ls ld-linux*[^g])
             libc.so.6
             libthread_db.so.1
             libquadmath.so.0.0.0
             libstdc++.so.6.0.33
             libitm.so.1.0.0
             libatomic.so.1.2.0"

cd /usr/lib

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

online_usrbin="bash find strip"
online_usrlib="libbfd-2.45.so
               libsframe.so.1.0.0
               libhistory.so.8.2
               libncursesw.so.6.5
               libm.so.6
               libreadline.so.8.2
               libz.so.1.3.1
               libzstd.so.1.5.7
               $(cd /usr/lib; find libnss*.so* -type f)"

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

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

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

unset BIN LIB save_usrlib online_usrbin online_usrlib

Clean Up

rm -rf /tmp/*
find /usr/lib /usr/libexec -name \*.la -delete
find /usr -depth -name $(uname -m)-lfs-linux-gnu\* | xargs rm -rf
userdel -r tester

Next Steps

Full system built! Proceed to:

  • Part 8: System configuration
  • Part 9: Kernel and bootloader
  • Part 10: Final testing

Important Notes

  • This is the most time-consuming part (~20-40 hours)
  • Run test suites when possible
  • Save logs for important packages
  • Don't skip GCC and Glibc verification steps
  • Take regular backups

References