2015年12月16日 星期三

[Linux From Scratch - Version 7.8][LFS] Build up LFS system

Prepare: (Two method)

  1. prepare one USB Disk
  2. using dd create one empty iso
    Create 8G file (Two method):
    1. fallocate -l 8G lfs.img
    2. dd if=/dev/zero of=lfs.img bs=1 count=0 seek=8G

    mkfs -t ext4 lfs.img

Following the document build up the enviroment.

Get the source code.

export LFS=/mnt/lfs
mkdir -v $LFS/sources
wget http://www.linuxfromscratch.org/lfs/view/stable/wget-list
chmod -v a+wt $LFS/sources
wget --input-file=wget-list --continue --directory-prefix=$LFS/sources

used to verify that all the correct packages are available before proceeding.
pushd $LFS/sources
md5sum -c md5sums
popd

Add LFS user & group
Switch to the user of LFS.
Environment settings are describing in the chapter 4.3 (Adding the LFS User).

5.4. Binutils-2.25.1 - Pass 1

tar xvf $LFS/sources/binutils-2.25.1.tar.bz2 -C .
cd binutils-2.25.1/

mkdir -v ../binutils-build
cd ../binutils-build

If building on x86_64, create a symlink to ensure the sanity of the toolchain
case $(uname -m) in
  x86_64) mkdir -v /tools/lib && ln -sv lib /tools/lib64 ;;
esac

 ../binutils-2.25.1/configure     \
    --prefix=/tools            \
    --with-sysroot=$LFS        \
    --with-lib-path=/tools/lib \
    --target=$LFS_TGT          \
    --disable-nls              \
    --disable-werror

make
make install

5.5. GCC-5.2.0 - Pass 1

tar xvf $LFS/sources/gcc-5.2.0.tar.bz2 -C .
cd gcc-5.2.0/

tar xvf $LFS/sources/mpfr-3.1.3.tar.xz -C ./ && mv mpfr-3.1.3 mpfr
tar xvf $LFS/sources/gmp-6.0.0a.tar.xz -C ./ && mv gmp-6.0.0 gmp
tar xvf $LFS/sources/mpc-1.0.3.tar.gz -C ./ && mv mpc-1.0.3 mpc

The following command will change the location of GCC’s default dynamic linker to use the one installed in /tools.

cd gcc-5.2.0
for file in \
 $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
do
  cp -uv $file{,.orig}
  sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' \
      -e 's@/usr@/tools@g' $file.orig > $file
  echo '
#undef STANDARD_STARTFILE_PREFIX_1
#undef STANDARD_STARTFILE_PREFIX_2
#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
#define STANDARD_STARTFILE_PREFIX_2 ""' >> $file
  touch $file.orig
done

mkdir -v ../gcc-build
cd ../gcc-build
../gcc-5.2.0/configure                             \
    --target=$LFS_TGT                              \
    --prefix=/tools                                \
    --with-glibc-version=2.11                      \
    --with-sysroot=$LFS                            \
    --with-newlib                                  \
    --without-headers                              \
    --with-local-prefix=/tools                     \
    --with-native-system-header-dir=/tools/include \
    --disable-nls                                  \
    --disable-shared                               \
    --disable-multilib                             \
    --disable-decimal-float                        \
    --disable-threads                              \
    --disable-libatomic                            \
    --disable-libgomp                              \
    --disable-libquadmath                          \
    --disable-libssp                               \
    --disable-libvtv                               \
    --disable-libstdcxx                            \
    --enable-languages=c,c++
make
make install

5.6. Linux-4.2 API Headers

