跟着我来一起编译lfs(四) 构建LFS系统

现在开始建立LFS系统,也就是说现在真正开始了解Linux系统。

让我们一步一步来构建,看看每个目录到底放的是什么?有什么用呢?平时使用的命令是干什么的?

我相信只要我们一步一步做下来,你立马就摆脱linux菜鸟阵营。

开始~~~

这里我们不用切换用户到lfs,就用root用户

第一件事

echo $LFS

/mnt/lfs

查看环境,这一步一定要看清楚!!!!!

如果不是这个结果请执行

LFS=/mnt/lfs

创建将用来挂载文件系统的目录

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

创建初始设备节点
在内核引导系统的时候,它依赖于几个设备节点,特别是 console 和 null 两个设备。

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

挂载和激活 /dev

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

挂载虚拟文件系统

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

在某些宿主机系统里,/dev/shm 是一个指向 /run/shm 的软链接。这个 /run 下的 tmpfs 文件系统已经在之前挂载了,所以在这里只需要创建一个目录。

if [ -h $LFS/dev/shm ]; then
  mkdir -pv $LFS/$(readlink $LFS/dev/shm)
fi

由于我们的新系统还没有 Udev 而且也没有被引导启动,所以通过绑定挂载宿主机系统实现

进入 Chroot 环境

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

这是你看到的是I have no name!不用怕,这个是对的,后面等/etc/passwd文件创建好了就好了。


现在准备创建 LFS 文件系统里的一些目录结构

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}

发现没有,我们建立的很多目录,再看看其他Linux系统,是不是很熟悉,其实这些都是可以改的,但是大家比较准守这种规则。


创建必需的文件和符号链接

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

为什么要创建这些链接呢?因为有些源码把路径写死在代码里了,不做链接编译不过去。

ln -sv /proc/self/mounts /etc/mtab

上面这个是历史遗留问题,我们同样加上。

现在我们命令行前面的提示是i have no name! ,之前说是缺少文件,现在我们补起来,要在/ect目录里新建两个文件,passwd和group

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
systemd-bus-proxy:x:72:72:systemd Bus Proxy:/:/bin/false
systemd-journal-gateway:x:73:73:systemd Journal Gateway:/:/bin/false
systemd-journal-remote:x:74:74:systemd Journal Remote:/:/bin/false
systemd-journal-upload:x:75:75:systemd Journal Upload:/:/bin/false
systemd-network:x:76:76:systemd Network Management:/:/bin/false
systemd-resolve:x:77:77:systemd Resolver:/:/bin/false
systemd-timesync:x:78:78:systemd Time Synchronization:/:/bin/false
systemd-coredump:x:79:79:systemd Core Dumper:/:/bin/false
nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
EOF
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:
systemd-bus-proxy:x:72:
systemd-journal-gateway:x:73:
systemd-journal-remote:x:74:
systemd-journal-upload:x:75:
systemd-network:x:76:
systemd-resolve:x:77:
systemd-timesync:x:78:
systemd-coredump:x:79:
nogroup:x:99:
users:x:999:
EOF

打开一个新的shell看看

exec /tools/bin/bash --login +h

是不是变了?


接下来初始化日志文件,如果没有这些文件日志是不会记录的。

touch /var/log/{btmp,lastlog,faillog,wtmp}
chgrp -v utmp /var/log/lastlog
chmod -v 664  /var/log/lastlog
chmod -v 600  /var/log/btmp

/var/log/wtmp 会记录所有的登录和登出
/var/log/btmp 会记录失败的登录尝试
/var/log/lastlog 最后一次登录信息
/var/log/faillog 会记录错误的登录


又要开始编译源码了

Linux API Headers

