一朝风月 万古长空

0%

LFS7.7编译要点

LFS7.7 编译安装记录

编译完成后的想法

断断续续折腾了两个星期,此次编译安装的心得,果如古人云“欲速则不达”。
反思编译安装过程,需要注意以下问题:

  • 首先通读LFS整篇文档,了解每个步骤的主要工作
  • 检查当前编译环境,相关编译工具是否安装完成
  • 退出当前编译环境后,怎样重回LFS的编译环境

LFS 主要是帮助大家理解Linux系统整体流程,通读文档,就会有一个很好的了解。
那么进行此次编译的目的,也就达到。

LFS7.7 在线阅读

LFS7.7 官方在线阅读地址

  • 请注意查阅最新章节

    Tips

编译环境
主机:MacBook Pro Model:A1502
VirtualBox安装:Ubuntu 14.04.2 LTS (GNU/Linux 3.16.0-30-generic x86_64)
针对于ubuntu宿主环境,需要安装以下程序

1
2
sudo apt-get install bison      
sudo apt-get install texinfo

并根据手册,运行相关脚本检测当前系统程序版本和相关库。
不超出推荐版本,即可。

运行library-check.sh检测脚本出现以下提示,亦无问题(LFS有相关说明)。

1
2
3
4
aurora@aurora-VirtualBox:~/lfs$ bash library-check.sh
libgmp.la: not found
libmpfr.la: not found
libmpc.la: not found

删除指定sources文件夹之外的文件夹

1
ls |grep -v sources|xargs sudo rm -rf

删除当前目录下其他文件夹

1
find -type d -maxdepth 1|sudo xargs rm -rf

virtualbox添加LFS运行硬盘

添加独立硬盘,完成lfs编译后,在主grub中添加lfs系统引导启动。

  • 通过virtualbox创建新的linux磁盘大小
    Alt ext

如上图所示,新增lfs硬盘。而后,启动虚拟机。参照如下指令,对磁盘进行分区。注意将对应磁盘,替换为自己编译环境中的相应盘符。

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
78
79
80
81
82
83
84
85
86
87
88
aurora@aurora-VirtualBox:~$ sudo fdisk -l
[sudo] password for aurora:

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000e7c1c

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 37748735 18873344 83 Linux
/dev/sda2 37750782 41940991 2095105 5 Extended
/dev/sda5 37750784 41940991 2095104 82 Linux swap / Solaris

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

aurora@aurora-VirtualBox:~$ sudo fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x375750ff.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x375750ff

Device Boot Start End Blocks Id System
/dev/sdb1 2048 41943039 20970496 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
aurora@aurora-VirtualBox:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 18G 3.6G 14G 22% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 991M 4.0K 991M 1% /dev
tmpfs 201M 952K 200M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 1001M 76K 1001M 1% /run/shm
none 100M 28K 100M 1% /run/user

创建ext4文件分区

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
aurora@aurora-VirtualBox:~$ sudo mkfs -v -t ext4 /dev/sdb1
mke2fs 1.42.9 (4-Feb-2014)
fs_types for mke2fs.conf resolution: 'ext4'
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242624 blocks
262131 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

LFS7.7 各章编译要点

###chapter 5 编译
5.22. Gawk-4.1.1

1
make test

提示出错,lfs中也有说明,并不是一定要运行make test命令。通过google搜索,见到如下回复:

Chapter 5 isn’t a complete OS. It’s a bootstrap system, so it’s not going to be built the same, nor pass tests normally. As long as the GCC and binutils sanity checks are okay, you’re fine.
忽略此处,一样可以完成编译。没有问题。
编译chapter 5完成后,若磁盘空间足够,则无需剔除相关程序中的调试信息。
备份本章编译工具。chapter 6执行后,可能会更改相关工具。若chapter相关工具编译失败,可重新进行编译。节约时间。

chapter 6 编译

6.9. Glibc-2.21

1
make check

出现以下错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
scripts/merge-test-results.sh -t /sources/glibc-build/ subdir-tests.sum \
. argp assert catgets conform crypt csu ctype debug dirent dlfcn elf gmon gnulib grp gshadow hesiod iconv iconvdata inet intl io libidn libio locale localedata login malloc manual math misc nis nptl nptl_db nscd nss po posix pwd resolv resource rt setjmp shadow signal socket stdio-common stdlib streams string sunrpc sysvipc termios time timezone wcsmbs wctype \
> /sources/glibc-build/tests.sum
FAIL: nptl/tst-cond20
FAIL: nptl/tst-cond21
FAIL: nptl/tst-cond24
FAIL: posix/tst-getaddrinfo4
FAIL: posix/tst-getaddrinfo5
Summary of test results:
5 FAIL
2180 PASS
199 XFAIL
3 XPASS
Makefile:321: recipe for target 'tests' failed
make[1]: *** [tests] Error 1
make[1]: Leaving directory '/sources/glibc-2.21'
Makefile:9: recipe for target 'check' failed
make: *** [check] Error 2

允许,继续进行下一步