tar xvf $LFS/sources/linux-4.2.tar.xz -C .
cd linux-4.2
make mrproper
make INSTALL_HDR_PATH=dest headers_install
cp -rv dest/include/* /tools/include

5.7. Glibc-2.22

Extract the tarball file of glibc.
tar xvf $LFS/sources/glibc-2.22.tar.xz -C .
cd glibc-2.22/
patch -Np1 -i $LFS/sources/glibc-2.22-upstream_i386_fix-1.patch
mkdir -v ../glibc-build
cd ../glibc-build

configuration
../glibc-2.22/configure                             \
      --prefix=/tools                               \
      --host=$LFS_TGT                               \
      --build=$(../glibc-2.22/scripts/config.guess) \
      --disable-profile                             \
      --enable-kernel=2.6.32                        \
      --enable-obsolete-rpc                         \
      --with-headers=/tools/include                 \
      libc_cv_forced_unwind=yes                     \
      libc_cv_ctors_header=yes                      \
      libc_cv_c_cleanup=yes
make
make install

It is imperative to stop and ensure that the basic functions (compiling and linking) of the new toolchain are working as expected.
echo 'int main(){}' > dummy.c
$LFS_TGT-gcc dummy.c
readelf -l a.out | grep ': /tools'

If everything is working correctly, there should be no errors, and the output of the last command will be of the form:
[Requesting program interpreter: /tools/lib/ld-linux.so.2]

 Note that for 64-bit machines, the interpreter name will be /tools/lib64/ld-linux-x86-64.so.2.

If the output is not shown as above or there was no output at all, then something is wrong.
Once all is well, clean up the test files:
rm -v dummy.c a.out

5.8. Libstdc++-5.2.0

tar xvf $LFS/sources/gcc-5.2.0.tar.bz2 -C .
cd gcc-5.2.0
mkdir -v ../gcc-build
cd ../gcc-build
../gcc-5.2.0/libstdc++-v3/configure \
    --host=$LFS_TGT                 \
    --prefix=/tools                 \
    --disable-multilib              \
    --disable-nls                   \
    --disable-libstdcxx-threads     \
    --disable-libstdcxx-pch         \
    --with-gxx-include-dir=/tools/$LFS_TGT/include/c++/5.2.0
make
make install

5.9. Binutils-2.25.1 - Pass 2

tar xvf $LFS/sources/binutils-2.25.1.tar.bz2 -C .

mkdir -v ../binutils-build
cd ../binutils-build

Prepare Binutils for compilation:
CC=$LFS_TGT-gcc                \
AR=$LFS_TGT-ar                 \
RANLIB=$LFS_TGT-ranlib         \
../binutils-2.25.1/configure     \
    --prefix=/tools            \
    --disable-nls              \
    --disable-werror           \
    --with-lib-path=/tools/lib \
    --with-sysroot

Compile the package:
make

 Install the package:
make install

 Now prepare the linker for the “Re-adjusting” phase in the next chapter:
make -C ld clean
make -C ld LIB_PATH=/usr/lib:/lib
cp -v ld/ld-new /tools/bin

5.10. GCC-5.2.0 - Pass 2

GCC-5.2.0 - Pass 1 is partial does not include the extended features of the system header.
GCC-5.2.0 - Pass 2 building the temporary libc, but this build of GCC now requires the full internal header.
tar xvf $LFS/sources/gcc-5.2.0.tar.bz2 -C .
cd gcc-5.2.0/
cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
  `dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/include-fixed/limits.h
tar xvf $LFS/sources/mpfr-3.1.3.tar.xz -C ./ && mv mpfr-3.1.3 mpfr
tar xvf $LFS/sources/gmp-6.0.0a.tar.xz -C ./ && mv gmp-6.0.0 gmp
tar xvf $LFS/sources/mpc-1.0.3.tar.gz -C ./ && mv mpc-1.0.3 mpc
Change the location of GCC’s default dynamic linker to use the one installed in /tools
for file in \
 $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
do
  cp -uv $file{,.orig}
  sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' \
      -e 's@/usr@/tools@g' $file.orig > $file
  echo '
#undef STANDARD_STARTFILE_PREFIX_1
#undef STANDARD_STARTFILE_PREFIX_2
#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
#define STANDARD_STARTFILE_PREFIX_2 ""' >> $file
  touch $file.orig
done
Create a separate build directory again:
mkdir -v ../gcc-build
cd ../gcc-build
Prepare GCC for compilation:
CC=$LFS_TGT-gcc                                    \
CXX=$LFS_TGT-g++                                   \
AR=$LFS_TGT-ar                                     \
RANLIB=$LFS_TGT-ranlib                             \
../gcc-5.2.0/configure                             \
    --prefix=/tools                                \
    --with-local-prefix=/tools                     \
    --with-native-system-header-dir=/tools/include \
    --enable-languages=c,c++                       \
    --disable-libstdcxx-pch                        \
    --disable-multilib                             \
    --disable-bootstrap                            \
    --disable-libgomp
make
make install

5.11. Tcl-core-8.6.4

tar xvf $LFS/sources/gcc-5.2.0.tar.bz2 -C .
cd /tcl8.6.4/unix
./configure –prefix=/tools
make
make install
Make the installed library writable so debugging symbols can be removed later:
chmod -v u+w /tools/lib/libtcl8.6.so
Tcl’s headers. Expect, requires them to build.
make install-private-headers
make a necessary symbolic link:
ln -sv tclsh8.6 /tools/bin/tclsh

5.12. Expect-5.45

tar xvf $LFS/sources/expect5.45.tar.gz -C .
cd expect5.45
use /bin/stty instead of a /usr/local/bin/stty
cp -v configure{,.orig}
sed ‘s:/usr/local/bin:/bin:’ configure.orig > configure
./configure --prefix=/tools       \
            --with-tcl=/tools/lib \
            --with-tclinclude=/tools/include
make
make SCRIPTS=”” install
SCRIPTS=""
This prevents installation of the supplementary Expect scripts, which are not needed.

5.13. DejaGNU-1.5.3

tar xvf $LFS/sources/dejagnu-1.5.3.tar.gz -C .
cd dejagnu-1.5.3/
make install

5.14. Check-0.10.0

tar xvf $LFS/sources/check-0.10.0.tar.gz -C .
cd check-0.10.0/
PKG_CONFIG= ./configure –prefix=/tools
PKG_CONFIG=
This tells the configure script to ignore any pkg-config options that may cause the system to try to link with libraries not in the /tools directory.
make
make install

5.15. Ncurses-6.0

tar xvf $LFS/sources/ncurses-6.0.tar.gz -C .
cd ncurses-6.0/
ensure that gawk is found first during configuration:
sed -i s/mawk// configure
./configure --prefix=/tools \
            --with-shared   \
            --without-debug \
            --without-ada   \
            --enable-widec  \
            --enable-overwrite
make
make install

5.16. Bash-4.3.30

tar xvf $LFS/sources/bash-4.3.30.tar.gz -C .
cd bash-4.3.30
./configure –prefix=/tools –without-bash-malloc
make
make install
Make a link for the programs that use sh for a shell:
ln -sv bash /tools/bin/sh

5.17. Bzip2-1.0.6

tar xvf $LFS/sources/bzip2-1.0.6.tar.gz -C .
cd bzip2-1.0.6
Bzip2 package does not contain a configure script.
make
make PREFIX=/tools install

5.18. Coreutils-8.24

tar xvf $LFS/sources/coreutils-8.24.tar.xz -C .
cd coreutils-8.24/
./configure –prefix=/tools –enable-install-program=hostname
make
make install

5.19. Diffutils-3.3

tar xvf $LFS/sources/diffutils-3.3.tar.xz -C .
cd diffutils-3.3
./configure –prefix=/tools
make
make install

5.20. File-5.24

tar xvf $LFS/sources/file-5.24.tar.gz -C .
cd file-5.24/
./configure –prefix=/tools
make
make install

5.21. Findutils-4.4.2

tar xvf $LFS/sources/findutils-4.4.2.tar.gz -C .
cd findutils-4.4.2/
./configure –prefix=/tools
make
make install

5.22. Gawk-4.1.3

tar xvf $LFS/sources/gawk-4.1.3.tar.xz -C .
cd gawk-4.1.3/
./configure –prefix=/tools
make
make install

5.23. Gettext-0.19.5.1

tar xvf $LFS/sources/gettext-0.19.5.1.tar.xz -C .
cd gettext-0.19.5.1/gettext-tools
EMACS=”no” ./configure –prefix=/tools –disable-shared
make -C gnulib-lib
make -C intl pluralx.c
make -C src msgfmt
make -C src msgmerge
make -C src xgettext
Install the msgfmt, msgmerge and xgettext programs:
cp -v src/{msgfmt,msgmerge,xgettext} /tools/bin

5.24. Grep-2.21

tar xvf $LFS/sources/grep-2.21.tar.xz -C .
cd grep-2.21/
./configure –prefix=/tools
make
make install

5.25. Gzip-1.6

tar xvf $LFS/sources/gzip-1.6.tar.xz -C .
cd gzip-1.6/
./configure –prefix=/tools
make
make install

5.26. M4-1.4.17

tar xvf $LFS/sources/m4-1.4.17.tar.xz -C .
cd m4-1.4.17/
./configure –prefix=/tools
make
make install

5.27. Make-4.0

tar xvf $LFS/sources/make-4.0.tar.bz2 -C .
cd make-4.1/
./configure –prefix=/tools –without-guile
make
make install


Ps. After compile make-4.1 package, when use make command will cause segment fault. So I change 4.0 to be my version of make.

5.28. Patch-2.7.5

tar xvf $LFS/sources/patch-2.7.5.tar.xz -C .
cd patch-2.7.5/
./configure –prefix=/tools
make
make install

5.29. Perl-5.22.0

tar xvf $LFS/sources/perl-5.22.0.tar.bz2 -C .
cd perl-5.22.0/
sh Configure -des -Dprefix=/tools -Dlibs=-lm
make
Only a few of the utilities and libraries need to be installed at this time:
cp -v perl cpan/podlators/pod2man /tools/bin
mkdir -pv /tools/lib/perl5/5.22.0
cp -Rv lib/* /tools/lib/perl5/5.22.0

5.30. Sed-4.2.2

tar xvf $LFS/sources/sed-4.2.2.tar.bz2 -C .
cd sed-4.2.2/
./configure –prefix=/tools
make
make install

5.31. Tar-1.28

tar xvf $LFS/sources/tar-1.28.tar.xz -C .
cd tar-1.28/
./configure –prefix=/tools
make
make install

5.32. Texinfo-6.0

tar xvf $LFS/sources/texinfo-6.0.tar.xz -C .
cd texinfo-6.0/
./configure –prefix=/tools
make
make install

5.33. Util-linux-2.27

tar xvf $LFS/sources/util-linux-2.27.tar.xz -C .
cd util-linux-2.27/
./configure --prefix=/tools                \
            --without-python               \
            --disable-makeinstall-chown    \
            --without-systemdsystemunitdir \
            PKG_CONFIG=""
make
make install

5.34. Xz-5.2.1

tar xvf $LFS/sources/xz-5.2.1.tar.xz -C .
cd xz-5.2.1/
./configure –prefix=/tools
make
make install

5.35. Stripping

strip –strip-debug /tools/lib/*
/usr/bin/strip –strip-unneeded /tools/{,s}bin/*
To save more, remove the documentation:
rm -rf /tools/{,share}/{info,man,doc}


5.36. Changing Ownership

hange the ownership of the $LFS/tools directory to user root by running the following command:
chown -R root:root $LFS/tools
Although the $LFS/tools directory can be deleted once the LFS system has been finished,

6.2. Preparing Virtual Kernel File Systems

Begin by creating directories onto which the file systems will be mounted:
mkdir -pv $LFS/{dev,proc,sys,run}

Creating Initial Device Nodes

mknod -m 600 $LFS/dev/console c 5 1
mknod -m 666 $LFS/dev/null c 1 3

Mounting and Populating /dev

mount -v --bind /dev $LFS/dev

Mounting Virtual Kernel File Systems

mount -vt devpts devpts $LFS/dev/pts -o gid=5,mode=620
mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys
mount -vt tmpfs tmpfs $LFS/run
The /run tmpfs was mounted above so in this case only a directory needs to be created.
if [ -h $LFS/dev/shm ]; then
  mkdir -pv $LFS/$(readlink $LFS/dev/shm)
fi

6.3. Package Management

Discuss about package management.

6.4. Entering the Chroot Environment

Root Priviledge
As user root, run the following command to enter the realm that is.
chroot "$LFS" /tools/bin/env -i \
    HOME=/root                  \
    TERM="$TERM"                \
    PS1='\u:\w\$ '              \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
    /tools/bin/bash --login +h
Prompt will say I have no name! This is normal because the /etc/passwd file has not been created yet.

6.5. Creating Directories

Create a standard directory tree by issuing the following commands:
mkdir -pv /{bin,boot,etc/{opt,sysconfig},home,lib/firmware,mnt,opt}
mkdir -pv /{media/{floppy,cdrom},sbin,srv,var}
install -dv -m 0750 /root
install -dv -m 1777 /tmp /var/tmp
mkdir -pv /usr/{,local/}{bin,include,lib,sbin,src}
mkdir -pv /usr/{,local/}share/{color,dict,doc,info,locale,man}
mkdir -v  /usr/{,local/}share/{misc,terminfo,zoneinfo}
mkdir -v  /usr/libexec
mkdir -pv /usr/{,local/}share/man/man{1..8}

case $(uname -m) in
 x86_64) ln -sv lib /lib64
         ln -sv lib /usr/lib64
         ln -sv lib /usr/local/lib64 ;;
esac

mkdir -v /var/{log,mail,spool}
ln -sv /run /var/run
ln -sv /run/lock /var/lock
mkdir -pv /var/{opt,cache,lib/{color,misc,locate},local}

ln -sv /tools/bin/{bash,cat,echo,pwd,stty} /bin
ln -sv /tools/bin/perl /usr/bin
ln -sv /tools/lib/libgcc_s.so{,.1} /usr/lib
ln -sv /tools/lib/libstdc++.so{,.6} /usr/lib
sed 's/tools/usr/' /tools/lib/libstdc++.la > /usr/lib/libstdc++.la
ln -sv bash /bin/sh
Historically, Linux maintains a list of the mounted file systems in the file /etc/mtab.
ln -sv /proc/self/mounts /etc/mtab
Create the /etc/passwd
cat > /etc/passwd << "EOF"
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/dev/null:/bin/false
daemon:x:6:6:Daemon User:/dev/null:/bin/false
messagebus:x:18:18:D-Bus Message Daemon User:/var/run/dbus:/bin/false
nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
EOF
Create the /etc/group
cat > /etc/group << "EOF"
root:x:0:
bin:x:1:daemon
sys:x:2:
kmem:x:3:
tape:x:4:
tty:x:5:
daemon:x:6:
floppy:x:7:
disk:x:8:
lp:x:9:
dialout:x:10:
audio:x:11:
video:x:12:
utmp:x:13:
usb:x:14:
cdrom:x:15:
adm:x:16:
messagebus:x:18:
systemd-journal:x:23:
input:x:24:
mail:x:34:
nogroup:x:99:
users:x:999:
EOF
/etc/passwd and /etc/group files have been created
exec /tools/bin/bash --login +h

I have no name!:/# exec /tools/bin/bash --login +h
root:/# 
touch /var/log/{btmp,lastlog,wtmp}
chgrp -v utmp /var/log/lastlog
chmod -v 664  /var/log/lastlog
chmod -v 600  /var/log/btmp
The /var/log/wtmp file records all logins and logouts.
The /var/log/lastlog file records when each user last logged in.
The /var/log/btmp file records the bad login attempts.
The /run/utmp file records the users that are currently logged in.

6.7. Linux-4.2 API Headers

cd /home
tar xvf /sources/linux-4.2.tar.xz -C .
Make sure there are no stale files and dependencies lying around from previous activity:
make mrproper
Now extract the user-visible kernel headers from the source
make INSTALL_HDR_PATH=dest headers_install
find dest/include \( -name .install -o -name ..install.cmd \) -delete
cp -rv dest/include/* /usr/include

6.8. Man-pages-4.02

cd /home
tar xvf /sources/man-pages-4.02.tar.xz -C .
Install Man-pages by running:
make install

6.9. Glibc-2.22

cd /home
tar xvf /sources/glibc-2.22.tar.xz -C .
cd glibc-2.22/
following patch to make such programs store their runtime data in the FHS-compliant locations:
patch -Np1 -i /sources/glibc-2.22-fhs-1.patch
Fix a build problem that affects i386 systems:
patch -Np1 -i /sources/glibc-2.22-upstream_i386_fix-1.patch
mkdir -v ../glibc-build
cd ../glibc-build
../glibc-2.22/configure    \
    --prefix=/usr          \
    --disable-profile      \
    --enable-kernel=2.6.32 \
    --enable-obsolete-rpc
make
Now test the build results:
make check
touch /etc/ld.so.conf
Install the package:
make install
Install the configuration file and runtime directory for nscd
cp -v ../glibc-2.22/nscd/nscd.conf /etc/nscd.conf
mkdir -pv /var/cache/nscd
There are two method for Individual locales.
Method 1:
Individual locales can be installed using the localedef program
mkdir -pv /usr/lib/locale
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 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_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 it_IT -f ISO-8859-1 it_IT
localedef -i it_IT -f UTF-8 it_IT.UTF-8
localedef -i ja_JP -f EUC-JP ja_JP
localedef -i ru_RU -f KOI8-R ru_RU.KOI8-R
localedef -i ru_RU -f UTF-8 ru_RU.UTF-8
localedef -i tr_TR -f UTF-8 tr_TR.UTF-8
localedef -i zh_CN -f GB18030 zh_CN.GB18030
Method 2:
Alternatively, install all locales listed in the glibc-2.22/localedata/SUPPORTED file
make localedata/install-locales

Configuring Glibc

The /etc/nsswitch.conf file needs to be created because the Glibc defaults do not work well in a networked environment.
cat > /etc/nsswitch.conf << "EOF"
# Begin /etc/nsswitch.conf

passwd: files
group: files
shadow: files

hosts: files dns
networks: files

protocols: files
services: files
ethers: files
rpc: files

# End /etc/nsswitch.conf
EOF

Adding time zone data

tar -xvf source/tzdata2015f.tar.gz -C /tmp


ZONEINFO=/usr/share/zoneinfo
mkdir -pv $ZONEINFO/{posix,right}

for tz in etcetera southamerica northamerica europe africa antarctica  \
          asia australasia backward pacificnew systemv; do
    zic -L /dev/null   -d $ZONEINFO       -y "sh yearistype.sh" ${tz}
    zic -L /dev/null   -d $ZONEINFO/posix -y "sh yearistype.sh" ${tz}
    zic -L leapseconds -d $ZONEINFO/right -y "sh yearistype.sh" ${tz}
done

cp -v zone.tab zone1970.tab iso3166.tab $ZONEINFO
zic -d $ZONEINFO -p America/New_York
unset ZONEINFO
One way to determine the local time zone is to run the following script:
tzselect
Then create the /etc/localtime file by running:
cp -v /usr/share/zoneinfo/<xxx> /etc/localtime

Configuring the Dynamic Loader

Create a new file /etc/ld.so.conf by running the following:
cat > /etc/ld.so.conf << "EOF"
# Begin /etc/ld.so.conf
/usr/local/lib
/opt/lib

EOF
The dynamic loader can also search a directory and include the contents of files found there
cat >> /etc/ld.so.conf << "EOF"
# Add an include directory
include /etc/ld.so.conf.d/*.conf

EOF


mkdir -pv /etc/ld.so.conf.d

6.10. Adjusting the Toolchain

Change ld
mv -v /tools/bin/{ld,ld-old}
mv -v /tools/$(gcc -dumpmachine)/bin/{ld,ld-old}
mv -v /tools/bin/{ld-new,ld}
ln -sv /tools/bin/ld /tools/$(gcc -dumpmachine)/bin/ld
gcc -dumpspecs | sed -e 's@/tools@@g'                   \
    -e '/\*startfile_prefix_spec:/{n;s@.*@/usr/lib/ @}' \
    -e '/\*cpp:/{n;s@$@ -isystem /usr/include@}' >      \
    `dirname $(gcc --print-libgcc-file-name)`/specs
-e 's@/tools@@g'    
Remove tools

-e '/\*startfile_prefix_spec:/{n;s@.*@/usr/lib/ @}' \
Before
*startfile_prefix_spec:

After
*startfile_prefix_spec:
/usr/lib/ 

-e '/\*cpp:/{n;s@$@ -isystem /usr/include@}' >
Before
%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}

After
%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT} -isystem /usr/include
check out the change is successfully.
cd /tmp


echo 'int main(){}' > dummy.c
gcc dummy.c -v -Wl,--verbose &> dummy.log
readelf -l a.out | grep ': /lib'
root:/tmp# readelf -l a.out | grep ': /lib'
      [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
Note that /lib64 is now the prefix of our dynamic linker.
There are 5 item need to be checked.
1
Grep the dummy.log file to check some info.
Now make sure that we’re setup to use the correct startfiles:
root:/tmp# grep -o '/usr/lib.*/crt[1in].*succeeded' dummy.log
/usr/lib/../lib64/crt1.o succeeded
/usr/lib/../lib64/crti.o succeeded
/usr/lib/../lib64/crtn.o succeeded
2
Verify that the compiler is searching for the correct header files:
root:/tmp# grep -B1 '^ /usr/include' dummy.log
#include <...> search starts here:
 /usr/include