cd /sources
xz -d linux-4.7.2.tar.xz  (如果你是从我分享的网盘下的源码,可能已经解压成tar了,报错就忽略)
tar xf linux-4.7.2.tar
cd linux-4.7.2
make mrproper
make INSTALL_HDR_PATH=dest headers_install
find dest/include \( -name .install -o -name ..install.cmd \) -delete
cp -rv dest/include/* /usr/include

Man-pages

cd /sources
xz -d man-pages-4.07.tar.xz
tar xf man-pages-4.07.tar
cd man-pages-4.07
make install

Glibc

cd /sources
xz -d glibc-2.24.tar.xz  (如果你是从我分享的网盘下的源码,可能已经解压成tar了,报错就忽略)
tar xf glibc-2.24.tar
cd glibc-2.24
patch -Np1 -i ../glibc-2.24-fhs-1.patch
mkdir -v build
cd build
../configure --prefix=/usr          \
             --enable-kernel=2.6.32 \
             --enable-obsolete-rpc
make
make check
touch /etc/ld.so.conf
make install

为 nscd 安装配置文件并创建运行时目录

cp -v ../nscd/nscd.conf /etc/nscd.conf
mkdir -pv /var/cache/nscd
install -v -Dm644 ../nscd/nscd.tmpfiles /usr/lib/tmpfiles.d/nscd.conf
install -v -Dm644 ../nscd/nscd.service /lib/systemd/system/nscd.service

安装语言环境

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

配置 Glibc

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

安装时区

tar -xf ../../tzdata2016f.tar.gz
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

选择时区

tzselect
ln -sfv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

配置动态库加载器

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

EOF

调整工具链

备份

mv -v /tools/bin/{ld,ld-old}
mv -v /tools/$(uname -m)-pc-linux-gnu/bin/{ld,ld-old}
mv -v /tools/bin/{ld-new,ld}
ln -sv /tools/bin/ld /tools/$(uname -m)-pc-linux-gnu/bin/ld

修改 GCC 参数文件

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

测试

cd /root
echo 'int main(){}' > dummy.c
cc dummy.c -v -Wl,--verbose &> dummy.log
readelf -l a.out | grep ': /lib'

应该显示下面的内容
[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]

查看

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

grep -B1 '^ /usr/include' dummy.log

会显示下面内容
#include <...> search starts here:
/usr/include

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

会有显示下面内容
SEARCH_DIR(“/usr/lib”)
SEARCH_DIR(“/lib”)

grep "/lib.*/libc.so.6 " dummy.log

会显示下面内容
attempt to open /lib/libc.so.6 succeeded

grep found dummy.log

会显示下面内容
found ld-linux-x86-64.so.2 at /lib64/ld-linux-x86-64.so.2


Zlib

cd /sources
tar zxf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure --prefix=/usr
make
make check
make install
mv -v /usr/lib/libz.so.* /lib
ln -sfv ../../lib/$(readlink /usr/lib/libz.so) /usr/lib/libz.so

File

cd /sources
tar zxf file-5.28.tar.gz
cd file-5.28
./configure --prefix=/usr
make
make check
make install

Binutils

cd /sources
tar jxf binutils-2.27.tar.bz2
cd binutils-2.27
expect -c "spawn ls"

会显示
spawn ls
如果显示其他的都是错误的

mkdir -v build
cd build
../configure --prefix=/usr   \
             --enable-shared \
             --disable-werror
make tooldir=/usr
make -k check
make tooldir=/usr install

GMP

cd /sources
xz -d gmp-6.1.1.tar.xz
tar xf gmp-6.1.1.tar
cd gmp-6.1.1

编译软件包并生成 HTML 文档

make
make html

查看结果及测试

make check 2>&1 | tee gmp-check-log
awk '/# PASS:/{total+=$3} ; END{print total}' gmp-check-log

应该有190

没问题就安装

make install
make install-html

MPFR

cd /sources
xz -d zxf mpfr-3.1.4.tar.xz
tar xf mpfr-3.1.4.tar
cd mpfr-3.1.4
./configure --prefix=/usr        \
            --disable-static     \
            --enable-thread-safe \
            --docdir=/usr/share/doc/mpfr-3.1.4
make
make html
make check
make install
make install-html

MPC

cd /sources
tar zxf mpc-1.0.3.tar.gz
cd mpc-1.0.3
./configure --prefix=/usr    \
            --disable-static \
            --docdir=/usr/share/doc/mpc-1.0.3
make
make html
make check
make install
make install-html

GCC

cd /sources
tar jxf gcc-6.2.0.tar.bz2
cd gcc-6.2.0
mkdir -v build
cd build
SED=sed                               \
../configure --prefix=/usr            \
             --enable-languages=c,c++ \
             --disable-multilib       \
             --disable-bootstrap      \
             --with-system-zlib
make
ulimit -s 32768
make -k check
../contrib/test_summary
make install
ln -sv ../usr/bin/cpp /lib
ln -sv gcc /usr/bin/cc
ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/6.2.0/liblto_plugin.so \
        /usr/lib/bfd-plugins/

测试

echo 'int main(){}' > dummy.c
cc dummy.c -v -Wl,--verbose &> dummy.log
readelf -l a.out | grep ': /lib'

显示如下
[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]

grep -o '/usr/lib.*/crt[1in].*succeeded' dummy.log

