物理主机配置

物理主机 配置
CPU AMD Ryzen 7 6800H with Radeon Graphics (16) @ 3.20 GHz
RAM 16G LPDDR5 6400MHz
硬盘 512G SSD
OS名称 Microsoft Windows 11 10.0.22621 专业版
OS版本 10.0.22621/1265

虚拟机配置

虚拟机 配置
产品 VMware® Workstation 17 Pro
版本 17.0.0 build-20800274
配置 8核CPU 8GB内存
磁盘1 60GB
磁盘2 80GB
操作系统 Linux Mint 21.1 x86_64 Cinnamon Edition
Kernel 5.15.0-56-generic
Linux From Scratch版本 LFS 11.2 (systemd)

VMWare 中创建虚拟机, 安装好宿主系统, 这里选择的宿主系统是 Linux Mint 21.1 Cinnamon 桌面版。

Linux From Scratch(缩写LFS), 中文释意为“从零开始构建的 Linux”, 官方网站: https://linuxfromscratch.org/ , Linux From Scratch 手册的核心内容,是提供亲自设计和构建系统所需的背景知识和操作步骤。

环境准备

宿主系统 必须拥有下列软件,且 不能低于 给出的最低版本:

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
Bash-3.2 (/bin/sh 必须是到 bash 的符号链接或硬连接)

Binutils-2.13.1 (比 2.39 更新的版本未经测试,不推荐使用)

Bison-2.7 (/usr/bin/yacc 必须是到 bison 的链接,或者是一个执行 bison 的小脚本)

Coreutils-6.9

Diffutils-2.8.1

Findutils-4.2.31

Gawk-4.0.1 (/usr/bin/awk 必须是到 gawk 的链接)

GCC-4.8,包括 C++ 编译器 g++ (比 12.2.0 更新的版本未经测试,不推荐使用)。C 和 C++ 标准库 (包括头文件) 也必须可用,这样 C++ 编译器才能构建宿主环境的程序

Grep-2.5.1a

Gzip-1.3.12

Linux Kernel-3.2

内核版本的要求是为了符合第 5 章和第 8 章中编译 glibc 时开发者推荐的配置选项。udev 也要求一定的内核版本。

如果宿主内核比 3.2 更早,您需要将内核升级到较新的版本。升级内核有两种方法,如果您的发行版供应商提供了 3.2 或更新的内核软件包,您可以直接安装它。如果供应商没有提供一个足够新的内核包,或者您不想安装它,您可以自己编译内核。编译内核和配置启动引导器 (假设宿主使用 GRUB) 的步骤在第 10 章中。

M4-1.4.10

Make-4.0

Patch-2.5.4

Perl-5.8.8

Python-3.4

Sed-4.1.5

Tar-1.22

Texinfo-4.7

Xz-5.0.0

为了确定 宿主系统 拥有每个软件的 合适 版本,且能够编译程序,可以通过运行下列脚本进行各个软件版本的检测:

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
cat > version-check.sh << "EOF"
#!/bin/bash
# Simple script to list version numbers of critical development tools
export LC_ALL=C
bash --version | head -n1 | cut -d" " -f2-4
MYSH=$(readlink -f /bin/sh)
echo "/bin/sh -> $MYSH"
echo $MYSH | grep -q bash || echo "ERROR: /bin/sh does not point to bash"
unset MYSH

echo -n "Binutils: "; ld --version | head -n1 | cut -d" " -f3-
bison --version | head -n1

if [ -h /usr/bin/yacc ]; then
echo "/usr/bin/yacc -> `readlink -f /usr/bin/yacc`";
elif [ -x /usr/bin/yacc ]; then
echo yacc is `/usr/bin/yacc --version | head -n1`
else
echo "yacc not found"
fi

echo -n "Coreutils: "; chown --version | head -n1 | cut -d")" -f2
diff --version | head -n1
find --version | head -n1
gawk --version | head -n1

if [ -h /usr/bin/awk ]; then
echo "/usr/bin/awk -> `readlink -f /usr/bin/awk`";
elif [ -x /usr/bin/awk ]; then
echo awk is `/usr/bin/awk --version | head -n1`
else
echo "awk not found"
fi