3
The new linker is being used with the correct search paths:
root:/tmp# grep 'SEARCH.*/usr/lib' dummy.log |sed 's|; |\n|g'
SEARCH_DIR("=/tools/x86_64-unknown-linux-gnu/lib64")
SEARCH_DIR("/usr/lib")    <---- important
SEARCH_DIR("/lib")        <---- important
SEARCH_DIR("=/tools/x86_64-unknown-linux-gnu/lib");
4
make sure that we’re using the correct libc:
root:/tmp# grep "/lib.*/libc.so.6 " dummy.log
attempt to open /lib64/libc.so.6 succeeded
5
make sure GCC is using the correct dynamic linker:
root:/tmp# grep found dummy.log
found ld-linux-x86-64.so.2 at /lib64/ld-linux-x86-64.so.2
If everything is no problem then go to next chapter.

6.11. Zlib-1.2.8

cd /home

tar xvf /sources/zlib-1.2.8.tar.xz -C .
cd zlib-1.2.8/
./configure --prefix=/usr
make
make install
  1. The shared library needs to be moved to /lib
  2. The so file in /usr/lib will need to be recreated.
mv -v /usr/lib/libz.so.* /lib

root:/# ln -sfv /lib/$(readlink /usr/lib/libz.so) /usr/lib/libz.so
'/usr/lib/libz.so' -> '/lib/libz.so.1.2.8'