显示如下
/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.0/../../../../lib64/crt1.o succeeded
/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.0/../../../../lib64/crti.o succeeded
/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.0/../../../../lib64/crtn.o succeeded

grep -B4 '^ /usr/include' dummy.log

显示如下
#include <...> search starts here:
/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.0/include
/usr/local/include
/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.0/include-fixed
/usr/include

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

显示如下
SEARCH_DIR(“/usr/x86_64-pc-linux-gnu/lib64”)
SEARCH_DIR(“/usr/local/lib64”)
SEARCH_DIR(“/lib64”)
SEARCH_DIR(“/usr/lib64”)
SEARCH_DIR(“/usr/x86_64-pc-linux-gnu/lib”)
SEARCH_DIR(“/usr/local/lib”)
SEARCH_DIR(“/lib”)
SEARCH_DIR(“/usr/lib”);

grep "/lib.*/libc.so.6 " dummy.log

显示如下
attempt to open /lib64/libc.so.6 succeeded

grep found dummy.log

显示如下
found ld-linux-x86-64.so.2 at /lib64/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

Bzip2

cd /sources
tar zxf bzip2-1.0.6.tar.gz
cd bzip2-1.0.6
patch -Np1 -i ../bzip2-1.0.6-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 -v bzip2-shared /bin/bzip2
cp -av libbz2.so* /lib
ln -sv ../../lib/libbz2.so.1.0 /usr/lib/libbz2.so
rm -v /usr/bin/{bunzip2,bzcat,bzip2}
ln -sv bzip2 /bin/bunzip2
ln -sv bzip2 /bin/bzcat

Pkg-config

cd /sources
tar zxf pkg-config-0.29.1.tar.gz
cd pkg-config-0.29.1
./configure --prefix=/usr              \
            --with-internal-glib       \
            --disable-compile-warnings \
            --disable-host-tool        \
            --docdir=/usr/share/doc/pkg-config-0.29.1
make
make check
make install

Ncurses

cd /sources
tar zxf ncurses-6.0.tar.gz
cd ncurses-6.0
sed -i '/LIBTOOL_INSTALL/d' c++/Makefile.in
./configure --prefix=/usr           \
            --mandir=/usr/share/man \
            --with-shared           \
            --without-debug         \
            --without-normal        \
            --enable-pc-files       \
            --enable-widec
