os232

Final stretch! GO GO GO!!

8.0 Chapter 8 Setup

8.0.S Entering chroot environment

Run as root

Check mounted or not

findmnt | grep $LFS

Output if LFS IS MOUNTED:

├─/mnt/lfs                                              /dev/sdb2   ext4        rw,relatime
│ ├─/mnt/lfs/dev                                        udev        devtmpfs    rw,nosuid,relatime,size=1981744k,nr_inodes=495436,mode=755,inode64
│ │ ├─/mnt/lfs/dev/pts                                  devpts      devpts      rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000
│ │ └─/mnt/lfs/dev/shm                                  tmpfs       tmpfs       rw,nosuid,nodev,relatime,inode64
│ ├─/mnt/lfs/proc                                       proc        proc        rw,relatime
│ ├─/mnt/lfs/sys                                        sysfs       sysfs       rw,relatime
│ └─/mnt/lfs/run                                        tmpfs       tmpfs       rw,relatime,inode64

Output if LFS IS NOT MOUNTED:

├─/mnt/lfs                                              /dev/sdb2   ext4        rw,relatime

Mount virtual filesystem if not mounted

mkdir -pv $LFS/{dev,proc,sys,run}

mount -v --bind /dev $LFS/dev
mount -v --bind /dev/pts $LFS/dev/pts
mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys
mount -vt tmpfs tmpfs $LFS/run

if [ -h $LFS/dev/shm ]; then
  mkdir -pv $LFS/$(readlink $LFS/dev/shm)
else
  mount -t tmpfs -o nosuid,nodev tmpfs $LFS/dev/shm
fi

Enter chroot environment

chroot "$LFS" /usr/bin/env -i   \
    HOME=/root                  \
    TERM="$TERM"                \
    PS1='(lfs chroot) \u:\w\$ ' \
    PATH=/usr/bin:/usr/sbin     \
    /bin/bash --login

8.0.E Exiting chroot environment

When you want to exit just do this

exit

8.0.X Pre-flight Checks

Make sure you are in (lfs chroot) root:/# |
Create version-check.sh (See Section 7.12T on creating version-check.sh)

Run version-check.sh to see version requirements(Make sure all is OK)

bash version-check.sh

Check your “NPROC”, and “MAKEFLAGS” environment variables

echo "NPROC=$(nproc) MAKEFLAGS=$MAKEFLAGS"

Set MAKEFLAGS variable

export MAKEFLAGS='-j4'

8.0.B Backup

See Section 7.13.2 on backing up the LFS system.


8.82 (OPTIONAL) Stripping

If the intended user is not a programmer and does not plan to do any debugging of the system software, the system’s size can be decreased by some 2 GB by removing the debugging symbols, and some unnecessary symbol table entries, from binaries and libraries. This causes no real inconvenience for a typical Linux user. ```bash 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.32 libitm.so.1.0.0 libatomic.so.1.2.0”

cd /usr/lib

for LIB in $save_usrlib; do objcopy –only-keep-debug $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.41.so libsframe.so.1.0.0 libhistory.so.8.2 libncursesw.so.6.4 libm.so.6 libreadline.so.8.2 libz.so.1.2.13 $(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 ;; esac done

unset BIN LIB save_usrlib online_usrbin online_usrlib


## 8.83 Cleaning up
```bash
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