目录
每次退出后,执行7.3.1. 挂载和填充 /dev、7.3.2. 挂载虚拟内核文件系统、7.4. 进入 Chroot 环境操作
第 8 章 安装基本系统软件
8.5. Glibc-2.37
以下错误可以忽略。
#make check结果
Summary of test results:
4 FAIL
5041 PASS
124 UNSUPPORTED
16 XFAIL
4 XPASS
make[1]: *** [Makefile:647: tests] Error 1
make[1]: Leaving directory '/sources/glibc-2.37'
make: *** [Makefile:9: check] Error 2
# fail 结果
FAIL: io/tst-lchmod
FAIL: math/test-double-vlen4-avx2-tan
FAIL: math/test-float-vlen8-avx2-acos
FAIL: misc/tst-ttyname
#xpass 结果
XPASS: elf/tst-ifunc-isa-1
XPASS: elf/tst-ifunc-isa-1-static
XPASS: elf/tst-ifunc-isa-2
XPASS: elf/tst-ifunc-isa-2-static
8.11. Readline-8.2
文档路径不对,重新创建一个
# 安装文档的目标路径不存在
(lfs chroot) root:/sources/readline-8.2# install -v -m644 doc/*.{ps,pdf,html,dvi} /usr/share/doc/readline-8.2
install: target '/usr/share/doc/readline-8.2': No such file or directory
# 创建路径,重新执行
(lfs chroot) root:/sources/readline-8.2# mkdir /usr/share/doc/readline-8.2
(lfs chroot) root:/sources/readline-8.2# install -v -m644 doc/*.{ps,pdf,html,dvi} /usr/share/doc/readline-8.2
8.18. Binutils-2.40
可以忽略的错误,其他错误需要检查前面的步骤。
# 12 个错误,可以忽略
(lfs chroot) root:/sources/binutils-2.40/build# grep '^FAIL:' $(find -name '*.log')
./gold/testsuite/test-suite.log:FAIL: weak_undef_test
./gold/testsuite/test-suite.log:FAIL: initpri3a
./gold/testsuite/test-suite.log:FAIL: script_test_1
./gold/testsuite/test-suite.log:FAIL: script_test_2
./gold/testsuite/test-suite.log:FAIL: justsyms
./gold/testsuite/test-suite.log:FAIL: justsyms_exec
./gold/testsuite/test-suite.log:FAIL: binary_test
./gold/testsuite/test-suite.log:FAIL: script_test_3
./gold/testsuite/test-suite.log:FAIL: tls_phdrs_script_test
./gold/testsuite/test-suite.log:FAIL: script_test_12i
./gold/testsuite/test-suite.log:FAIL: incremental_test_2
./gold/testsuite/test-suite.log:FAIL: incremental_test_5
8.26. GCC-12.2.0
找不到gettext,估计7.7. Gettext-0.21.1时,少执行一步cp操作或者整个漏掉了。
/usr/bin/msgfmt: line 202: cd: /sources/gettext-0.21.1/gettext-tools/src: No such file or directory
重新执行7.7. Gettext-0.21.1,make gcc成功。
# /sources路径下执行,解压,重新构建并安装gettext
(lfs chroot) root:/sources#tar -xf gettext-0.21.1.tar.xz
(lfs chroot) root:/sources# cd gettext-0.21.1
./configure --disable-shared
make
cp -v gettext-tools/src/{msgfmt,msgmerge,xgettext} /usr/bin
为了减少执行时间,设置MAKEFLAGS变量,允许4个作业。
export MAKEFLAGS='-j4'
在7.6. 创建必要的文件和符号链接 ,创建一个tester账号,用于运行测试。
# g++ 4个错误,gcc11个错误如下,与文档描述一致:
(lfs chroot) root:/sources/gcc-12.2.0/build# ../contrib/test_summary | grep -A7 Summ
=== g++ Summary ===
# of expected passes 229916
# of unexpected failures 4
# of unexpected successes 4
# of expected failures 2069
# of unsupported tests 9925
/sources/gcc-12.2.0/build/gcc/xg++ version 12.2.0 (GCC)
--
=== gcc Summary ===
# of expected passes 176194
# of unexpected failures 11
# of expected failures 1382
# of unresolved testcases 1
# of unsupported tests 2419
/sources/gcc-12.2.0/build/gcc/xgcc version 12.2.0 (GCC)
这部分每个包的介绍非常有价值。
第 9 章 系统配置
正在学习,9.1、9.3原理介绍,适合反复中英文对照阅读体会。
9.2. LFS-Bootscripts-20230101
安装过程同第8章中的包,在此记录操作过程,前提进入chroot环境。
#解压安装包
(lfs chroot) root:/sources# cd /sources/
(lfs chroot) root:/sources# tar -xf lfs-bootscripts-20230101.tar.xz
(lfs chroot) root:/sources# cd lfs-bootscripts-20230101
#查看 MakeFile
more Makefile
#执行安装
make install
#删除安装包
cd ..
(lfs chroot) root:/sources# rm -rf lfs-bootscripts-20230101
这样就准备好udev命令
9.4. 管理设备
创建自定义 Udev 规则
(lfs chroot) root:/sources# bash /usr/lib/udev/init-net-rules.sh
9.5. 一般网络配置
技巧:查看宿主系统的网络配置,再修改lfs的配置文件
9.5.1. 创建网络接口配置文件
这里宿主系统有两个网卡,默认网关走eth0的10.0.2.2,
(lfs chroot) root:/etc/sysconfig# ip route show
default via 10.0.2.2 dev eth0 proto dhcp metric 102
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15 metric 102
192.168.26.0/24 dev eth1 proto kernel scope link src 192.168.26.120 metric 101
对应lfs中eth0的配置,注意在
cd /etc/sysconfig/
cat > ifconfig.eth0 << "EOF"
ONBOOT=yes
IFACE=eth0
SERVICE=ipv4-static
IP=10.0.2.16
GATEWAY=10.0.2.2
PREFIX=24
BROADCAST=10.0.2.255
EOF
对应lfs中eth1的配置
cat > ifconfig.eth1 << "EOF"
ONBOOT=yes
IFACE=eth1
SERVICE=ipv4-static
IP=192.168.26.121
PREFIX=24
BROADCAST=192.168.26.255
EOF
9.5.2. 创建 /etc/resolv.conf 文件
在宿主系统中查看/etc/resolv.conf文件内容
-bash-5.1$ cat /etc/resolv.conf
# Generated by NetworkManager
search DHCP HOST
nameserver 192.168.1.1
nameserver 192.168.0.1
在chroot环境中,创建resolv.conf文件
cat > /etc/resolv.conf << "EOF"
# Begin /etc/resolv.conf
nameserver 192.168.1.1
nameserver 192.168.0.1
# End /etc/resolv.conf
EOF
第 10 章 使 LFS 系统可引导
10.2. 创建 /etc/fstab 文件
此处为防止引导时,/dev节点名称变化,根据10.4.4的建议,改为设备节点路径 PARTUUID=
<分区 UUID>形式,
cat > /etc/fstab << "EOF"
# Begin /etc/fstab
# file system mount-point type options dump fsck
# order
PARTUUID=713c732a-01 / ext4 defaults 1 1
PARTUUID=713c732a-02 swap swap pri=1 0 0
proc /proc proc nosuid,noexec,nodev 0 0
sysfs /sys sysfs nosuid,noexec,nodev 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
tmpfs /run tmpfs defaults 0 0
devtmpfs /dev devtmpfs mode=0755,nosuid 0 0
tmpfs /dev/shm tmpfs nosuid,nodev 0 0
# End /etc/fstab
EOF
10.3. Linux-6.1.11
此处用Liunux-6.1.29代替,没有使用单独boot的分区
进入/sources路径,记录操作如下
#解压内核包
(lfs chroot) root:/sources# tar -xf linux-6.1.29.tar.xz
(lfs chroot) root:/sources#cd linux-6.1.29
(lfs chroot) root:/sources/linux-6.1.29#make mrproper
(lfs chroot) root:/sources/linux-6.1.29# make menuconfig
#检查配置
(lfs chroot) root:/sources/linux-6.1.29# more .config | grep CONFIG_RELOCATABLE
CONFIG_RELOCATABLE=y
....
(lfs chroot) root:/sources/linux-6.1.29# more .config | grep CONFIG_IRQ_REMAP
CONFIG_IRQ_REMAP=y
#编译
make
#编译结果
Kernel: arch/x86/boot/bzImage is ready (#1)
LDS scripts/module.lds
CC [M] drivers/thermal/intel/x86_pkg_temp_thermal.mod.o
LD [M] drivers/thermal/intel/x86_pkg_temp_thermal.ko
CC [M] fs/efivarfs/efivarfs.mod.o
LD [M] fs/efivarfs/efivarfs.ko
CC [M] net/ipv4/netfilter/iptable_nat.mod.o
LD [M] net/ipv4/netfilter/iptable_nat.ko
CC [M] net/netfilter/nf_log_syslog.mod.o
LD [M] net/netfilter/nf_log_syslog.ko
CC [M] net/netfilter/xt_LOG.mod.o
LD [M] net/netfilter/xt_LOG.ko
CC [M] net/netfilter/xt_MASQUERADE.mod.o
LD [M] net/netfilter/xt_MASQUERADE.ko
CC [M] net/netfilter/xt_addrtype.mod.o
LD [M] net/netfilter/xt_addrtype.ko
CC [M] net/netfilter/xt_mark.mod.o
LD [M] net/netfilter/xt_mark.ko
CC [M] net/netfilter/xt_nat.mod.o
LD [M] net/netfilter/xt_nat.ko
# 安装内核模块
(lfs chroot) root:/sources/linux-6.1.29# make modules_install
INSTALL /lib/modules/6.1.29/kernel/drivers/thermal/intel/x86_pkg_temp_thermal.ko
INSTALL /lib/modules/6.1.29/kernel/fs/efivarfs/efivarfs.ko
INSTALL /lib/modules/6.1.29/kernel/net/ipv4/netfilter/iptable_nat.ko
INSTALL /lib/modules/6.1.29/kernel/net/netfilter/nf_log_syslog.ko
INSTALL /lib/modules/6.1.29/kernel/net/netfilter/xt_LOG.ko
INSTALL /lib/modules/6.1.29/kernel/net/netfilter/xt_MASQUERADE.ko
INSTALL /lib/modules/6.1.29/kernel/net/netfilter/xt_addrtype.ko
INSTALL /lib/modules/6.1.29/kernel/net/netfilter/xt_mark.ko
INSTALL /lib/modules/6.1.29/kernel/net/netfilter/xt_nat.ko
DEPMOD /lib/modules/6.1.29
#执行一些复制工作
cp -iv arch/x86/boot/bzImage /boot/vmlinuz-6.1.29-lfs-11.3
cp -iv System.map /boot/System.map-6.1.29
cp -iv .config /boot/config-6.1.29
install -d /usr/share/doc/linux-6.1.29
cp -r Documentation/* /usr/share/doc/linux-6.1.29
10.4. 使用 GRUB 设定引导过程
10.4.3. 设定 GRUB 配置
(lfs chroot) root:/# grub-install /dev/sdb
正在为 i386-pc 平台进行安装。
安装完成。没有报告错误。
10.4.4. 创建 GRUB 配置文件
在宿主系统中,查询文件uuid,分区uuid等信息
-bash-5.1$ lsblk -o UUID,PARTUUID,PATH,MOUNTPOINT
UUID PARTUUID PATH MOUNTPOINT
/dev/sda
8086e22e-a3fe-4caf-b9c4-0436ed51ea5e 02dcbede-01 /dev/sda1 /
29c894cf-5433-4aea-8ada-ccde59c393a4 02dcbede-02 /dev/sda2 [SWAP]
/dev/sdb
bed2add7-1eda-4238-bfae-be211092c403 713c732a-01 /dev/sdb1 /mnt/lfs
6561f7f2-44bf-4fbf-b554-198b636d4e30 713c732a-02 /dev/sdb2
2023-01-11-16-28-12-93 /dev/sr0
在chroot环境中,设置/boot/grub/grub.cfg文件,引导指向第二块硬盘,第一个分区
cat > /boot/grub/grub.cfg << "EOF"
# Begin /boot/grub/grub.cfg
set default=0
set timeout=5
insmod ext4
search --set=root --fs-uuid bed2add7-1eda-4238-bfae-be211092c403
menuentry "GNU/Linux, Linux 6.1.29-lfs-11.3" {
linux /boot/vmlinuz-6.1.29-lfs-11.3 root=PARTUUID=713c732a-01 ro
}
EOF
第 11 章 收尾工作
11.3. 重启系统
#退出 chroot 环境
(lfs chroot) root:/# logout
# 解除虚拟文件系统的挂载
-bash-5.1# umount -v $LFS/dev/pts
mountpoint -q $LFS/dev/shm && umount $LFS/dev/shm
umount -v $LFS/dev
umount -v $LFS/run
umount -v $LFS/proc
umount -v $LFS/sys
umount: /mnt/lfs/dev/pts 未挂载
umount: /mnt/lfs/dev 未挂载
umount: /mnt/lfs/run 未挂载
umount: /mnt/lfs/proc 未挂载
umount: /mnt/lfs/sys 未挂载
重启系统,virtualbox引导界面,按F12选择第二块硬盘引导,此处按数字2即可。
进入系统后
推荐阅读blfs的lfs后的配置问题。
配置OpenSSH-9.2p1,允许root登录,配置用户user