6.17. GCC-4.9.2

1
make -k check

时间很长,做好心理准备。
编译完成后,使用../gcc-4.9.2/contrib/test_summary检测编译输出log。
搜索相应平台版本编译生成的log日志
选择自己的宿主环境,对照编译log。
以下为我自己的log输出:

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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
root:/sources/gcc-build# ../gcc-4.9.2/contrib/test_summary
cat <<'EOF' |
LAST_UPDATED: Obtained from SVN: tags/gcc_4_9_2_release revision 216910

Native configuration is x86_64-unknown-linux-gnu

=== g++ tests ===


Running target unix
FAIL: g++.dg/asan/asan_test.C -O2 AddressSanitizer_HugeMallocTest Ident((char*)malloc(size))[-1] = 0 output pattern test
XPASS: g++.dg/tls/thread_local-order2.C -std=c++11 execution test
XPASS: g++.dg/tls/thread_local-order2.C -std=c++1y execution test

=== g++ Summary ===

# of expected passes 88500
# of unexpected failures 1
# of unexpected successes 2
# of expected failures 443
# of unsupported tests 3058
/sources/gcc-build/gcc/testsuite/g++/../../xg++ version 4.9.2 (GCC)

=== gcc tests ===


Running target unix

=== gcc Summary ===

# of expected passes 106352
# of expected failures 252
# of unsupported tests 1422
/sources/gcc-build/gcc/xgcc version 4.9.2 (GCC)

=== libatomic tests ===


Running target unix

=== libatomic Summary ===

# of expected passes 54
=== libgomp tests ===


Running target unix

=== libgomp Summary ===

# of expected passes 693
=== libitm tests ===


Running target unix

=== libitm Summary ===

# of expected passes 26
# of expected failures 3
# of unsupported tests 1
=== libstdc++ tests ===


Running target unix

=== libstdc++ Summary ===

# of expected passes 9925
# of expected failures 41
# of unsupported tests 233

Compiler version: 4.9.2 (GCC)
Platform: x86_64-unknown-linux-gnu
configure flags: --prefix=/usr --enable-languages=c,c++ --disable-multilib --disable-bootstrap --with-system-zlib
EOF
Mail -s "Results for 4.9.2 (GCC) testsuite on x86_64-unknown-linux-gnu" gcc-testresults@gcc.gnu.org &&
mv /sources/gcc-build/./gcc/testsuite/g++/g++.sum /sources/gcc-build/./gcc/testsuite/g++/g++.sum.sent &&
mv /sources/gcc-build/./gcc/testsuite/gcc/gcc.sum /sources/gcc-build/./gcc/testsuite/gcc/gcc.sum.sent &&
mv /sources/gcc-build/./x86_64-unknown-linux-gnu/libatomic/testsuite/libatomic.sum /sources/gcc-build/./x86_64-unknown-linux-gnu/libatomic/testsuite/libatomic.sum.sent &&
mv /sources/gcc-build/./x86_64-unknown-linux-gnu/libgomp/testsuite/libgomp.sum /sources/gcc-build/./x86_64-unknown-linux-gnu/libgomp/testsuite/libgomp.sum.sent &&
mv /sources/gcc-build/./x86_64-unknown-linux-gnu/libitm/testsuite/libitm.sum /sources/gcc-build/./x86_64-unknown-linux-gnu/libitm/testsuite/libitm.sum.sent &&
mv /sources/gcc-build/./x86_64-unknown-linux-gnu/libstdc++-v3/testsuite/libstdc++.sum /sources/gcc-build/./x86_64-unknown-linux-gnu/libstdc++-v3/testsuite/libstdc++.sum.sent &&
mv /sources/gcc-build/./gcc/testsuite/g++/g++.log /sources/gcc-build/./gcc/testsuite/g++/g++.log.sent &&
mv /sources/gcc-build/./gcc/testsuite/gcc/gcc.log /sources/gcc-build/./gcc/testsuite/gcc/gcc.log.sent &&
mv /sources/gcc-build/./x86_64-unknown-linux-gnu/libatomic/testsuite/libatomic.log /sources/gcc-build/./x86_64-unknown-linux-gnu/libatomic/testsuite/libatomic.log.sent &&
mv /sources/gcc-build/./x86_64-unknown-linux-gnu/libgomp/testsuite/libgomp.log /sources/gcc-build/./x86_64-unknown-linux-gnu/libgomp/testsuite/libgomp.log.sent &&
mv /sources/gcc-build/./x86_64-unknown-linux-gnu/libitm/testsuite/libitm.log /sources/gcc-build/./x86_64-unknown-linux-gnu/libitm/testsuite/libitm.log.sent &&
mv /sources/gcc-build/./x86_64-unknown-linux-gnu/libstdc++-v3/testsuite/libstdc++.log /sources/gcc-build/./x86_64-unknown-linux-gnu/libstdc++-v3/testsuite/libstdc++.log.sent &&
true
root:/sources/gcc-build#

6.38. Libtool-2.4.6

1
make check

