Welcome to Linux From Scratch!

官站

2022-3-21 23:00开始

宿主机:VMware16中运行Ubuntu20.04

$ sudo apt update
$ sudo apt upgrade
$ lsb_release  -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.4 LTS
Release:        20.04
Codename:       focal
$ uname -a
Linux virtual-machine 5.13.0-37-generic #42~20.04.1-Ubuntu SMP Tue Mar 15 15:44:28 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

一、准备宿主系统

1、环境检查

创建软件检测脚本

$ 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
bash, version 5.0.17(1)-release
/bin/sh -> /usr/bin/dash
ERROR: /bin/sh does not point to bash
Binutils: (GNU Binutils for Ubuntu) 2.34
version-check.sh: line 10: bison: command not found
yacc not found
Coreutils:  8.30
diff (GNU diffutils) 3.7
find (GNU findutils) 4.7.0
version-check.sh: line 21: gawk: command not found
/usr/bin/awk -> /usr/bin/mawk
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
version-check.sh: line 30: g++: command not found
grep (GNU grep) 3.4
gzip 1.10
Linux version 5.13.0-37-generic (buildd@lcy02-amd64-111) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #42~20.04.1-Ubuntu SMP Tue Mar 15 15:44:28 UTC 2022
version-check.sh: line 34: m4: command not found
version-check.sh: line 35: make: command not found
GNU patch 2.7.6
Perl version='5.30.0';
Python 3.8.10
sed (GNU sed) 4.7
tar (GNU tar) 1.30
version-check.sh: line 41: makeinfo: command not found
xz (XZ Utils) 5.2.4
version-check.sh: line 43: g++: command not found
g++ compilation failed
  1. 修改shell为bash:sudo dpkg-reconfigure dash 选择no
  2. 安装ubuntu开发环境:sudo apt-get install build-essential
  3. 安装bison、yacc、gawk、makeinfo:sudo apt install bison gawk texinfo
  4. 再执行软件包检测全部通过
$ bash version-check.sh
bash, version 5.0.17(1)-release
/bin/sh -> /usr/bin/bash
Binutils: (GNU Binutils for Ubuntu) 2.34
bison (GNU Bison) 3.5.1
/usr/bin/yacc -> /usr/bin/bison.yacc
Coreutils:  8.30
diff (GNU diffutils) 3.7
find (GNU findutils) 4.7.0
GNU Awk 5.0.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.2.0)
/usr/bin/awk -> /usr/bin/gawk
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
grep (GNU grep) 3.4
gzip 1.10
Linux version 5.13.0-37-generic (buildd@lcy02-amd64-111) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #42~20.04.1-Ubuntu SMP Tue Mar 15 15:44:28 UTC 2022
m4 (GNU M4) 1.4.18
GNU Make 4.2.1
GNU patch 2.7.6
Perl version='5.30.0';
Python 3.8.10
sed (GNU sed) 4.7
tar (GNU tar) 1.30
texi2any (GNU texinfo) 6.7
xz (XZ Utils) 5.2.4
g++ compilation OK

2、为LFS创建分区

再这里我直接再虚拟机里面添加了一块50G的硬盘。然后分了两个区,分别是用来给LFS作为/boot分区的500M空间和作为/分区的20G空间。

$ sudo fdisk /dev/sdb
命令(输入 m 获取帮助): p
Disk /dev/sdb:50 GiB,53687091200 字节,104857600 个扇区
Disk model: VMware Virtual S
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0c8cd79a

命令(输入 m 获取帮助): n
分区类型
   p   主分区 (0个主分区,0个扩展分区,4空闲)
   e   扩展分区 (逻辑分区容器)
选择 (默认 p): p
分区号 (1-4, 默认  1):
第一个扇区 (2048-104857599, 默认 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-104857599, 默认 104857599): +500M

创建了一个新分区 1,类型为“Linux”,大小为 500 MiB。

命令(输入 m 获取帮助): p
Disk /dev/sdb:50 GiB,53687091200 字节,104857600 个扇区
Disk model: VMware Virtual S
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0c8cd79a

设备       启动  起点    末尾    扇区  大小 Id 类型
/dev/sdb1        2048 1026047 1024000  500M 83 Linux

命令(输入 m 获取帮助): n
分区类型
   p   主分区 (1个主分区,0个扩展分区,3空闲)
   e   扩展分区 (逻辑分区容器)
选择 (默认 p): p
分区号 (2-4, 默认  2):
第一个扇区 (1026048-104857599, 默认 1026048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (1026048-104857599, 默认 104857599): +20G

创建了一个新分区 2,类型为“Linux”,大小为 20 GiB。

命令(输入 m 获取帮助): p
Disk /dev/sdb:50 GiB,53687091200 字节,104857600 个扇区
Disk model: VMware Virtual S
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0c8cd79a

设备       启动    起点     末尾     扇区  大小 Id 类型
/dev/sdb1          2048  1026047  1024000  500M 83 Linux
/dev/sdb2       1026048 42969087 41943040   20G 83 Linux

命令(输入 m 获取帮助): w
分区表已调整。
将调用 ioctl() 来重新读分区表。
正在同步磁盘。

格式化这俩分区