gcc --version | head -n1
g++ --version | head -n1
grep --version | head -n1
gzip --version | head -n1
cat /proc/version
m4 --version | head -n1
make --version | head -n1
patch --version | head -n1
echo Perl `perl -V:version`
python3 --version
sed --version | head -n1
tar --version | head -n1
makeinfo --version | head -n1 # texinfo version
xz --version | head -n1

echo 'int main(){}' > dummy.c && g++ -o dummy dummy.c
if [ -x dummy ]
then echo "g++ compilation OK";
else echo "g++ compilation failed"; fi
rm -f dummy.c dummy
EOF

bash version-check.sh

当前虚拟机内 Linux Mint 21.1 运行结果如下:

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
laohoo@laohoo-Virtual-Machine:~/Downloads$ bash version-check.sh
bash, version 5.1.16(1)-release
/bin/sh -> /usr/bin/dash
ERROR: /bin/sh does not point to bash
Binutils: (GNU Binutils for Ubuntu) 2.38
bison (GNU Bison) 3.8.2
/usr/bin/yacc -> /usr/bin/bison.yacc
Coreutils: 8.32
diff (GNU diffutils) 3.8
find (GNU findutils) 4.8.0
GNU Awk 5.1.0, API: 3.0 (GNU MPFR 4.1.0, GNU MP 6.2.1)
/usr/bin/awk -> /usr/bin/gawk
gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
version-check.sh: line 35: g++: command not found
grep (GNU grep) 3.7
gzip 1.10
Linux version 5.15.0-41-generic (buildd@lcy02-amd64-065) (gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #44-Ubuntu SMP Wed Jun 22 14:20:53 UTC 2022
m4 (GNU M4) 1.4.18
GNU Make 4.3
GNU patch 2.7.6
Perl version='5.34.0';
Python 3.10.4
sed (GNU sed) 4.8
tar (GNU tar) 1.34
version-check.sh: line 46: makeinfo: command not found
xz (XZ Utils) 5.2.5
version-check.sh: line 49: g++: command not found
g++ compilation failed

存在的问题

  1. shell 脚本未指向 bash 而是指向 dash:
1
2
/bin/sh -> /usr/bin/dash
ERROR: /bin/sh does not point to bash

执行以下命令进行修复:

1
sudo ln -sf bash /bin/sh
  1. g++ 没有安装
1
2
version-check.sh: line 49: g++: command not found
g++ compilation failed

执行以下命令安装 g++:

1
sudo apt install g++
  1. makeinfo 没有安装
1
version-check.sh: line 46: makeinfo: command not found

执行以下命令安装 texinfo:

1
sudo apt install texinfo

重新检查软件版本

再次执行命令进行环境检测: bash version-check.sh, 结果如下:

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
laohoo@laohoo-Virtual-Machine:~/Downloads$ bash version-check.sh
bash, version 5.1.16(1)-release
/bin/sh -> /usr/bin/bash
Binutils: (GNU Binutils for Ubuntu) 2.38
bison (GNU Bison) 3.8.2
/usr/bin/yacc -> /usr/bin/bison.yacc
Coreutils: 8.32
diff (GNU diffutils) 3.8
find (GNU findutils) 4.8.0
GNU Awk 5.1.0, API: 3.0 (GNU MPFR 4.1.0, GNU MP 6.2.1)
/usr/bin/awk -> /usr/bin/gawk
gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
g++ (Ubuntu 11.2.0-19ubuntu1) 11.2.0
grep (GNU grep) 3.7
gzip 1.10
Linux version 5.15.0-41-generic (buildd@lcy02-amd64-065) (gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #44-Ubuntu SMP Wed Jun 22 14:20:53 UTC 2022
m4 (GNU M4) 1.4.18
GNU Make 4.3
GNU patch 2.7.6
Perl version='5.34.0';
Python 3.10.4
sed (GNU sed) 4.8
tar (GNU tar) 1.34
texi2any (GNU texinfo) 6.8
xz (XZ Utils) 5.2.5
g++ compilation OK

LFS需要的各软件版本没问题

参考资料:

  1. Linux From Scratch Version 11.2

  2. Linux From Scratch 版本 11.2-systemd-中文翻译版