提示报错,忽略继续进行。
编译依旧lfs成功。log如下:

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
## ------------- ##
## Test results. ##
## ------------- ##

ERROR: 139 tests were run,
64 failed (59 expected failures).
31 tests were skipped.
## -------------------------- ##
## testsuite.log was created. ##
## -------------------------- ##

Please send `tests/testsuite.log' and all information you think might help:

To: <bug-libtool@gnu.org>
Subject: [GNU Libtool 2.4.6] testsuite: 123 124 125 126 130 failed

You may investigate any problem if you feel able to do so, in which
case the test suite provides a good starting point. Its output may
be found below `tests/testsuite.dir'.

Makefile:2459: recipe for target 'check-local' failed
make[3]: *** [check-local] Error 1
make[3]: Leaving directory '/sources/libtool-2.4.6'
Makefile:1897: recipe for target 'check-am' failed
make[2]: *** [check-am] Error 2
make[2]: Leaving directory '/sources/libtool-2.4.6'
Makefile:1606: recipe for target 'check-recursive' failed
make[1]: *** [check-recursive] Error 1
make[1]: Leaving directory '/sources/libtool-2.4.6'
Makefile:1899: recipe for target 'check' failed
make: *** [check] Error 2

lfs官方提示:
Five tests are known to fail in the LFS build envronment due to a circular dependency, but all tests pass if rechecked after automake is installed.

6.49. Gettext-0.19.4
编译时出现错误,现在暂时忽略。
编译lfs依旧成功。

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
make[6]: Entering directory '/sources/gettext-0.19.4/gettext-tools/tests'
make[6]: Nothing to be done for 'all'.
make[6]: Leaving directory '/sources/gettext-0.19.4/gettext-tools/tests'
============================================================================
Testsuite summary for gettext-tools 0.19.4
============================================================================
# TOTAL: 397
# PASS: 378
# SKIP: 18
# XFAIL: 0
# FAIL: 1
# XPASS: 0
# ERROR: 0
============================================================================
See tests/test-suite.log
Please report to bug-gnu-gettext@gnu.org
============================================================================
Makefile:2221: recipe for target 'test-suite.log' failed
make[5]: *** [test-suite.log] Error 1
make[5]: Leaving directory '/sources/gettext-0.19.4/gettext-tools/tests'
Makefile:2327: recipe for target 'check-TESTS' failed
make[4]: *** [check-TESTS] Error 2
make[4]: Leaving directory '/sources/gettext-0.19.4/gettext-tools/tests'
Makefile:5172: recipe for target 'check-am' failed
make[3]: *** [check-am] Error 2
make[3]: Leaving directory '/sources/gettext-0.19.4/gettext-tools/tests'
Makefile:1721: recipe for target 'check-recursive' failed
make[2]: *** [check-recursive] Error 1
make[2]: Leaving directory '/sources/gettext-0.19.4/gettext-tools'
Makefile:369: recipe for target 'check-recursive' failed
make[1]: *** [check-recursive] Error 1
make[1]: Leaving directory '/sources/gettext-0.19.4'
Makefile:661: recipe for target 'check' failed
make: *** [check] Error 2

chapter 7.1

针对于chapter 6章,离开编译环境(重启,或退出终端),重新进入编译环境,参照lfs,执行6.2.2和6.2.3相关命令。

If the virtual kernel file systems have been unmounted, either manually or through a reboot, ensure that the virtual kernel file systems are mounted when reentering the chroot. This process was explained in Section 6.2.2, “Mounting and Populating /dev” and Section 6.2.3, “Mounting Virtual Kernel File Systems”.

1
2
3
4
5
6
7
8
9
10
11
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
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

进入chapter 7章,离开编译环境(重启,或退出终端),重新进入编译环境,执行以下命令

1
2
3
4
5
6
7
8
9
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
chroot "$LFS" /usr/bin/env -i \
HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin \
/bin/bash --login

设置本地变量,统一设置为en_US.utf8,以下命令测试,是否支持。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
LC_ALL=en_US.utf8 locale language
LC_ALL=en_US.utf8 locale charmap
LC_ALL=en_US.utf8 locale int_curr_symbol
LC_ALL=en_US.utf8 locale int_prefix


root:/etc/sysconfig# LC_ALL=en_US.utf8 locale language
English
root:/etc/sysconfig# LC_ALL=en_US.utf8 locale charmap
UTF-8
root:/etc/sysconfig# LC_ALL=en_US.utf8 locale int_curr_symbol
USD
root:/etc/sysconfig# LC_ALL=en_US.utf8 locale int_prefix
1

之后创建配置文件

cat > /etc/profile << "EOF"
# Begin /etc/profile

export LANG=en_US.utf8

# End /etc/profile
EOF

chapter 8
安装grub,导致覆盖了ubuntu原来的grub配置,可参照如下链接步骤恢复:
覆盖grub,恢复原来的系统

其他博主的LFS编译总结

不错的LFS编译总结

需要大家支持⬇️⬇️玩摩托,惭愧,惭愧.