目录
  1. 1. LFS系统构建03-安装基础系统软件
    1. 1.1. 准备虚拟内核文件系统
    2. 1.2. 开始进入构建的lfs环境
    3. 1.3. 创建主要目录
    4. 1.4. 创建重要文件和符号连接
    5. 1.5. linux api 头文件
    6. 1.6. man-pages
    7. 1.7. glibc
    8. 1.8. gawk
    9. 1.9. 适应工具链
    10. 1.10. zlib
    11. 1.11. file
    12. 1.12. readline
    13. 1.13. m4
    14. 1.14. bc
    15. 1.15. texinfo
    16. 1.16. binutils
    17. 1.17. gmp
    18. 1.18. mpfr
    19. 1.19. mpc
    20. 1.20. shadow
    21. 1.21. gcc(第三次安装)
    22. 1.22. bzip
    23. 1.23. pkg-config
    24. 1.24. ncurses
    25. 1.25. attr
    26. 1.26. acl
  2. 2. libcap
    1. 2.1. sed
    2. 2.2. psmisc
    3. 2.3. lana-etc
    4. 2.4. bison
    5. 2.5. flex
    6. 2.6. grep
    7. 2.7. bash
    8. 2.8. libtool
    9. 2.9. gdbm
    10. 2.10. gperf
    11. 2.11. expat
    12. 2.12. inetutils
    13. 2.13. perl
    14. 2.14. XML-Parser
    15. 2.15. intltool
    16. 2.16. autoconf
    17. 2.17. automake
    18. 2.18. xz
    19. 2.19. kmod
    20. 2.20. gettext
    21. 2.21. elfutils
    22. 2.22. libffi
    23. 2.23. openssl
    24. 2.24. Python
    25. 2.25. ninja
    26. 2.26. meson
    27. 2.27. coreutils
    28. 2.28. check
    29. 2.29. diffutils
    30. 2.30. gawk
    31. 2.31. findutils
    32. 2.32. groff
    33. 2.33. grub
    34. 2.34. less
    35. 2.35. gzip
    36. 2.36. iproute
    37. 2.37. kbd
    38. 2.38. libpipeline
    39. 2.39. make
    40. 2.40. man-db
    41. 2.41. patch
    42. 2.42. tar
    43. 2.43. vim
    44. 2.44. procps
    45. 2.45. utils-linux
    46. 2.46. e2fsprogs
    47. 2.47. sysklogd
    48. 2.48. sysvinit
    49. 2.49. eudev
    50. 2.50. 再次剥离(可选)
    51. 2.51. 清理
LFS系统构建03-安装基础系统软件

LFS系统构建03-安装基础系统软件

准备虚拟内核文件系统

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
mkdir -pv $LFS/{dev,proc,sys,run}
#创建初始化设备节点
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

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

开始进入构建的lfs环境

1
2
3
4
5
6
7
8
chroot "$LFS" /tools/bin/env -i \
HOME=/root
\
TERM="$TERM"
\
PS1='(lfs chroot) \u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
/tools/bin/bash --login +h

创建主要目录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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) mkdir -v /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}

创建重要文件和符号连接

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
ln -sv /tools/bin/{bash,cat,chmod,dd,echo,ln,mkdir,pwd,rm,stty,touch} /bin
ln -sv /tools/bin/{env,install,perl,printf} /usr/bin
ln -sv /tools/lib/libgcc_s.so{,.1} /usr/lib
ln -sv /tools/lib/libstdc++.{a,so{,.6}} /usr/lib
install -vdm755 /usr/lib/pkgconfig
ln -sv bash /bin/sh
ln -sv /proc/self/mounts /etc/mtab


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


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:
input:x:24:
mail:x:34:
kvm:x:61:
wheel:x:97:
nogroup:x:99:
users:x:999:
EOF

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

linux api 头文件

1
2
3
4
5
6
7
8
cd $LFS/sources/
tar xvf linux-4.20.12.tar.xz
cd linux-4.20.12
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

1
2
3
tar xvf man-pages-4.16.tar.xz
cd man-pages-4.16
make install

glibc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
cd $LFS/sources/
cd glibc-2.29
patch -Np1 -i ../glibc-2.29-fhs-1.patch
ln -sfv /tools/lib/gcc /usr/lib