6.12. File-5.24

cd /home

tar xvf /sources/file-5.24.tar.gz -C .
cd file-5.24/
./configure --prefix=/usr
make
make install

6.13. Binutils-2.25.1

cd /home

tar xvf /sources/binutils-2.25.1.tar.bz2 -C .
make tooldir=/usr
make tooldir=/usr install

6.14. GMP-6.0.0a

cd /home

tar xvf /sources/gmp-6.0.0a.tar.xz -C .
cd gmp-6.0.0/
./configure --prefix=/usr    \
            --enable-cxx     \
            --disable-static \
            --docdir=/usr/share/doc/gmp-6.0.0a

make
make html
Test the results:
make check 2>&1 | tee gmp-check-log
Ensure that all 188 tests in the test suite passed
root:/home/gmp-6.0.0# awk '/tests passed/{total+=$2} ; END{print total}' gmp-check-log
188
Install the package and its documentation:
make install
make install-html

6.15. MPFR-3.1.3

cd /home

tar xvf /sources/mpfr-3.1.3.tar.xz -C .
cd mpfr-3.1.3/
patch -Np1 -i /sources/mpfr-3.1.3-upstream_fixes-1.patch

./configure --prefix=/usr        \
            --disable-static     \
            --enable-thread-safe \
            --docdir=/usr/share/doc/mpfr-3.1.3

