lfs-7.7学习笔记(3)构建 LFS 系统

四、构建 LFS 系统

4.1.1 创建挂载文件系统的目录

使用root用户执行:

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

4.1.2 创建初始设备节点

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

4.1.3 挂载和激活 /dev

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

4.1.4 挂载虚拟文件系统

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

4.2 进入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

这时bash的提示符是“I have no name!”

4.3 创建标准的目录树

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}

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

4.4.1 创建符号链接

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

4.4.2 创建/etc/passwd和/etc/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
nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
EOF

创建/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:
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:
nogroup:x:99:
users:x:999:
EOF

4.4.3 移除“I have no name!”

在当前shell中执行:

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

4.4.4 初始化日志文件件并设置权限:

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

4.5开始安装软件

宿主系统的/opt/lfs/sources在进入chroot环境后变为/sources,需进入该目录解压编译软件。
推荐在make完成后进行make check进行测试,我这里为节省时间,省略了这一步骤

4.5.1 安装Linux API头文件

cd /sources/linux-3.19
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

4.5.2 安装 Man-pages

tar -xf man-pages-3.79.tar.xz && cd man-pages-3.79
make install

4.5.3 安装和配置Glibc

4.5.3.1 安装Glibc

打FHS兼容性补丁:

cd /sources/glibc-2.21
patch -Np1 -i ../glibc-2.21-fhs-1.patch

修正一个影响32位系统的问题:

sed -e '/ia32/s/^/1:/' \
 -e '/SSE2/s/^1://' \
 -i sysdeps/i386/i686/multiarch/mempcpy_chk.S

准备编译:

cd ../glibc-build && rm -rf ./*
../glibc-2.21/configure \
 --prefix=/usr \
 --disable-profile \
 --enable-kernel=2.6.32 \
 --enable-obsolete-rpc

编译、测试和安装:

make && make check  #make check会有一些fail,多数是正常的
make install

为nscd建立配置文件和运行目录:


cp -v ../glibc-2.21/nscd/nscd.conf /etc/nscd.conf
mkdir -pv /var/cache/nscd

为nscd安装系统支持文件:

install -v -Dm644 ../glibc-2.21/nscd/nscd.tmpfiles  /usr/lib/tmpfiles.d/nscd.conf
install -v -Dm644 ../glibc-2.21/nscd/nscd.service  /lib/systemd/system/nscd.service

安装语言环境:
安装全部:

make localedata/install-locales

安装全部会比较久,占用空间也比较大,也可以最小安装:

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

4.5.3.2 配置Glibc

新建/etc/nsswitch.conf :

cat > /etc/nsswitch.conf << "EOF"
# Begin /etc/nsswitch.conf
passwd: files
group: files
shadow: files

: files dns myhostname
networks: files
protocols: files
services: files
ethers: files
rpc: files
# End /etc/nsswitch.conf
EOF

安装时区数据:

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

设定时区

ln -sfv /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime

4.5.3.3 配置动态库加载器

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

包含指定目录的配置文件:

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

4.5.3.4 调整工具链

让新编译的程序使用新的C语言库:

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找到正确的头文件和Glibc启动文件:

 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

这里一定要做测试,确保工具链工作正常

4.5.3.5 测试

测试动态链接库的前缀,执行已下内容:

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

确保输出中路径为/lib或/lib64开头:


[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("=/tools/x86_64-unknown-linux-gnu/lib64")
SEARCH_DIR("/usr/lib")
SEARCH_DIR("/lib")
SEARCH_DIR("=/tools/x86_64-unknown-linux-gnu/lib");

测试是否使用正确的libc,执行:

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

输出:

attempt to open /lib64/libc.so.6 succeeded

测试GCC 使用的动态链接器,执行:

found ld-linux-x86-64.so.2 at /lib64/ld-linux-x86-64.so.2


4.5.4 安装zlib

tar -xf zlib-1.2.8.tar.xz && cd zlib-1.2.8
./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

4.5.5 安装file

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

4.5.6 安装 Binutils

确保PTY工作正常:

expect -c "spawn ls"

输出为:


spawn ls

准备编译:

../binutils-2.25/configure --prefix=/usr \
 --enable-shared \
 --disable-werror

编译并安装:

make tooldir=/usr
make tooldir=/usr install

4.5.7 安装m4

先安装m4,否则按照官方教程在编译GMP时会提示没有m4

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

4.5.8安装GMP

tar -xf gmp-6.0.0a.tar.xz && cd gmp-6.0.0
./configure --prefix=/usr  --enable-cxx  --docdir=/usr/share/doc/gmp-6.0.0a
make && make html

测试:

make check 2>&1 | tee gmp-check-log
awk '/tests passed/{total+=$2} ; END{print total}' gmp-check-log

确保188个测试都是成功的

安装:

make install
make install-html

4.5.9 安装 MPFR

tar -xf mpfr-3.1.2.tar.xz && cd mpfr-3.1.2
patch -Np1 -i ../mpfr-3.1.2-upstream_fixes-3.patch
./configure --prefix=/usr  --enable-thread-safe  --docdir=/usr/share/doc/mpfr-3.1.2
make  && make html
make check
  make install &&   make install-html

4.5.10 安装MPC

tar -xf mpc-1.0.2.tar.gz  && cd mpc-1.0.2
./configure --prefix=/usr --docdir=/usr/share/doc/mpc-1.0.2
make && make html
make check
make install && make install-html

4.5.11 安装 GCC

准备编译:


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

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

编译并安装:


make && make install

兼容部分希望gcc安装在/lib的软件:

ln -sv ../../usr/bin/cpp /lib

创建cc命令的软链接:

ln -sv gcc /usr/bin/cc

启用编译程序时进行链接时间优化:

install -v -dm755 /usr/lib/bfd-plugins
ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/4.9.2/liblto_plugin.so  /usr/lib/bfd-plugins/

之后执行4.5.3.5中的测试,输出大体一致,只是相应的路径会不一样,为确保后续编译正常,这个测试一定要做

4.5.12 安装Bzip2

打bzip2安装帮助文档补丁:

patch -Np1 -i ../bzip2-1.0.6-install_docs-1.patch

确保安装的符号链接是相对链接:

sed -i 's@\(ln -s -f \)$(PREFIX)/bin/@\1@' Makefile

确保man页面安装到正确的位置:

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

4.5.13 安装Pkg-config

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

make && make install

4.5.14 安装 Ncurses

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

make && make install

移动共享库到/lib

mv -v /usr/lib/libncursesw.so.5* /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${lib}w.a /usr/lib/lib${lib}.a
 ln -sfv ${lib}w.pc /usr/lib/pkgconfig/${lib}.pc
done
ln -sfv libncurses++w.a /usr/lib/libncurses++.a

rm -vf /usr/lib/libcursesw.so
echo "INPUT(-lncursesw)" > /usr/lib/libcursesw.so
ln -sfv libncurses.so /usr/lib/libcurses.so
ln -sfv libncursesw.a /usr/lib/libcursesw.a
ln -sfv libncurses.a /usr/lib/libcurses.a

安装帮助文档:

mkdir -v /usr/share/doc/ncurses-5.9
cp -v -R doc/* /usr/share/doc/ncurses-5.9

4.5.15 安装 Attr

准备编译:


sed -i -e 's|/@pkg_name@|&-@pkg_version@|' include/builddefs.in
sed -i -e "/SUBDIRS/s|man2||" man/Makefile
./configure --prefix=/usr

编译、测试和安装:

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

4.5.16 安装 Acl

修复一些错误,准备编译:

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 --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

4.5.17安装 Libcap

编译并安装:

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

4.5.18 安装 Sed

./configure --prefix=/usr --bindir=/bin --htmldir=/usr/share/doc/sed-4.2.2
make && make html
make install && make -C doc install-html

4.5.19 安装 Shadow

取消安装 groups 程序:


sed -i 's/groups$(EXEEXT) //' src/Makefile.in
find man -name Makefile.in -exec sed -i 's/groups\.1 / /' {} \;

使用更安全的SHA-512加密:

sed -i -e 's@#ENCRYPT_METHOD DES@ENCRYPT_METHOD SHA512@' \
 -e 's@/var/spool/mail@/var/mail@' etc/login.defs

保持useradd组一致:

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

启用shadow密码和shadow组密码:

pwconv
grpconv

新加用户不创建邮箱文件:

sed -i 's/yes/no/' /etc/default/useradd

4.5.20 安装 Psmisc

./configure --prefix=/usr
make && make install
mv -v /usr/bin/fuser /bin
mv -v /usr/bin/killall /bin

4.5.21 安装 Procps-ng

./configure --prefix=/usr \
 --exec-prefix= \
 --libdir=/usr/lib \
 --docdir=/usr/share/doc/procps-ng-3.3.10 \
 --disable-static \
 --disable-kill

make && make install
mv -v /usr/bin/pidof /bin
mv -v /usr/lib/libprocps.so.* /lib
ln -sfv ../../lib/$(readlink /usr/lib/libprocps.so) /usr/lib/libprocps.so

4.5.22 安装 E2fsprogs

修复潜在的安全问题:

sed -e '/int.*old_desc_blocks/s/int/blk64_t/' \
 -e '/if (old_desc_blocks/s/super->s_first_meta_bg/desc_blocks/' \
 -i lib/ext2fs/closefs.c
 
 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 && 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

4.5.23 安装 Coreutils

打兼容性补丁:


patch -Np1 -i ../coreutils-8.23-i18n-1.patch
touch Makefile.in

准备编译:


FORCE_UNSAFE_CONFIGURE=1 ./configure \
 --prefix=/usr \
 --enable-no-install-program=kill,uptime

编译并安装:

make && 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

4.5.24 安装 Iana-Etc

make && make install

4.5.25 安装 Flex

sed -i -e '/test-bison/d' tests/Makefile.in
./configure --prefix=/usr --docdir=/usr/share/doc/flex-2.5.39
make && make install
ln -sv flex /usr/bin/lex

4.5.26 安装 Bison

./configure --prefix=/usr --docdir=/usr/share/doc/bison-3.0.4
make && make install

4.5.27 安装 Grep

修复潜在的安全问题:

sed -i -e '/tp++/a if (ep <= tp) break;' src/kwset.c

编译安装:

./configure --prefix=/usr --bindir=/bin
make && make install

4.5.28 安装 Readline

修复一些bug:

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 --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

4.5.29 安装 Bash

修复bug:


patch -Np1 -i ../bash-4.3.30-upstream_fixes-1.patch

准备编译:

./configure --prefix=/usr \
 --bindir=/bin \
 --docdir=/usr/share/doc/bash-4.3.30 \
 --without-bash-malloc \
 --with-installed-readline

编译并安装:


make && make install
exec /bin/bash --login +h

4.5.30 安装 Bc

修复内存泄露:


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 && make install 

4.5.31 安装 Libtool

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

4.5.32 安装 GDBM

./configure --prefix=/usr --enable-libgdbm-compat
make && make install

4.5.33 安装 Expat

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

安装帮助文档

install -v -dm755 /usr/share/doc/expat-2.1.0
install -v -m644 doc/*.{html,png,css} /usr/share/doc/expat-2.1.0

4.5.34 安装 Inetutils

使ifconfig能正常编译:

echo '#define PATH_PROCNET_DEV "/proc/net/dev"' >> ifconfig/system/linux.h 

./configure --prefix=/usr \
 --localstatedir=/var \
 --disable-logger \
 --disable-whois \
 --disable-servers
 
 make && make install

移动文件:

mv -v /usr/bin/{hostname,ping,ping6,traceroute} /bin
mv -v /usr/bin/ifconfig /sbin

4.5.35 安装 Perl

创建hosts文件:


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 install
unset BUILD_ZLIB BUILD_BZIP2

4.5.36 安装 XML::Parser

perl Makefile.PL
make && make install

4.5.37 安装 Autoconf

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

4.5.38 安装automake

./configure --prefix=/usr --docdir=/usr/share/doc/automake-1.15
make  && make install

4.5.39 安装 Diffutils

修复文件安装区域文件:


sed -i 's:= @mkdir_p@:= /bin/mkdir -p:' po/Makefile.in.in

编译:

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

4.5.40 安装 Gawk

./configure --prefix=/usr
make && make install
mkdir -v /usr/share/doc/gawk-4.1.1
cp -v doc/{awkforai.txt,*.{eps,pdf,jpg}} /usr/share/doc/gawk-4.1.1

4.5.41 安装 Findutils

./configure --prefix=/usr --localstatedir=/var/lib/locate
make && make install
mv -v /usr/bin/find /bin
sed -i 's|find:=${BINDIR}|find:=/bin|' /usr/bin/updatedb

4.5.42 安装 Gettext

./configure --prefix=/usr --docdir=/usr/share/doc/gettext-0.19.4
make && make install

4.5.43 安装 Intltool

./configure --prefix=/usr
make && make install
install -v -Dm644 doc/I18N-HOWTO /usr/share/doc/intltool-0.50.2/I18NHOWTO

4.5.44 安装 Gperf

./configure --prefix=/usr --docdir=/usr/share/doc/gperf-3.0.4
make && make install

4.5.45 安装 Groff

PAGE=A4 ./configure --prefix=/usr
make && make install

4.5.46 安装 Xz

./configure --prefix=/usr --docdir=/usr/share/doc/xz-5.2.0
make && 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

4.5.47 安装 GRUB

./configure --prefix=/usr \
 --sbindir=/sbin \
 --sysconfdir=/etc \
 --disable-grub-emu-usb \
 --disable-efiemu \
 --disable-werror

make && make install

4.5.48 安装 Less

./configure --prefix=/usr --sysconfdir=/etc
make && make install

4.5.49 安装 Gzip

./configure --prefix=/usr --bindir=/bin
make && make install 
mv -v /bin/{gzexe,uncompress,zcmp,zdiff,zegrep} /usr/bin
mv -v /bin/{zfgrep,zforce,zgrep,zless,zmore,znew} /usr/bin

4.5.50 安装 IPRoute2

sed -i '/^TARGETS/s@arpd@@g' misc/Makefile
sed -i /ARPD/d Makefile
sed -i 's/arpd.8//' man/man8/Makefile

make 
make DOCDIR=/usr/share/doc/iproute2-3.19.0 install

4.5.51 安装 Kbd

patch -Np1 -i ../kbd-2.0.2-backspace-1.patch
sed -i 's/\(RESIZECONS_PROGS=\)yes/\1no/g' configure
sed -i 's/resizecons.8 //' docs/man/man8/Makefile.in

编译 Kbd:

PKG_CONFIG_PATH=/tools/lib/pkgconfig ./configure --prefix=/usr --disable-vlock
make && make install 

安装帮助手册:

mkdir -v /usr/share/doc/kbd-2.0.2
cp -R -v docs/doc/* /usr/share/doc/kbd-2.0.2

4.5.52 安装 Kmod

./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 -sv ../bin/kmod /sbin/$target
done

ln -sv kmod /bin/lsmod

4.5.53 安装 Libpipeline

PKG_CONFIG_PATH=/tools/lib/pkgconfig ./configure --prefix=/usr
make && make install

4.5.54 安装 Make

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

4.5.55 安装 Patch

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

4.5.56 安装 systemd

设置编译参数:

cat > config.cache << "EOF"
KILL=/bin/kill
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
EOF

修复util-linux编译错误:

sed -i "s:blkid/::" $(grep -rl "blkid/blkid.h")
patch -Np1 -i ../systemd-219-compat-1.patch
sed -i "s:test/udev-test.pl ::g" Makefile.in

准备编译 systemd:

./configure --prefix=/usr \
 --sysconfdir=/etc \
 --localstatedir=/var \
--config-cache \
 --with-rootprefix= \
 --with-rootlibdir=/lib \
 --enable-split-usr \
 --disable-gudev \
 --disable-firstboot \
 --disable-ldconfig \
 --disable-sysusers \
 --without-python \
 --docdir=/usr/share/doc/systemd-219 \
 --with-dbuspolicydir=/etc/dbus-1/system.d \
 --with-dbussessionservicedir=/usr/share/dbus-1/services \
 --with-dbussystemservicedir=/usr/share/dbus-1/system-services

编译并安装:

make LIBRARY_PATH=/tools/lib
make LD_LIBRARY_PATH=/tools/lib install
mv -v /usr/lib/libnss_{myhostname,mymachines,resolve}.so.2 /lib

创建也sysvinit兼容的符号链接:

for tool in runlevel reboot shutdown poweroff halt telinit; do
 ln -sfv ../bin/systemctl /sbin/${tool}
done
ln -sfv ../lib/systemd/systemd /sbin/init

修复错误:


sed -i "s:0775 root lock:0755 root root:g" /usr/lib/tmpfiles.d/legacy.conf
sed -i "/pam.d/d" /usr/lib/tmpfiles.d/etc.conf

创建/etc/machine-id文件:

systemd-machine-id-setup

4.5.57 安装 D-Bus

./configure --prefix=/usr \
 --sysconfdir=/etc \
 --localstatedir=/var \
 --docdir=/usr/share/doc/dbus-1.8.16 \
 --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

4.5.58 安装 Util-linux

新建hwclock目录:


mkdir -pv /var/lib/hwclock

准备编译 Util-linux:

./configure ADJTIME_PATH=/var/lib/hwclock/adjtime \
 --docdir=/usr/share/doc/util-linux-2.26 \
 --disable-chfn-chsh \
 --disable-login \
 --disable-nologin \
 --disable-su \
 --disable-setpriv \
 --disable-runuser \
 --disable-pylibmount \
 --without-python

make && make install

4.5.59 安装 Man-DB

./configure --prefix=/usr \
 --docdir=/usr/share/doc/man-db-2.7.1 \
 --sysconfdir=/etc \
 --disable-setuid \
 --with-browser=/usr/bin/lynx \
 --with-vgrind=/usr/bin/vgrind \
 --with-grap=/usr/bin/grap

make && make install

移除不存在的用户:

sed -i "s:man root:root root:g" /usr/lib/tmpfiles.d/man-db.conf

4.5.60 安装 Tar

FORCE_UNSAFE_CONFIGURE=1 \
./configure --prefix=/usr \
 --bindir=/bin
 
make && make install
make -C doc install-html docdir=/usr/share/doc/tar-1.28

4.5.61 安装 Texinfo

./configure --prefix=/usr
make && 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

4.5.62 Vim 的安装

修改默认配置文件位置为/etc:

echo '#define SYS_VIMRC_FILE "/etc/vimrc"' >> src/feature.h

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

建立vi的符号链接:

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

设置 Vim:

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

lfs-7.7学习笔记(1)准备篇
lfs-7.7学习笔记(2)构建临时系统
lfs-7.7学习笔记(3)构建 LFS 系统
lfs-7.7学习笔记(4)系统配置