case $(uname -m) in
i?86)
GCC_INCDIR=/usr/lib/gcc/$(uname -m)-pc-linux-gnu/8.2.0/include
ln -sfv ld-linux.so.2 /lib/ld-lsb.so.3
;;
x86_64) GCC_INCDIR=/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/include
ln -sfv ../lib/ld-linux-x86-64.so.2 /lib64
ln -sfv ../lib/ld-linux-x86-64.so.2 /lib64/ld-lsb-x86-64.so.3
;;
esac

rm -f /usr/include/limits.h
mkdir -v build
cd build

gawk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
tar xvf gawk-4.2.1.tar.xz
cd gawk-4.2.1
sed -i 's/extras//' Makefile.in
unset GCC_INCDIR

case $(uname -m) in
i?86)
ln -sfnv $PWD/elf/ld-linux.so.2
/lib ;;
x86_64) ln -sfnv $PWD/elf/ld-linux-x86-64.so.2 /lib ;;
esac

touch /etc/ld.so.conf
sed '/test-installation/s@$(PERL)@echo not running@' -i ../Makefile

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

#配置语言环境
mkdir -pv /usr/lib/locale
localedef -i POSIX -f UTF-8 C.UTF-8 2> /dev/null || true
localedef -i en_US -f ISO-8859-1 en_US
localedef -i en_US -f UTF-8 en_US.UTF-8
localedef -i zh_CN -f GB18030 zh_CN.GB18030
localedef -i zh_CN -f UTF-8 zh_CN.UTF-8
make localedata/install-locales

#增加 nsswitch.conf
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 -zxvf ../../tzdata2018i.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 ${tz} ; zic -L /dev/null -d $ZONEINFO/posix ${tz} ; zic -L leapseconds -d $ZONEINFO/right ${tz} ; done
cp -v zone.tab zone1970.tab iso3166.tab $ZONEINFO
zic -d $ZONEINFO -p Asia/ShangHai
#用命令更改时区
tzselect
cp -v /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
unset ZONEINFO

#配置动态加载

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

适应工具链

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
mv -v /tools/bin/{ld,ld-old}
renamed '/tools/bin/ld' -> '/tools/bin/ld-old'

mv -v /tools/$(uname -m)-pc-linux-gnu/bin/{ld,ld-old}
renamed '/tools/x86_64-pc-linux-gnu/bin/ld' -> '/tools/x86_64-pc-linux-gnu/bin/ld-old'

mv -v /tools/bin/{ld-new,ld}
renamed '/tools/bin/ld-new' -> '/tools/bin/ld'

ln -sv /tools/bin/ld /tools/$(uname -m)-pc-linux-gnu/bin/ld
'/tools/x86_64-pc-linux-gnu/bin/ld' -> '/tools/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

#测试工具链
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/../lib/crt1.o succeeded
/usr/lib/../lib/crti.o succeeded
/usr/lib/../lib/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-pc-linux-gnu/lib64")
SEARCH_DIR("/usr/lib")
SEARCH_DIR("/lib")
SEARCH_DIR("=/tools/x86_64-pc-linux-gnu/lib");

#确保我们用的是正确的libc
grep "/lib.*/libc.so.6 " dummy.log
attempt to open /lib/libc.so.6 succeeded

#确保gcc用的是正确的动态链接库
grep found dummy.log
found ld-linux-x86-64.so.2 at /lib/ld-linux-x86-64.so.2

#测试成功后删除
rm -v dummy.c a.out dummy.log

zlib

1
2
3
4
5
6
7
8
9
tar xvf zlib-1.2.11.tar.xz
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

1
2
3
4
5
6
7
cd $LFS/sources
tar -zxvf file-5.36.tar.gz
cd file-5.36
./configure --prefix=/usr
make
make check
make install

readline

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cd $LFS/sources
tar -zxvf readline-8.0.tar.gz
cd readline-8.0

sed -i '/MV.*old/d' Makefile.in
sed -i '/{OLDSUFF}/c:' support/shlib-install

./configure --prefix=/usr --disable-static --docdir=/usr/share/doc/readline-8.0
make SHLIB_LIBS="-L/tools/lib -lncursesw"
make SHLIB_LIBS="-L/tools/lib -lncursesw" install

mv -v /usr/lib/lib{readline,history}.so.* /lib
chmod -v u+w /lib/lib{readline,history}.so.*
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-8.0

m4

1
2
3
4
5
6
7
8
9
10
11
cd $LFS/sources
tar xvf m4-1.4.18.tar.xz
cd m4-1.4.18