make
make install
mv -v /usr/lib/libncursesw.so.6* /lib
ln -sfv ../../lib/$(readlink /usr/lib/libncursesw.so) /usr/lib/libncursesw.so
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
rm -vf                     /usr/lib/libcursesw.so
echo "INPUT(-lncursesw)" > /usr/lib/libcursesw.so
ln -sfv libncurses.so      /usr/lib/libcurses.so
mkdir -v       /usr/share/doc/ncurses-6.0
cp -v -R doc/* /usr/share/doc/ncurses-6.0
make distclean
./configure --prefix=/usr    \
            --with-shared    \
            --without-normal \
            --without-debug  \
            --without-cxx-binding \
            --with-abi-version=5
make sources libs
cp -av lib/lib*.so.5* /usr/lib

Attr

cd /sources
tar zxf attr-2.4.47.src.tar.gz
cd attr-2.4.47
sed -i -e 's|/@pkg_name@|&-@pkg_version@|' include/builddefs.in
sed -i -e "/SUBDIRS/s|man[25]||g" man/Makefile
./configure --prefix=/usr \
            --disable-static
make
make -j1 tests root-tests
make install install-dev install-lib
chmod -v 755 /usr/lib/libattr.so
mv -v /usr/lib/libattr.so.* /lib
ln -sfv ../../lib/$(readlink /usr/lib/libattr.so) /usr/lib/libattr.so

Acl

cd /sources
tar zxf acl-2.2.52.src.tar.gz
cd acl-2.2.52
sed -i -e 's|/@pkg_name@|&-@pkg_version@|' include/builddefs.in
sed -i "s:| sed.*::g" test/{sbits-restore,cp,misc}.test
sed -i -e "/TABS-1;/a if (x > (TABS-1)) x = (TABS-1);" \
    libacl/__acl_to_any_text.c
./configure --prefix=/usr    \
            --disable-static \
            --libexecdir=/usr/lib
make
make install install-dev install-lib
chmod -v 755 /usr/lib/libacl.so
mv -v /usr/lib/libacl.so.* /lib
ln -sfv ../../lib/$(readlink /usr/lib/libacl.so) /usr/lib/libacl.so

Libcap

cd /sources
xz -d libcap-2.25.tar.xz
tar xf libcap-2.25.tar
cd libcap-2.25
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

sed

cd /sources
tar jxf sed-4.2.2.tar.bz2
cd sed-4.2.2
./configure --prefix=/usr --bindir=/bin --htmldir=/usr/share/doc/sed-4.2.2
make
make html
make check
make install
make -C doc install-html

Shadow

cd /sources
xz -d shadow-4.2.1.tar.xz
tar xf shadow-4.2.1.tar
cd shadow-4.2.1
sed -i 's/groups$(EXEEXT) //' src/Makefile.in
find man -name Makefile.in -exec sed -i 's/groups\.1 / /'   {} \;
find man -name Makefile.in -exec sed -i 's/getspnam\.3 / /' {} \;
find man -name Makefile.in -exec sed -i 's/passwd\.5 / /'   {} \;
sed -i -e 's@#ENCRYPT_METHOD DES@ENCRYPT_METHOD SHA512@' \
       -e 's@/var/spool/mail@/var/mail@' etc/login.defs
sed -i 's@DICTPATH.*@DICTPATH\t/lib/cracklib/pw_dict@' etc/login.defs
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
sed -i 's/yes/no/' /etc/default/useradd
passwd root

Psmisc

cd /sources
tar zxf psmisc-22.21.tar.gz
cd psmisc-22.21
./configure --prefix=/usr
make
make install
mv -v /usr/bin/fuser   /bin
mv -v /usr/bin/killall /bin

Iana-Etc

cd /sources
tar jxf iana-etc-2.30.tar.bz2
cd iana-etc-2.30
make
make install

M4

cd /sources
tar xf m4-1.4.17.tar
cd m4-1.4.17
./configure --prefix=/usr
make
make check
make install

Bison

cd /sources
xz -d bison-3.0.4.tar.xz
tar xf bison-3.0.4.tar
cd bison-3.0.4
./configure --prefix=/usr --docdir=/usr/share/doc/bison-3.0.4
make
make install

Flex

cd /sources
xz -d flex-2.6.1.tar.xz
tar xf flex-2.6.1.tar
cd flex-2.6.1
./configure --prefix=/usr --docdir=/usr/share/doc/flex-2.6.1
make
make check
make install
ln -sv flex /usr/bin/lex

Grep

cd /sources
tar xf grep-2.25.tar
cd grep-2.25
./configure --prefix=/usr --bindir=/bin
make
make check
make install

Readline

cd /sources
tar zxf readline-6.3.tar.gz
cd readline-6.3
patch -Np1 -i ../readline-6.3-upstream_fixes-3.patch
sed -i '/MV.*old/d' Makefile.in
sed -i '/{OLDSUFF}/c:' support/shlib-install
./configure --prefix=/usr    \
            --disable-static \
            --docdir=/usr/share/doc/readline-6.3
make SHLIB_LIBS=-lncurses
make SHLIB_LIBS=-lncurses install
mv -v /usr/lib/lib{readline,history}.so.* /lib
ln -sfv ../../lib/$(readlink /usr/lib/libreadline.so) /usr/lib/libreadline.so
ln -sfv ../../lib/$(readlink /usr/lib/libhistory.so ) /usr/lib/libhistory.so
install -v -m644 doc/*.{ps,pdf,html,dvi} /usr/share/doc/readline-6.3

Bash

cd /sources
tar zxf bash-4.3.30.tar.gz
cd bash-4.3.30
patch -Np1 -i ../bash-4.3.30-upstream_fixes-3.patch
./configure --prefix=/usr                       \
            --docdir=/usr/share/doc/bash-4.3.30 \
            --without-bash-malloc               \
            --with-installed-readline
make
chown -Rv nobody .
su nobody -s /bin/bash -c "PATH=$PATH make tests"
make install
mv -vf /usr/bin/bash /bin
exec /bin/bash --login +h

Bc

cd /sources
tar jxf bc-1.06.95.tar.bz2
cd bc-1.06.95
patch -Np1 -i ../bc-1.06.95-memory_leak-1.patch
./configure --prefix=/usr           \
            --with-readline         \
            --mandir=/usr/share/man \
            --infodir=/usr/share/info
make
echo "quit" | ./bc/bc -l Test/checklib.b
make install

Libtool

cd /sources
xz -d libtool-2.4.6.tar.xz
tar xf libtool-2.4.6.tar
cd libtool-2.4.6
./configure --prefix=/usr
make
make check
make install

GDBM

cd /sources
tar zxf gdbm-1.12.tar.gz
cd gdbm-1.12
./configure --prefix=/usr \
            --disable-static \
            --enable-libgdbm-compat
make
make check
make install

Gperf

cd /sources
tar zxf gperf-3.0.4.tar.gz
cd gperf-3.0.4
./configure --prefix=/usr --docdir=/usr/share/doc/gperf-3.0.4
make
make -j1 check
make install

Expat

cd /sources
tar jxf expat-2.2.0.tar.bz2
cd expat-2.2.0
./configure --prefix=/usr --disable-static
make
make check
make install
install -v -dm755 /usr/share/doc/expat-2.2.0
install -v -m644 doc/*.{html,png,css} /usr/share/doc/expat-2.2.0

Inetutils

cd /sources
xz -d inetutils-1.9.4.tar.xz
tar xf inetutils-1.9.4.tar
cd inetutils-1.9.4
./configure --prefix=/usr        \
            --localstatedir=/var \
            --disable-logger     \
            --disable-whois      \
            --disable-rcp        \
            --disable-rexec      \
            --disable-rlogin     \
            --disable-rsh        \
            --disable-servers
make
make check
make install
mv -v /usr/bin/{hostname,ping,ping6,traceroute} /bin
mv -v /usr/bin/ifconfig /sbin

Perl

cd /sources
tar jxf perl-5.24.0.tar.bz2
cd perl-5.24.0
echo "127.0.0.1 localhost $(hostname)" > /etc/hosts
export BUILD_ZLIB=False
export BUILD_BZIP2=0
sh Configure -des -Dprefix=/usr                 \
                  -Dvendorprefix=/usr           \
                  -Dman1dir=/usr/share/man/man1 \
                  -Dman3dir=/usr/share/man/man3 \
                  -Dpager="/usr/bin/less -isR"  \
                  -Duseshrplib
make
make -k test
make install
unset BUILD_ZLIB BUILD_BZIP2

XML::Parser

cd /sources
tar zxf XML-Parser-2.44.tar.gz
cd XML-Parser-2.44
perl Makefile.PL
make
make test
make install

Intltool

cd /sources
tar zxf intltool-0.51.0.tar.gz
cd intltool-0.51.0
sed -i 's:\\\${:\\\$\\{:' intltool-update.in
./configure --prefix=/usr
make
make check
make install
install -v -Dm644 doc/I18N-HOWTO /usr/share/doc/intltool-0.51.0/I18N-HOWTO

Autoconf

cd /sources
xz -d autoconf-2.69.tar.xz
tar xf autoconf-2.69.tar
cd autoconf-2.69
./configure --prefix=/usr
make
make check
make install

Automake

cd /sources
xz -d automake-1.15.tar.xz
tar xf automake-1.15.tar
cd automake-1.15
sed -i 's:/\\\${:/\\\$\\{:' bin/automake.in
./configure --prefix=/usr --docdir=/usr/share/doc/automake-1.15
make
sed -i "s:./configure:LEXLIB=/usr/lib/libfl.a &:" t/lex-{clean,depend}-cxx.sh
make -j4 check
make install

Xz

cd /sources
tar xf xz-5.2.2.tar
cd xz-5.2.2
sed -e '/mf\.buffer = NULL/a next->coder->mf.size = 0;' \
     -i src/liblzma/lz/lz_encoder.c
./configure --prefix=/usr    \
            --disable-static \
            --docdir=/usr/share/doc/xz-5.2.2
make
make check
make install
mv -v   /usr/bin/{lzma,unlzma,lzcat,xz,unxz,xzcat} /bin
mv -v /usr/lib/liblzma.so.* /lib
ln -svf ../../lib/$(readlink /usr/lib/liblzma.so) /usr/lib/liblzma.so

Kmod

cd /sources
xz -d kmod-23.tar.xz
tar xf kmod-23.tar
cd kmod-23
./configure --prefix=/usr          \
            --bindir=/bin          \
            --sysconfdir=/etc      \
            --with-rootlibdir=/lib \
            --with-xz              \
            --with-zlib
make
make install
for target in depmod insmod lsmod modinfo modprobe rmmod; do
  ln -sfv ../bin/kmod /sbin/$target
done
ln -sfv kmod /bin/lsmod

Gettext

cd /sources
tar xf gettext-0.19.8.1.tar
cd gettext-0.19.8.1
./configure --prefix=/usr    \
            --disable-static \
            --docdir=/usr/share/doc/gettext-0.19.8.1
make
make check
make install
chmod -v 0755 /usr/lib/preloadable_libintl.so

Systemd

cd /sources
xz -d systemd-231.tar.xz
tar xf systemd-231.tar
cd systemd-231
sed -i "s:blkid/::" $(grep -rl "blkid/blkid.h")
sed -e 's@test/udev-test.pl @@'  \
    -e 's@test-copy$(EXEEXT) @@' \
    -i Makefile.in
cat > config.cache << "EOF"
KILL=/bin/kill
MOUNT_PATH=/bin/mount
UMOUNT_PATH=/bin/umount
HAVE_BLKID=1
BLKID_LIBS="-lblkid"
BLKID_CFLAGS="-I/tools/include/blkid"
HAVE_LIBMOUNT=1
MOUNT_LIBS="-lmount"
MOUNT_CFLAGS="-I/tools/include/libmount"
cc_cv_CFLAGS__flto=no
XSLTPROC="/usr/bin/xsltproc"
EOF
./configure --prefix=/usr            \
            --sysconfdir=/etc        \
            --localstatedir=/var     \
            --config-cache           \
            --with-rootprefix=       \
            --with-rootlibdir=/lib   \
            --enable-split-usr       \
            --disable-firstboot      \
            --disable-ldconfig       \
            --disable-sysusers       \
            --without-python         \
            --with-default-dnssec=no \
            --docdir=/usr/share/doc/systemd-231
make LIBRARY_PATH=/tools/lib
make LD_LIBRARY_PATH=/tools/lib install
mv -v /usr/lib/libnss_{myhostname,mymachines,resolve}.so.2 /lib
rm -rfv /usr/lib/rpm
for tool in runlevel reboot shutdown poweroff halt telinit; do
     ln -sfv ../bin/systemctl /sbin/${tool}
done
ln -sfv ../lib/systemd/systemd /sbin/init
systemd-machine-id-setup
rm -fv /etc/resolv.conf
ln -s ../lib/systemd/resolv.conf /etc/resolv.conf
sed -i "s:minix:ext4:g" src/test/test-path-util.c
make LD_LIBRARY_PATH=/tools/lib -k check

Procps

cd /sources
xz -d procps-ng-3.3.12.tar.xz
tar xf procps-ng-3.3.12.tar
cd procps-ng-3.3.12
./configure --prefix=/usr                            \
            --exec-prefix=                           \
            --libdir=/usr/lib                        \
            --docdir=/usr/share/doc/procps-ng-3.3.12 \
            --disable-static                         \
            --disable-kill                           \
            --with-systemd
make
sed -i -r 's|(pmap_initname)\\\$|\1|' testsuite/pmap.test/pmap.exp
make check
make install
mv -v /usr/lib/libprocps.so.* /lib
ln -sfv ../../lib/$(readlink /usr/lib/libprocps.so) /usr/lib/libprocps.so

E2fsprogs

cd /sources
tar zxf e2fsprogs-1.43.1.tar.gz
cd e2fsprogs-1.43.1
sed -i -e 's:\[\.-\]::' tests/filter.sed
mkdir -v build
cd build

LIBS=-L/tools/lib \

CFLAGS=-I/tools/include              \
PKG_CONFIG_PATH=/tools/lib/pkgconfig \
../configure --prefix=/usr           \
             --bindir=/bin           \
             --with-root-prefix=""   \
             --enable-elf-shlibs     \
             --disable-libblkid      \
             --disable-libuuid       \
             --disable-uuidd         \
             --disable-fsck
make
ln -sfv /tools/lib/lib{blk,uu}id.so.1 lib
make LD_LIBRARY_PATH=/tools/lib check
make install
make install-libs
chmod -v u+w /usr/lib/{libcom_err,libe2p,libext2fs,libss}.a
gunzip -v /usr/share/info/libext2fs.info.gz
install-info --dir-file=/usr/share/info/dir /usr/share/info/libext2fs.info
makeinfo -o      doc/com_err.info ../lib/et/com_err.texinfo
install -v -m644 doc/com_err.info /usr/share/info
install-info --dir-file=/usr/share/info/dir /usr/share/info/com_err.info

Coreutils

cd /sources
tar xf coreutils-8.25.tar
cd coreutils-8.25
patch -Np1 -i ../coreutils-8.25-i18n-2.patch
FORCE_UNSAFE_CONFIGURE=1 ./configure \
            --prefix=/usr            \
            --enable-no-install-program=kill,uptime
FORCE_UNSAFE_CONFIGURE=1 make
make NON_ROOT_USERNAME=nobody check-root
echo "dummy:x:1000:nobody" >> /etc/group
chown -Rv nobody .
su nobody -s /bin/bash \
          -c "PATH=$PATH make RUN_EXPENSIVE_TESTS=yes check"
sed -i '/dummy/d' /etc/group
make install
mv -v /usr/bin/{cat,chgrp,chmod,chown,cp,date,dd,df,echo} /bin
mv -v /usr/bin/{false,ln,ls,mkdir,mknod,mv,pwd,rm} /bin
mv -v /usr/bin/{rmdir,stty,sync,true,uname} /bin
mv -v /usr/bin/chroot /usr/sbin
mv -v /usr/share/man/man1/chroot.1 /usr/share/man/man8/chroot.8
sed -i s/\"1\"/\"8\"/1 /usr/share/man/man8/chroot.8
mv -v /usr/bin/{head,sleep,nice,test,[} /bin

Diffutils

cd /sources
tar xf diffutils-3.5.tar
cd diffutils-3.5
sed -i 's:= @mkdir_p@:= /bin/mkdir -p:' po/Makefile.in.in
./configure --prefix=/usr
make
make check
make install

Gawk

cd /sources
tar xf gawk-4.1.3.tar
cd gawk-4.1.3
./configure --prefix=/usr
make
make check
make install

mkdir -v /usr/share/doc/gawk-4.1.3
cp -v doc/{awkforai.txt,*.{eps,pdf,jpg}} /usr/share/doc/gawk-4.1.3


Findutils

cd /sources
tar zxf findutils-4.6.0.tar.gz
cd findutils-4.6.0
./configure --prefix=/usr --localstatedir=/var/lib/locate
make
make check
make install
mv -v /usr/bin/find /bin
sed -i 's|find:=${BINDIR}|find:=/bin|' /usr/bin/updatedb

Groff

cd /sources
tar zxf groff-1.22.3.tar.gz
cd groff-1.22.3
PAGE=A4 ./configure --prefix=/usr
make
make install

GRUB

cd /sources
xz -d grub-2.02~beta3.tar.xz
tar xf grub-2.02~beta3.tar
cd grub-2.02~beta3
./configure --prefix=/usr          \
            --sbindir=/sbin        \
            --sysconfdir=/etc      \
            --disable-efiemu       \
            --disable-werror
make
make install

Less

cd /sources
tar zxf less-481.tar.gz
cd less-481
./configure --prefix=/usr --sysconfdir=/etc
make
make install

Gzip

cd /sources
tar xf gzip-1.8.tar
cd gzip-1.8
./configure --prefix=/usr
make
make check
make install
mv -v /usr/bin/gzip /bin

IPRoute2

cd /sources
xz -d iproute2-4.7.0.tar.xz
tar xf iproute2-4.7.0.tar
cd iproute2-4.7.0
sed -i /ARPD/d Makefile
sed -i 's/arpd.8//' man/man8/Makefile
rm -v doc/arpd.sgml
sed -i 's/m_ipt.o//' tc/Makefile
make
make DOCDIR=/usr/share/doc/iproute2-4.7.0 install

Kbd

cd /sources
xz -d kbd-2.0.3.tar.xz
tar xf kbd-2.0.3.tar
cd kbd-2.0.3
patch -Np1 -i ../kbd-2.0.3-backspace-1.patch
sed -i 's/\(RESIZECONS_PROGS=\)yes/\1no/g' configure
sed -i 's/resizecons.8 //' docs/man/man8/Makefile.in
PKG_CONFIG_PATH=/tools/lib/pkgconfig ./configure --prefix=/usr --disable-vlock
make
make check
make install
mkdir -v       /usr/share/doc/kbd-2.0.3
cp -R -v docs/doc/* /usr/share/doc/kbd-2.0.3

Libpipeline

cd /sources
tar zxf libpipeline-1.4.1.tar.gz
cd libpipeline-1.4.1
PKG_CONFIG_PATH=/tools/lib/pkgconfig ./configure --prefix=/usr
make
make check
make install

Make

cd /sources
tar jxf make-4.2.1.tar.bz2
cd make-4.2.1
./configure --prefix=/usr
make
make check
make install

Patch

cd /sources
tar xf patch-2.7.5.tar
cd patch-2.7.5
./configure --prefix=/usr
make
make check
make install

D-Bus

cd /sources
zxf dbus-1.10.10.tar.gz
cd dbus-1.10.10
 ./configure --prefix=/usr                       \
              --sysconfdir=/etc                   \
              --localstatedir=/var                \
              --disable-static                    \
              --disable-doxygen-docs              \
              --disable-xml-docs                  \
              --docdir=/usr/share/doc/dbus-1.10.10 \
              --with-console-auth-dir=/run/console
make
make install
mv -v /usr/lib/libdbus-1.so.* /lib
ln -sfv ../../lib/$(readlink /usr/lib/libdbus-1.so) /usr/lib/libdbus-1.so
ln -sfv /etc/machine-id /var/lib/dbus

Util-linux

cd /sources
tar xf util-linux-2.28.1.tar
cd util-linux-2.28.1
./configure ADJTIME_PATH=/var/lib/hwclock/adjtime   \
            --docdir=/usr/share/doc/util-linux-2.28.1 \
            --disable-chfn-chsh  \
            --disable-login      \
            --disable-nologin    \
            --disable-su         \
            --disable-setpriv    \
            --disable-runuser    \
            --disable-pylibmount \
            --disable-static     \
            --without-python     \
            --enable-libmount-force-mountinfo
make
chown -Rv nobody .
su nobody -s /bin/bash -c "PATH=$PATH make -k check"
make install

Man-DB

cd /sources
xz -d man-db-2.7.5.tar.xz
tar xf man-db-2.7.5.tar
cd man-db-2.7.5
./configure --prefix=/usr                        \
            --docdir=/usr/share/doc/man-db-2.7.5 \
            --sysconfdir=/etc                    \
            --disable-setuid                     \
            --with-browser=/usr/bin/lynx         \
            --with-vgrind=/usr/bin/vgrind        \
            --with-grap=/usr/bin/grap
make
make check
make install
sed -i "s:man root:root root:g" /usr/lib/tmpfiles.d/man-db.conf

Tar

cd /sources
tar xf tar-1.29.tar
cd tar-1.29
FORCE_UNSAFE_CONFIGURE=1  \
./configure --prefix=/usr \
            --bindir=/bin
make
make check
make install
make -C doc install-html docdir=/usr/share/doc/tar-1.29

Texinfo

cd /sources
tar xf texinfo-6.1.tar
cd texinfo-6.1
./configure --prefix=/usr --disable-static
make
make check
make install
make TEXMF=/usr/share/texmf install-tex
pushd /usr/share/info
rm -v dir
for f in *
  do install-info $f dir 2>/dev/null
done
popd

Vim

cd /sources
tar jxf vim-7.4.tar.bz2

cd vim74

echo '#define SYS_VIMRC_FILE "/etc/vimrc"' >> src/feature.h
./configure --prefix=/usr
make
make -j1 test
make install
ln -sv vim /usr/bin/vi
for L in  /usr/share/man/{,*/}man1/vim.1; do
    ln -sv vim.1 $(dirname $L)/vi.1
