Linux From Scratch
LFS: http://www.linuxfromscratch.org/lfs/
Chinese Book: 中文翻译版
宿主系统需求
Host OS: Ubuntu 20.04
root
$ sudo passwd root
New password:
Retype new password:
passwd: password updated successfully
$ su - root
#
- Bash-3.2 (/bin/sh 必须是到 bash 的符号链接或硬连接)
# ls -l /bin/sh
lrwxrwxrwx 1 root root 4 9月 2 21:13 /bin/sh -> dash
# rm /bin/sh
# ln -s /bin/bash /bin/sh
# ls -l /bin/sh
lrwxrwxrwx 1 root root 9 9月 3 10:50 /bin/sh -> /bin/bash
-
Binutils-2.25 (比 2.35 更新的版本未经测试,不推荐使用)
-
Bison-2.7 (/usr/bin/yacc 必须是到 bison 的链接,或者是一个执行 bison 的小脚本)
-
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-6.2 包括 C++ 编译器, g++ (比 10.2.0 更新的版本未经测试,不推荐使用)
-
Glibc-2.11 (比 2.32 更新的版本未经测试,不推荐使用)
-
Grep-2.5.1a
-
Gzip-1.3.12
-
Linux Kernel-3.2
内核版本的要求是为了符合第 6 章中编译 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
cat version-check.sh
#!/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
bzip2 --version 2>&1 < /dev/null | head -n1 | cut -d" " -f1,6-
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
ldd --version | head -n1 | cut -d" " -f2- # glibc version
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
bash bash version-check.sh
分区 GPT
sudo cfdisk
Device | Size | Type | Mount |
---|---|---|---|
/dev/sda1 | 100M | ext2 | /boot |
/dev/sda2 | 4G | swap | - |
/dev/sda3 | 35.9G | ext4 | / |
mkfs -v -t ext2 /dev/sda1
mkswap /dev/sda2
swapon /dev/sda2
mkfs -v -t ext4 /dev/sda3
GParted Live on USB
Windows Method A: Tuxboot
- Download Tuxboot on your MS Windows computer.
- Follow the USB setup with MS Windows instructions to install GParted Live on your USB flash drive.
Gpared_disk.png
version
./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
bzip2, Version 1.0.8, 13-Jul-2019.
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.3.0-10ubuntu2) 9.3.0
g++ (Ubuntu 9.3.0-10ubuntu2) 9.3.0
(Ubuntu GLIBC 2.31-0ubuntu9) 2.31
grep (GNU grep) 3.4
gzip 1.10
Linux version 5.4.0-47-generic (buildd@lcy01-amd64-014) (gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2)) #51-Ubuntu SMP Fri Sep 4 19:50:52 UTC 2020
m4 (GNU M4) 1.4.18
GNU Make 4.2.1
GNU patch 2.7.6
Perl version='5.30.0';
Python 3.8.2
sed (GNU sed) 4.7
tar (GNU tar) 1.30
texi2any (GNU texinfo) 6.7
xz (XZ Utils) 5.2.4
g++ compilation OK
glibc
collect2: error: ld returned 1 exit status
case $(uname -m) in
i?86) ln -sfv ld-linux.so.2 $LFS/lib/ld-lsb.so.3
;;
x86_64) ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64
ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64/ld-lsb-x86-64.so.3
;;
esac
ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64
ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64/ld-lsb-x86-64.so.3
gcc
../../../libstdc++-v3/src/c++98/strstream.cc:324:63: error: 'INT_MAX' was not declared in this scope
source ~/.bashrc
grub
# grub-install /dev/sda --target i386-pc
正在为 i386-pc 平台进行安装。
grub-install:警告: this GPT partition label contains no BIOS Boot Partition; embedding won't be possible.
grub-install:警告: 无法嵌入。在此次安装中 GRUB 只能通过使用块列表安装。但是块列表是不可信赖的,不推荐使用。.
grub-install:错误: 停止进行块列表安装.
http://www.linuxfromscratch.org/blfs/view/svn/postlfs/parted.html
parted /dev/sda set 1 bios_grub on
parted /dev/sda print
grub-install /dev/sda --target i386-pc
Interface eth0 doesn't exist
eth0.jpg注意
如果没有使用前一节描述的自定义命名策略,udev 会根据系统物理特征命名网卡接口,例如enp2s1
。如果您不能确定接口名,可以在引导您的LFS
系统后使用ip link
或ls /sys/class/net
命令确认。
参考:http://www.linuxfromscratch.org/lfs/view/8.4/chapter07/network.html
cd /etc/sysconfig/
cat > ifconfig.enp2s0 << "EOF"
ONBOOT=yes
IFACE=enp2s0
SERVICE=ipv4-static
IP=192.168.1.222
GATEWAY=192.168.1.1
PREFIX=24
BROADCAST=192.168.1.255
EOF
ping
cat > /etc/resolv.conf << "EOF"
# Begin /etc/resolv.conf
nameserver 192.168.1.1
nameserver 8.8.8.8
# End /etc/resolv.conf
EOF
BLFS
curl
SSL certificate problem: unable to get local issuer certificate
https://curl.haxx.se/docs/sslcerts.html
curl https://curl.haxx.se/ca/cacert.pem --output cacert.pem
scp cacert.pem xxx@lfs:/etc/curlssl/cacert.pem
export CURL_CA_BUNDLE=/etc/curlssl/cacert.pem
https://mirror-hk.koddos.net/blfs/10.0/u/unzip60.tgz