sed -i 's/IO_ftrylockfile/IO_EOF_SEEN/' lib/*.c
echo "#define _IO_IN_BACKUP 0x100" >> lib/stdio-impl.h

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

bc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
cd $LFS/sources
tar -zxvf bc-1.07.1.tar.gz
cd bc-1.07.1

cat > bc/fix-libmath_h << "EOF"
#! /bin/bash
sed -e '1
s/^/{"/' \
-e
's/$/",/' \
-e '2,$ s/^/"/' \
-e
'$ d'
\
-i libmath.h
sed -e '$ s/$/0}/' \
-i libmath.h
EOF

ln -sv /tools/lib/libncursesw.so.6 /usr/lib/libncursesw.so.6
ln -sfv libncursesw.so.6 /usr/lib/libncurses.so
sed -i -e '/flex/s/as_fn_error/: ;; # &/' configure

./configure --prefix=/usr --with-readline --mandir=/usr/share/man --infodir=/usr/share/info
make
#如果出现makeinfo: command not found
提前编译安装texinfo,使其提供makeinfo就能解决

echo "quit" | ./bc/bc -l Test/checklib.b
make install

texinfo

1
2
3
4
5
sed -i '5481,5485 s/({/(\\{/' tp/Texinfo/Parser.pm
./configure --prefix=/usr --disable-static
make
make check
make TEXMF=/usr/share/texmf install-tex

binutils

1
2
3
4
5
6
7
8
9
10
tar xvf binutils-2.32.tar.xz 
cd binutils-2.32
expect -c "spawn ls"
mkdir -v build
cd build/

../configure --prefix=/usr --enable-gold --enable-ld=default --enable-plugins --enable-shared --disable-werror --enable-64-bit-bfd --with-system-zlib
make tooldir=/usr
make -k check
make tooldir=/usr install

gmp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cd $LFS/sources
tar xvf gmp-6.1.2.tar.xz
cd gmp-6.1.2

#如果你是32位的机子,但是运行64位的cpu,就需要使用这句
ABI=32 ./configure ...

cp -v configfsf.guess config.guess
cp -v configfsf.sub config.sub
./configure --prefix=/usr --enable-cxx --disable-static --docdir=/usr/share/doc/gmp-6.1.2
make
make html
make check 2>&1 | tee gmp-check-log
awk '/# PASS:/{total+=$3} ; END{print total}' gmp-check-log
make install
make install-html

mpfr

1
2
3
4
5
6
7
8
cd $LFS/sources
tar xvf mpfr-4.0.2.tar.xz
./configure --prefix=/usr --disable-static --enable-thread-safe --docdir=/usr/share/doc/mpfr-4.0.2
make
make html
make check
make install
make install-html

mpc

1
2
3
4
5
6
7
8
9
cd $LFS/sources
tar -zxvf mpc-1.1.0.tar.gz
cd mpc-1.1.0
./configure --prefix=/usr --disable-static --docdir=/usr/share/doc/mpc-1.1.0
make
make html
make check
make install
make install-html

shadow

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
cd $LFS/sources
tar xvf shadow-4.6.tar.xz
cd shadow-4.6
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 / /' {} \;

#用更安全的sha-512来加密
sed -i -e 's@#ENCRYPT_METHOD DES@ENCRYPT_METHOD SHA512@' \
-e 's@/var/spool/mail@/var/mail@' etc/login.defs
sed -i 's/1000/999/' etc/useradd
#加上Cracklib支持
sed -i 's@DICTPATH.*@DICTPATH\t/lib/cracklib/pw_dict@' etc/login.defs
./configure --sysconfdir=/etc --with-group-name-max-length=32
make
make install
mv -v /usr/bin/passwd /bin

#配置shadow
pwconv #将密码shadow
grpconv #将组密码shadow

passwd root

gcc(第三次安装)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
cd $LFS/sources
tar xvf gcc-8.2.0.tar.xz
cd gcc-8.2.0

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

#移除之前安装的gcc
rm -f /usr/lib/gcc
mkdir -v build
cd build/

../configure --prefix=/usr --enable-languages=c,c++ --disable-multilib --disable-bootstrap --disable-libmpx --with-system-zlib
make
ulimit -s 32768
rm ../gcc/testsuite/g++.dg/pr83239.C
chown -Rv nobody .
su nobody -s /bin/bash -c "PATH=$PATH make -k check"
../contrib/test_summary
make install
ln -sv ../usr/bin/cpp /lib
ln -sv gcc /usr/bin/cc

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

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

#确保开启文件正确 ok
grep -o '/usr/lib.*/crt[1in].*succeeded' dummy.log
/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../lib/crt1.o succeeded
/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../lib/crti.o succeeded
/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../lib/crtn.o succeeded