make
make html
make check

==========================================
Testsuite summary for MPFR 3.1.3
==========================================
# TOTAL: 160
# PASS:  159
# SKIP:  1
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
===========================================
make install
make install-html

6.16. MPC-1.0.3

cd /home

tar xvf /sources/mpc-1.0.3.tar.gz -C .

./configure --prefix=/usr    \
            --disable-static \
            --docdir=/usr/share/doc/mpc-1.0.3

make
make html
To test the results, issue:
make check

============================================================================
Testsuite summary for mpc 1.0.3
============================================================================
# TOTAL: 64
# PASS:  64
# SKIP:  0
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
===========================================
Install the package and its documentation:
make install
make install-html

6.17. GCC-5.2.0

cd /home

tar xvf /sources/gcc-5.2.0.tar.bz2 -C .

mkdir -v ../gcc-build
cd ../gcc-build


SED=sed                       \
../gcc-5.2.0/configure        \
     --prefix=/usr            \
     --enable-languages=c,c++ \
     --disable-multilib       \
     --disable-bootstrap      \
     --with-system-zlib

make
make install
Some packages expect the C preprocessor to be installed in the /lib directory.
ln -sv /usr/bin/cpp /lib
Many packages use the name cc to call the C compiler.
ln -sv gcc /usr/bin/cc
compatibility symlink to enable building programs with Link Time Optimization (LTO):
install -v -dm755 /usr/lib/bfd-plugins
ln -sfv /usr/libexec/gcc/$(gcc -dumpmachine)/5.2.0/liblto_plugin.so /usr/lib/bfd-plugins/
Now that our final toolchain is in place, ensure that compiling and linking will work as expected.
echo 'int main(){}' > dummy.c
cc dummy.c -v -Wl,--verbose &> dummy.log
readelf -l a.out | grep ': /lib'