done
ln -sv ../vim/vim74/doc /usr/share/doc/vim-7.4
cat > /etc/vimrc << "EOF"
" Begin /etc/vimrc

set nocompatible
set backspace=2
syntax on
if (&term == "iterm") || (&term == "putty")
  set background=dark
endif

" End /etc/vimrc
EOF
vim -c ':options'

终于编译完了,很累很累,中间是不是也碰到很多错误?呵呵~~~

清理一下
先退出 保证环境没有错误

logout

重新进入

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

清理

/tools/bin/find /usr/lib -type f -name \*.a \
   -exec /tools/bin/strip --strip-debug {} ';'
/tools/bin/find /lib /usr/lib -type f -name \*.so* \
   -exec /tools/bin/strip --strip-unneeded {} ';'
/tools/bin/find /{bin,sbin} /usr/{bin,sbin,libexec} -type f \
    -exec /tools/bin/strip --strip-all {} ';'
rm -rf /tmp/*

修改进入命令

chroot "$LFS" /usr/bin/env -i              \
    HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin     \
    /bin/bash --login
rm -f /usr/lib/lib{bfd,opcodes}.a
rm -f /usr/lib/libbz2.a
rm -f /usr/lib/lib{com_err,e2p,ext2fs,ss}.a
rm -f /usr/lib/libltdl.a
rm -f /usr/lib/libfl.a
rm -f /usr/lib/libfl_pic.a
rm -f /usr/lib/libz.a

好了,这章终于结束了,搞个LOL,看个电影,等待下一章系统配置!

Leave a Reply

Your email address will not be published.