#验证编译时搜索的头文件 ok
grep -B4 '^ /usr/include' dummy.log
#include <...> search starts here:
/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/include
/usr/local/include
/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/include-fixed
/usr/include

#验证新链接器的搜索路径 ok
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");

#确保用的是正确的libc ok
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 /lib/ld-linux-x86-64.so.2

#删除测试文件
rm -v dummy.c a.out dummy.log


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

bzip

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
cd $LFS/sources
tar xvf 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

1
2
3
4
5
6
7
cd $LFS/sources
tar -zxvf pkg-config-0.29.2.tar.gz
cd pkg-config-0.29.2
./configure --prefix=/usr --with-internal-glib --disable-host-tool --docdir=/usr/share/doc/pkg-config-0.29.2
make
make check
make install

ncurses

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cd $LFS/sources
tar -zxvf ncurses-6.1.tar.gz
cd ncurses-6.1
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.1
cp -v -R doc/* /usr/share/doc/ncurses-6.1

attr

1
2
3
4
5
6
7
8
9
cd $LFS/sources
tar -zxvf attr-2.4.48.tar.gz
cd attr-2.4.48
./configure --prefix=/usr --bindir=/bin --disable-static --sysconfdir=/etc --docdir=/usr/share/doc/attr-2.4.48
make
make check
make install
mv -v /usr/lib/libattr.so.* /lib
ln -sfv ../../lib/$(readlink /usr/lib/libattr.so) /usr/lib/libattr.so

acl

1
2
3
4
5
6
7
8
cd $LFS/sources
tar -zxvf acl-2.2.53.tar.gz
cd acl-2.2.53
./configure --prefix=/usr --bindir=/bin --disable-static --libexecdir=/usr/lib --docdir=/usr/share/doc/acl-2.2.53
make
make install
mv -v /usr/lib/libacl.so.* /lib
ln -sfv ../../lib/$(readlink /usr/lib/libacl.so) /usr/lib/libacl.so

libcap

1
2
3
4
5
6
7
8
9
10
cd $LFS/sources
tar xvf libcap-2.26.tar.xz
cd libcap-2.26
sed -i '/install.*STALIBNAME/d' libcap/Makefile
make
make RAISE_SETFCAP=no lib=lib prefix=/usr install
chmod -v 755 /usr/lib/libcap.so.2.26

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

sed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cd $LFS/sources
tar xvf sed-4.7.tar.xz
cd sed-4.7
sed -i 's/usr/tools/' build-aux/help2man
sed -i 's/testsuite.panic-tests.sh//' Makefile.in

./configure --prefix=/usr --bindir=/bin
make
make html
make check
make install

install -d -m755 /usr/share/doc/sed-4.7
install -m644 doc/sed.html /usr/share/doc/sed-4.7

psmisc

1
2
3
4
5
6
7
8
cd $LFS/sources
tar xvf psmisc-23.2.tar.xz
cd psmisc-23.2
./configure --prefix=/usr
make
make install
mv -v /usr/bin/fuser /bin
mv -v /usr/bin/killall /bin

lana-etc

1
2
3
4
5
cd $LFS/sources
tar -jxvf iana-etc-2.30.tar.bz2
cd iana-etc-2.30
make
make install

bison

1
2
3
4
5
6
cd $LFS/sources
tar xvf bison-3.3.2.tar.xz
cd bison-3.3.2
./configure --prefix=/usr --docdir=/usr/share/doc/bison-3.3.2
make
make install

flex

1
2
3
4
5
6
7
8
9
cd $LFS/sources
tar -zxvf flex-2.6.4.tar.gz
cd flex-2.6.4
sed -i "/math.h/a #include <malloc.h>" src/flexdef.h
HELP2MAN=/tools/bin/true ./configure --prefix=/usr --docdir=/usr/share/doc/flex-2.6.4
make
make check
make install
ln -sv flex /usr/bin/lex

grep

1
2
3
4
5
6
7
cd $LFS/sources
tar xvf grep-3.3.tar.xz
cd grep-3.3
./configure --prefix=/usr --bindir=/bin
make
make -k check
make install

bash

1
2
3
4
5
6
7
8
9
10
cd $LFS/sources
tar -zxvf bash-5.0.tar.gz
cd bash-5.0
./configure --prefix=/usr --docdir=/usr/share/doc/bash-5.0 --without-bash-malloc --with-installed-readline
make
chown -Rv nobody .
su nobody -s /bin/bash -c "PATH=$PATH HOME=/home make tests"
make install
mv -vf /usr/bin/bash /bin
exec /bin/bash --login +h

libtool

1
2
3
4
5
6
7
cd $LFS/sources
tar xvf libtool-2.4.6.tar.xz
cd libtool-2.4.6
./configure --prefix=/usr
make
make check
make install

gdbm

1
2
3
4
5
6
7
cd $LFS/sources
tar -zxvf gdbm-1.18.1.tar.gz
cd gdbm-1.18.1
./configure --prefix=/usr --disable-static --enable-libgdbm-compat
make
make check
make install

gperf

1
2
3
4
5
6
7
cd $LFS/sources
tar -zxvf gperf-3.1.tar.gz
cd gperf-3.1
./configure --prefix=/usr --docdir=/usr/share/doc/gperf-3.1
make
make -j1 check
make install

expat

1
2
3
4
5
6
7
8
9
cd $LFS/sources
tar -jxvf expat-2.2.6.tar.bz2
cd expat-2.2.6
sed -i 's|usr/bin/env |bin/|' run.sh.in
./configure --prefix=/usr --disable-static --docdir=/usr/share/doc/expat-2.2.6
make
make check
make install
install -v -m644 doc/*.{html,png,css} /usr/share/doc/expat-2.2.6

inetutils

1
2
3
4
5
6
7
8
9
10
cd $LFS/sources
tar xvf inetutils-1.9.4.tar.xz
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

1
2
3
4
5
6
7
8
9
10
11
12
cd $LFS/sources
tar xvf perl-5.28.1.tar.xz
cd perl-5.28.1
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 -Dusethreads
make
make -k check
make install
unset BUILD_ZLIB BUILD_BZIP2

XML-Parser

1
2
3
4
5
6
7
cd $LFS/sources
tar -zxvf XML-Parser-2.44.tar.gz
cd XML-Parser-2.44
perl Makefile.PL
make
make test
make install

intltool

1
2
3
4
5
6
7
8
9
cd $LFS/sources
tar -zxvf 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

1
2
3
4
5
6
7
cd $LFS/sources
tar xvf autoconf-2.69.tar.xz
cd autoconf-2.69
./configure --prefix=/usr
make
make check
make install

automake

1
2
3
4
5
6
7
cd $LFS/sources
tar xvf automake-1.16.1.tar.xz
cd automake-1.16.1
./configure --prefix=/usr --docdir=/usr/share/doc/automake-1.16.1
make
make -j4 check
make install

xz

1
2
3
4
5
6
7
8
9
10
cd $LFS/sources
tar xvf xz-5.2.4.tar.xz
cd xz-5.2.4
./configure --prefix=/usr --disable-static --docdir=/usr/share/doc/xz-5.2.4
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

1
2
3
4
5
6
7
8
9
10
11
cd $LFS/sources
tar xvf kmod-26.tar.xz
cd kmod-26
./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

1
2
3
4
5
6
7
8
9
10
cd $LFS/sources
tar xvf gettext-0.19.8.1.tar.xz
cd gettext-0.19.8.1
sed -i '/^TESTS =/d' gettext-runtime/tests/Makefile.in && sed -i 's/test-lock..EXEEXT.//' gettext-tools/gnulib-tests/Makefile.in
sed -e '/AppData/{N;N;p;s/\.appdata\./.metainfo./}' -i gettext-tools/its/appdata.loc
./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

elfutils

1
2
3
4
5
6
7
8
cd $LFS/sources
tar -jxvf elfutils-0.176.tar.bz2
cd elfutils-0.176
./configure --prefix=/usr
make
make check
make -C libelf install
install -vm644 config/libelf.pc /usr/lib/pkgconfig

libffi

1
2
3
4
5
6
7
8
9
10
cd $LFS/sources
tar -zxvf libffi-3.2.1.tar.gz
cd libffi-3.2.1
sed -e '/^includesdir/ s/$(libdir).*$/$(includedir)/' -i include/Makefile.in
sed -e '/^includedir/ s/=.*$/=@includedir@/' -e 's/^Cflags: -I${includedir}/Cflags:/' -i libffi.pc.in

./configure --prefix=/usr --disable-static --with-gcc-arch=native
make
make check
make install

openssl

1
2
3
4
5
6
7
8
9
10
cd $LFS/sources
tar -zxvf openssl-1.1.1a.tar.gz
cd openssl-1.1.1a
./config --prefix=/usr --openssldir=/etc/ssl --libdir=lib shared zlib-dynamic
make
make test
sed -i '/INSTALL_LIBS/s/libcrypto.a libssl.a//' Makefile
make MANSUFFIX=ssl install
mv -v /usr/share/doc/openssl /usr/share/doc/openssl-1.1.1a
cp -vfr doc/* /usr/share/doc/openssl-1.1.1a

Python

1
2
3
4
5
6
7
8
9
10
cd $LFS/sources
tar xvf Python-3.7.2.tar.xz
cd Python-3.7.2
./configure --prefix=/usr --enable-shared --with-system-expat --with-system-ffi --with-ensurepip=yes
make
make install
chmod -v 755 /usr/lib/libpython3.7m.so
chmod -v 755 /usr/lib/libpython3.so
install -v -dm755 /usr/share/doc/python-3.7.2/html
tar --strip-components=1 --no-same-owner --no-same-permissions -C /usr/share/doc/python-3.7.2/html -jxvf ../python-3.7.2-docs-html.tar.bz2

ninja

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
cd $LFS/sources
tar -zxvf ninja-1.9.0.tar.gz
cd ninja-1.9.0
export NINJAJOBS=4

sed -i '/int Guess/a \
int j = 0;\
char* jobs = getenv( "NINJAJOBS" );\
if ( jobs != NULL ) j = atoi( jobs );\
if ( j > 0 ) return j;\
' src/ninja.cc

python3 configure.py --bootstrap
python3 configure.py
./ninja ninja_test
./ninja_test --gtest_filter=-SubprocessTest.SetWithLots

install -vm755 ninja /usr/bin/
install -vDm644 misc/bash-completion /usr/share/bash-completion/completions/ninja
install -vDm644 misc/zsh-completion /usr/share/zsh/site-functions/_ninja

meson

1
2
3
4
5
6
cd $LFS/sources
tar -zxvf meson-0.49.2.tar.gz
cd meson-0.49.2
python3 setup.py build
python3 setup.py install --root=dest
cp -rv dest/* /

coreutils

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
cd $LFS/sources
tar xvf coreutils-8.30.tar.xz
cd coreutils-8.30
patch -Np1 -i ../coreutils-8.30-i18n-1.patch
sed -i '/test.lock/s/^/#/' gnulib-tests/gnulib.mk
autoreconf -fiv
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,nice,sleep,touch} /bin

check

1
2
3
4
5
6
7
8
cd $LFS/sources
tar -zxvf check-0.12.0.tar.gz
cd check-0.12.0
./configure --prefix=/usr
make
make check
make install
sed -i '1 s/tools/usr/' /usr/bin/checkmk

diffutils

1
2
3
4
5
6
7
cd $LFS/sources
tar xvf diffutils-3.7.tar.xz
cd diffutils-3.7
./configure --prefix=/usr
make
make check
make install

gawk

1
2
3
4
5
6
7
8
9
10
cd $LFS/sources
tar -xvf gawk-4.2.1.tar.xz
cd gawk-4.2.1
sed -i 's/extras//' Makefile.in
./configure --prefix=/usr
make
make check
make install
mkdir -v /usr/share/doc/gawk-4.2.1
cp -v doc/{awkforai.txt,*.{eps,pdf,jpg}} /usr/share/doc/gawk-4.2.1

findutils

1
2
3
4
5
6
7
8
9
10
11
12
13
cd $LFS/sources
tar -zxvf findutils-4.6.0.tar.gz
cd findutils-4.6.0
sed -i 's/test-lock..EXEEXT.//' tests/Makefile.in
sed -i 's/IO_ftrylockfile/IO_EOF_SEEN/' gl/lib/*.c
sed -i '/unistd/a #include <sys/sysmacros.h>' gl/lib/mountlist.c
echo "#define _IO_IN_BACKUP 0x100" >> gl/lib/stdio-impl.h
./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

1
2
3
4
5
6
cd $LFS/sources
tar -zxvf groff-1.22.4.tar.gz
cd groff-1.22.4
PAGE=A4 ./configure --prefix=/usr
make -j1
make install

grub

1
2
3
4
5
6
7
cd $LFS/sources
tar xvf grub-2.02.tar.xz
cd grub-2.02
./configure --prefix=/usr --sbindir=/sbin --sysconfdir=/etc --disable-efiemu --disable-werror
make
make install
mv -v /etc/bash_completion.d/grub /usr/share/bash-completion/completions

less

1
2
3
4
5
6
cd $LFS/sources
tar -zxvf less-530.tar.gz
cd less-530
./configure --prefix=/usr --sysconfdir=/etc
make
make install

gzip

1
2
3
4
5
6
7
8
cd $LFS/sources
tar xvf gzip-1.10.tar.xz
cd gzip-1.10
./configure --prefix=/usr
make
make check
make install
mv -v /usr/bin/gzip /bin

iproute

1
2
3
4
5
6
7
8
cd $LFS/sources
tar xvf iproute2-4.20.0.tar.xz
cd iproute2-4.20.0
sed -i /ARPD/d Makefile
rm -fv man/man8/arpd.8
sed -i 's/.m_ipt.o//' tc/Makefile
make
make DOCDIR=/usr/share/doc/iproute2-4.20.0 install

kbd

1
2
3
4
5
6
7
8
9
10
11
12
cd $LFS/sources
tar xvf kbd-2.0.4.tar.xz
cd kbd-2.0.4
patch -Np1 -i ../kbd-2.0.4-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.4
cp -R -v docs/doc/* /usr/share/doc/kbd-2.0.4

libpipeline

1
2
3
4
5
6
7
cd $LFS/sources
tar -zxvf libpipeline-1.5.1.tar.gz
cd libpipeline-1.5.1
./configure --prefix=/usr
make
make check
make install

make

1
2
3
4
5
6
7
8
cd $LFS/sources
tar -zxvf make-4.2.1.tar.gz
cd make-4.2.1
sed -i '211,217 d; 219,229 d; 232 d' glob/glob.c
./configure --prefix=/usr
make
make PERL5LIB=$PWD/tests/ check
make install

man-db

1
2
3
4
5
6
7
cd $LFS/sources
tar xvf man-db-2.8.5.tar.xz
cd man-db-2.8.5
./configure --prefix=/usr --docdir=/usr/share/doc/man-db-2.8.5 --sysconfdir=/etc --disable-setuid --enable-cache-owner=bin --with-browser=/usr/bin/lynx --with-vgrind=/usr/bin/vgrind --with-grap=/usr/bin/grap --with-systemdtmpfilesdir= --with-systemdsystemunitdir=
make
make check
make install

patch

1
2
3
4
5
6
7
cd $LFS/sources
tar xvf patch-2.7.6.tar.xz
cd patch-2.7.6
./configure --prefix=/usr
make
make check
make install

tar

1
2
3
4
5
6
7
8
9
cd $LFS/sources
tar xvf tar-1.31.tar.xz
cd tar-1.31
sed -i 's/abort.*/FALLTHROUGH;/' src/extract.c
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.31