root:/tmp# readelf -l a.out | grep ': /lib'
      [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
There are 5 item to verify that compiling and linking will work as expected.
1. Test Startfiles
Now make sure that we’re setup to use the correct startfiles:
root:/tmp# grep -o '/usr/lib.*/crt[1in].*succeeded' dummy.log
/usr/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/../../../../lib64/crt1.o succeeded
/usr/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/../../../../lib64/crti.o succeeded
/usr/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/../../../../lib64/crtn.o succeeded
  1. Test Header file
    Verify that the compiler is searching for the correct header files:
root:/tmp# grep -B4 '^ /usr/include' dummy.log
#include <...> search starts here:
 /usr/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/include
 /usr/local/include
 /usr/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/include-fixed
 /usr/include
  1. Test Linker
    New linker is being used with the correct search paths:
root:/tmp# grep 'SEARCH.*/usr/lib' dummy.log |sed 's|; |\n|g'
SEARCH_DIR("/usr/x86_64-unknown-linux-gnu/lib64")
SEARCH_DIR("/usr/local/lib64")
SEARCH_DIR("/lib64")
SEARCH_DIR("/usr/lib64")
SEARCH_DIR("/usr/x86_64-unknown-linux-gnu/lib")
SEARCH_DIR("/usr/local/lib")
SEARCH_DIR("/lib")
SEARCH_DIR("/usr/lib");
  1. Test Libc
    Make sure that we’re using the correct libc:
root:/tmp# grep "/lib.*/libc.so.6 " dummy.log
attempt to open /lib64/libc.so.6 succeeded
  1. Test Dynamic Linker
    make sure GCC is using the correct dynamic linker:
root:/tmp# grep found dummy.log
found ld-linux-x86-64.so.2 at /lib64/ld-linux-x86-64.so.2
move a misplaced file:
root:/tmp# mkdir -pv /usr/share/gdb/auto-load/usr/lib
mkdir: created directory '/usr/share/gdb'
mkdir: created directory '/usr/share/gdb/auto-load'
mkdir: created directory '/usr/share/gdb/auto-load/usr'
mkdir: created directory '/usr/share/gdb/auto-load/usr/lib'
root:/tmp# mv -v /usr/lib/*gdb.py /usr/share/gdb/auto-load/usr/lib
'/usr/lib/libstdc++.so.6.0.21-gdb.py' -> '/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.21-gdb.py'

6.18. Bzip2-1.0.6

tar xvf /sources/bzip2-1.0.6.tar.gz -C .
cd bzip2-1.0.6/

patch -Np1 -i /sources/bzip2-1.0.6-install_docs-1.patch
sed -i 's@\(ln -s -f \)$(PREFIX)/bin/@\1@' Makefile
Before
ln -s -f $(PREFIX)/bin/bzgrep $(PREFIX)/bin/bzegrep

After
ln -s -f bzgrep $(PREFIX)/bin/bzegrep
sed -i "s@(PREFIX)/man@(PREFIX)/share/man@g" Makefile
Before
    if ( test ! -d $(PREFIX)/man ) ; then mkdir -p $(PREFIX)/man ; fi
After
    if ( test ! -d $(PREFIX)/share/man ) ; then mkdir -p $(PREFIX)/share/man ; fi
Bzip2 for compilation with:
make -f Makefile-libbz2_so
make clean
make
make PREFIX=/usr install
Install the shared bzip2 binary into the /bin directory
cp -v bzip2-shared /bin/bzip2
cp -av libbz2.so* /lib
ln -sv ../../lib/libbz2.so.1.0 /usr/lib/libbz2.so (when under /home/bzip2-1.0.6 )
rm -v /usr/bin/{bunzip2,bzcat,bzip2}
ln -sv bzip2 /bin/bunzip2
ln -sv bzip2 /bin/bzcat

6.19. Pkg-config-0.28

tar xvf /sources/pkg-config-0.28.tar.gz -C .
cd pkg-config-0.28/

./configure --prefix=/usr        \
            --with-internal-glib \
            --disable-host-tool  \
            --docdir=/usr/share/doc/pkg-config-0.28

make
make install

6.20. Ncurses-6.0

Don’t install a static library that is not handled by configure:
sed -i '/LIBTOOL_INSTALL/d' c++/Makefile.in
tar xvf /sources/ncurses-6.0.tar.gz -C .
cd ncurses-6.0/

./configure --prefix=/usr           \
            --mandir=/usr/share/man \
            --with-shared           \
            --without-debug         \
            --without-normal        \
            --enable-pc-files       \
            --enable-widec

make
make install
Move the shared libraries to the /lib directory.
mv -v /usr/lib/libncursesw.so.6* /lib
ln -sfv ../../lib/$(readlink /usr/lib/libncursesw.so) /usr/lib/libncursesw.so
Many applications still expect the linker to be able to find non-wide-character Ncurses libraries.
root:/home/ncurses-6.0# for lib in ncurses form panel menu ; do
>     rm -vf                    /usr/lib/lib${lib}.so
>     echo "INPUT(-l${lib}w)" > /usr/lib/lib${lib}.so
>     ln -sfv ${lib}w.pc        /usr/lib/pkgconfig/${lib}.pc
> done
'/usr/lib/pkgconfig/ncurses.pc' -> 'ncursesw.pc'
'/usr/lib/pkgconfig/form.pc' -> 'formw.pc'
'/usr/lib/pkgconfig/panel.pc' -> 'panelw.pc'
'/usr/lib/pkgconfig/menu.pc' -> 'menuw.pc'
Option: install the Ncurses documentation:
mkdir -v       /usr/share/doc/ncurses-6.0
cp -v -R doc/* /usr/share/doc/ncurses-6.0

6.21. Attr-2.4.47

tar xvf /sources/attr-2.4.47.src.tar.gz -C .
cd attr-2.4.47
sed -i -e 's|/@pkg_name@|&-@pkg_version@|' include/builddefs.in
Before
PKG_DOC_DIR = @datadir@/doc/@pkg_name@

After
PKG_DOC_DIR = @datadir@/doc/@pkg_name@-@pkg_version@
sed -i -e "/SUBDIRS/s|man2||" man/Makefile
Before
SUBDIRS = man1 man2 man3 man5

After
SUBDIRS = man1  man3 man5
./configure --prefix=/usr \
            --bindir=/bin \
            --disable-static

make 
make install install-dev install-lib
chmod -v 755 /usr/lib/libattr.so
The shared library needs to be moved to /lib
mv -v /usr/lib/libattr.so.* /lib
ln -sfv ../../lib/$(readlink /usr/lib/libattr.so) /usr/lib/libattr.so (under /home/attr-2.4.47)

6.22. Acl-2.2.52

tar xvf /sources/acl-2.2.52.src.tar.gz -C .

sed -i -e 's|/@pkg_name@|&-@pkg_version@|' include/builddefs.in
sed -i "s:| sed.*::g" test/{sbits-restore,cp,misc}.test
Before
    $ ls -dl d | awk '{print $1}' | sed 's/\.$//g'

After
    $ ls -dl d | awk '{print $1}' 
Additionally, fix a bug that causes getfacl -e to segfault on overly long group name
Before (empty)

After (Add following code)
if (x > (TABS-1)) x = (TABS-1);
./configure --prefix=/usr    \
            --bindir=/bin    \
            --disable-static \
            --libexecdir=/usr/lib

make

make install install-dev install-lib
chmod -v 755 /usr/lib/libacl.so
The shared library needs to be moved to /lib,
mv -v /usr/lib/libacl.so.* /lib
ln -sfv ../../lib/$(readlink /usr/lib/libacl.so) /usr/lib/libacl.so

6.23. Libcap-2.24

tar xvf /sources/libcap-2.24.tar.xz -C .
cd libcap-2.24/

sed -i '/install.*STALIBNAME/d' libcap/Makefile

make

make RAISE_SETFCAP=no prefix=/usr install
chmod -v 755 /usr/lib/libcap.so

mv -v /usr/lib/libcap.so.* /lib
ln -sfv ../../lib/$(readlink /usr/lib/libcap.so) /usr/lib/libcap.so

6.24. Sed-4.2.2

tar xvf /sources/sed-4.2.2.tar.bz2 -C .
cd sed-4.2.2/

./configure --prefix=/usr    \
            --bindir=/bin    \
            --htmldir=/usr/share/doc/sed-4.2.2

make
make html


make install
make -C doc install-html

6.25. Shadow-4.2.1

tar xvf /sources/shadow-4.2.1.tar.xz -C .
cd shadow-4.2.1/
Disable the installation of the groups program and its man pages
sed -i 's/groups$(EXEEXT) //' src/Makefile.in
find man -name Makefile.in -exec sed -i 's/groups\.1 / /' {} \;

sed -i -e 's@#ENCRYPT_METHOD DES@ENCRYPT_METHOD SHA512@' \
       -e 's@/var/spool/mail@/var/mail@' etc/login.defs
Make a minor change to make the default useradd consistent with the LFS groups file
sed -i 's/1000/999/' etc/useradd
./configure --sysconfdir=/etc    \
            --with-group-name-max-length=32
make 
make install
mv -v /usr/bin/passwd /bin
Configuring Shadow
To enable shadowed passwords
pwconv
To enable shadowed group passwords
grpconv
mailbox files are not created
sed -i 's/yes/no/' /etc/default/useradd
Setting the root password
Choose a password for user root and set it by running
passwd root
Q:
Changing password for root
Enter the new password (minimum of 5 characters)
Please use a combination of upper and lower case letters and numbers.
Bad password: too short.  
Warning: weak password (enter it again to use it anyway).
passwd: password changed.

6.26. Psmisc-22.21

tar xvf /sources/psmisc-22.21.tar.gz -C .
cd psmisc-22.21/

./configure --prefix=/usr

make 
make install

Finally, move the killall and fuser programs to the location specified by the FHS
mv -v /usr/bin/fuser   /bin
mv -v /usr/bin/killall /bin

Reference:

0 意見:

張貼留言