vim

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
cd $LFS/sources
tar -jxvf vim-8.1.tar.bz2
cd vim81/
echo '#define SYS_VIMRC_FILE "/etc/vimrc"' >> src/feature.h
./configure --prefix=/usr
make

# 测试结果
LANG=en_US.UTF-8 make -j1 test &> vim-test.log
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/vim81/doc /usr/share/doc/vim-8.1

cat > /etc/vimrc << "EOF"
" Begin /etc/vimrc
" Ensure defaults are set before customizing settings, not after
source $VIMRUNTIME/defaults.vim
let skip_defaults_vim=1
set nocompatible
set backspace=2
set mouse=
syntax on
if (&term == "xterm") || (&term == "putty")
set background=dark
endif
" End /etc/vimrc
EOF

vim -c ':options'

procps

1
2
3
4
5
6
7
8
9
10
11
12
cd $LFS/sources
tar xvf procps-ng-3.3.15.tar.xz
cd procps-ng-3.3.15
./configure --prefix=/usr --exec-prefix= --libdir=/usr/lib --docdir=/usr/share/doc/procps-ng-3.3.15 --disable-static --disable-kill
make
sed -i -r 's|(pmap_initname)\\\$|\1|' testsuite/pmap.test/pmap.exp
sed -i '/set tty/d' testsuite/pkill.test/pkill.exp
rm testsuite/pgrep.test/pgrep.exp
make check
make install
mv -v /usr/lib/libprocps.so.* /lib
ln -sfv ../../lib/$(readlink /usr/lib/libprocps.so) /usr/lib/libprocps.so

utils-linux

1
2
3
4
5
6
7
8
9
10
cd $LFS/sources
tar xvf util-linux-2.33.1.tar.xz
cd util-linux-2.33.1
mkdir -pv /var/lib/hwclock
rm -vf /usr/include/{blkid,libmount,uuid}
./configure ADJTIME_PATH=/var/lib/hwclock/adjtime --docdir=/usr/share/doc/util-linux-2.33.1 --disable-chfn-chsh --disable-login --disable-nologin --disable-su --disable-setpriv --disable-runuser --disable-pylibmount --disable-static --without-python --without-systemd --without-systemdsystemunitdir
make
chown -Rv nobody .
su nobody -s /bin/bash -c "PATH=$PATH make -k check"
make install

e2fsprogs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
cd $LFS/sources
tar -zxvf e2fsprogs-1.44.5.tar.gz
cd e2fsprogs-1.44.5
mkdir -v build
cd build

../configure --prefix=/usr --bindir=/bin --with-root-prefix="" --enable-elf-shlibs --disable-libblkid --disable-libuuid --disable-uuidd --disable-fsck
make
make 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

sysklogd

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cd $LFS/sources
tar -zxvf sysklogd-1.5.1.tar.gz
cd sysklogd-1.5.1
sed -i '/Error loading kernel symbols/{n;n;d}' ksym_mod.c
sed -i 's/union wait/int/' syslogd.c
make
make BINDIR=/sbin install

cat > /etc/syslog.conf << "EOF"
# Begin /etc/syslog.conf
auth,authpriv.* -/var/log/auth.log
*.*;auth,authpriv.none -/var/log/sys.log
daemon.* -/var/log/daemon.log
kern.* -/var/log/kern.log
mail.* -/var/log/mail.log
user.* -/var/log/user.log
*.emerg *
# End /etc/syslog.conf
EOF

sysvinit

1
2
3
4
5
6
cd $LFS/sources
tar xvf sysvinit-2.93.tar.xz
cd sysvinit-2.93
patch -Np1 -i ../sysvinit-2.93-consolidated-1.patch
make
make install

eudev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
cd $LFS/sources
tar -zxvf eudev-3.2.7.tar.gz
cd eudev-3.2.7

cat > config.cache << "EOF"
HAVE_BLKID=1
BLKID_LIBS="-lblkid"
BLKID_CFLAGS="-I/tools/include"
EOF

./configure --prefix=/usr --bindir=/sbin --sbindir=/sbin --libdir=/usr/lib --sysconfdir=/etc --libexecdir=/lib --with-rootprefix= --with-rootlibdir=/lib --enable-manpages --disable-static --config-cache

LIBRARY_PATH=/tools/lib make

mkdir -pv /lib/udev/rules.d
mkdir -pv /etc/udev/rules.d

make LD_LIBRARY_PATH=/tools/lib check
make LD_LIBRARY_PATH=/tools/lib install
tar -jxvf ../udev-lfs-20171102.tar.bz2
make -f udev-lfs-20171102/Makefile.lfs install

#配置
LD_LIBRARY_PATH=/tools/lib udevadm hwdb --update

再次剥离(可选)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#在blfs中u用valgrind 或 gdb运行测试时需要这些调试信息
save_lib="ld-2.29.so libc-2.29.so libpthread-2.29.so libthread_db-1.0.so"
cd /lib
for LIB in $save_lib; do
objcopy --only-keep-debug $LIB $LIB.dbg
strip --strip-unneeded $LIB
objcopy --add-gnu-debuglink=$LIB.dbg $LIB
done
save_usrlib="libquadmath.so.0.0.0 libstdc++.so.6.0.25
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
strip --strip-unneeded $LIB
objcopy --add-gnu-debuglink=$LIB.dbg $LIB
done
unset LIB save_lib save_usrlib

#确保二进制能运行
exec /tools/bin/bash

#安全剥离二进制和库
/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* -a ! -name \*dbg \) \
-exec /tools/bin/strip --strip-unneeded {} ';'
/tools/bin/find /{bin,sbin} /usr/{bin,sbin,libexec} -type f \
-exec /tools/bin/strip --strip-all {} ';'

清理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
rm -rf /tmp/*

exit

sudo chroot "$LFS" /usr/bin/env -i HOME=/root TERM="$TERM" PS1='(lfs chroot) \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/libz.a
find /usr/lib /usr/libexec -name \*.la -delete
文章作者: rack-leen
文章链接: http://yoursite.com/2019/06/04/LFS/LFS%E7%B3%BB%E7%BB%9F%E6%9E%84%E5%BB%BA03-%E5%AE%89%E8%A3%85%E5%9F%BA%E7%A1%80%E7%B3%BB%E7%BB%9F%E8%BD%AF%E4%BB%B6/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 rack-leen's blog
打赏
  • 微信
  • 支付宝

评论