Linux From Scratch 9.0 (LFS) Precautions in the process of customizing your own Linux distribution

0, this article agreed

0.0. Reference content

    Special thanks to the " Linux China-LCTT-LFS Translation Team " for the translation of the LFS manual. The official website of the group is https://lctt.github.io and the URL of the LFS manual is https://lctt.github.io/LFS-BOOK .


    The LFS manual used in this article is the Linux From Scratch (Simplified Chinese version)-9.0-SysV HTML version translated by the team .


It is strongly recommended to refer to the HTML version of the LFS manual for the operation process, for the reason, see section 1.1. of this article .

0.1. Input and output styles

    The commands entered and output results in the Linux environment are expressed in the following style (the content is consistent with the terminal display):

lfs@lfs-VirtualBox:~$ echo "hello world"

0.2. Matters needing attention

    Use the following style to express:

Here are the precautions,

0.3. Host configuration

    The physical machines used in this article are:

HP ZHAN 66 Pro 14 G3
CPU: i7-10510U
RAM: 16GB
Operating system: Windows10-64

    LFS compilation environment:

VirualBox-6.1 & Ubuntu-Desktop-20.04 (If you use the server version, please execute the "mount --bind /boot /mnt/lfs/boot" command in Chapter 8.3 of the LFS manual, and use the terminal software to connect to the host through ssh to execute The order)

    The software versions in the LFS compilation environment:

bash, version 5.0.17(1)-release
/bin/sh -> /usr/bin/bash
Binutils: GNU ld (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-17ubuntu1~20.04) 9.3.0
g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
(Ubuntu GLIBC 2.31-0ubuntu9.2) 2.31
grep (GNU grep) 3.4
gzip 1.10
Linux version 5.4.0-42-generic (buildd@lgw01-amd64-038) (gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2)) #46-Ubuntu SMP Fri Jul 10 00:24:02 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.5
sed (GNU sed) 4.7
tar (GNU tar) 1.30
texi2any (GNU texinfo) 6.7
xz (XZ Utils) 5.2.4
g++ compilation OK

1. A little understanding of LFS

1.0. About LFS cross compilation environment

    Essentially, in the host operating system, another operating system that can be used on other machines is compiled, that is, cross-compilation.


    The complication is that it is necessary to prevent the compilation result from being affected by the host's environment variables and software version, causing the link of the compilation result, environment variables, etc. to point to the host, so that the compilation result cannot be used normally on other machines.


    In order to avoid this situation (environmental pollution), all operations in the LFS manual are actually divided into three steps:

  • The first step is to construct a set of tools carefully (strictly set their symbolic links, compilation parameters, etc.).
  • The second step is to use this set of tools that will not cause environmental pollution to compile a basic cross-compilation environment.
  • The third step , when the basic cross-compilation environment is built, the LFS manual guides us to switch to this environment through the chroot command, and use the most basic compilation tools in the environment to compile other software we need.

The last picture is to facilitate understanding:
Insert picture description here

1.1. About the operation steps

    The shell code part in the LFS manual (as shown in the figure below), just copy and paste it and execute it. But it must be noted that if the LFS manual you refer to is a PDF version, the code part below may not have line breaks (that is, \n in Linux, or \r\n in Windows), or some symbols cannot be copied (Such as the English-symbol in some chapters). Again, it is strongly recommended to refer to the html version of the LFS manual for the operation process .

Insert picture description here
    About the entire operation process of the LFS manual, it is roughly understood as the following figure:

Insert picture description here

2. Several places to pay attention to in the LFS manual

2.0. About software version check

    In the chapter "2.2. Host System Requirements" of the LFS manual, the software version check script given cannot correctly display the version of Binutils under ubuntu20.04. You need to modify the script content and delete the yellow highlighter in the figure below. That's it (that is, delete the original | cut -d" "-f3- ). Otherwise, the output version of Binutils is: " Binutils: GNU ", and the output version after modification is: " Binutils: GNU ld (GNU Binutils for Ubuntu) 2.34 ".

Insert picture description here

2.1. About partitions

    In the chapter "2.4. Creating a new partition" of the LFS manual, it is recommended to use a new partition for building an LFS system, and it is recommended to create a swap partition, /boot partition and other partitions. This article does not do this, but mounts a 50GB New hard disk /dev/sdb, and create an entire primary partition /dev/sdb1 for it, and then format it with ext4 format.

2.2. About compiling and installing packages

With particular emphasis on

  • When compiling and installing the software package, you need to enter the $LFS/sources directory first.

  • Each time you compile the software, first use the tar command to decompress the target software (tar -xf for xz files, tar -jxf for bz2 files, and tar -zxf for gz files).

  • Then use the cd command to enter the software source code directory.

  • Then follow the LFS prompts.

  • Finally, after the operation is completed, use the cd …or cd …/… command to return to the $LFS/sources directory, and use the rm -rf command to remove the software source code directory (if the LFS manual does not expressly need to keep it).

  • The clear command clears the screen display ( otherwise it will be suspected that the terminal will crash because of too much content )

  • LFS manual page turn

  • Starting from the chapter "6.7. Linux-5.2.8 API Header File", please use the cd command to enter the $LFS/sources directory for operation

  • It is known that the following commands in the "6.80. Cleanup" chapter cannot be executed correctly

logout

chroot "$LFS" /usr/bin/env -i          \
    HOME=/root TERM="$TERM"            \
    PS1='(lfs chroot) \u:\w\$ '        \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin \
    /bin/bash --login

This is because this article uses the desktop system login of ubuntu-desktop, and then opens a Terminal in the desktop system to execute the command. The shell currently executing the command is not a login shell, so an error will be reported, and the exit failure will further lead to the failure to find $ LFS environment variables and their corresponding directories:

(lfs chroot) root:/usr/lib# logout
bash: logout: not login shell: use `exit'
(lfs chroot) root:/usr/lib# 
(lfs chroot) root:/usr/lib# chroot "$LFS" /usr/bin/env -i          \
>     HOME=/root TERM="$TERM"            \
>     PS1='(lfs chroot) \u:\w\$ '        \
>     PATH=/bin:/usr/bin:/sbin:/usr/sbin \
>     /bin/bash --login
chroot: cannot change root directory to '': No such file or directory

So we need to use the "exit" command instead of the logout command. The modified command is as follows:

exit

chroot "$LFS" /usr/bin/env -i          \
    HOME=/root TERM="$TERM"            \
    PS1='(lfs chroot) \u:\w\$ '        \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin \
    /bin/bash --login

2.3. About installing linux header files

    In the chapters of "5.6. Linux-5.2.8 API Header File" and "6.7. Linux-5.2.8 API Header File" in the original text of the LFS manual, the preparation steps are not described (as shown in the figure below).

Insert picture description here


    In fact, this is the same as section 2.2. of this article, first unzip the linux kernel source package, then enter it, and then execute it. code show as below:
lfs@lfs-VirtualBox:/mnt/lfs/sources$ tar -xf linux-5.2.8.tar.xz
lfs@lfs-VirtualBox:/mnt/lfs/sources$ cd linux-5.2.8

2.4. About local character set support in the chapter "7.7. Bash Shell Startup File"

Use the following command to view the supported character sets:

locale -a

This article can only view zh_CN.gb18030, therefore, the script for creating /etc/profile in the original LFS manual is modified as follows:

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

export LANG=zh_CN.gb18030

# End /etc/profile
EOF

2.5. Create fstab file in chapter "8.2. Create /etc/fstab File"

Since this article uses a single partition, the script for creating the fstab file in section 8.2 is modified as follows:

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

# file system  mount-point  type     options             dump  fsck
#                                                              order

/dev/sdb1     /            <fff>    defaults            1     1
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

# End /etc/fstab
EOF

2.6. Chapter "8.3. Linux-5.2.8"

Unzip the linux-5.2.8.tar.xz compressed package in the /sources directory, and then cd to enter, first execute the make mrproper command, then execute the make defconfig command, and then execute the make menuconfig command, and then follow the recommendations of LFS to complete the kernel configuration.

It is important to note that the following commands should not be executed in the chroot environment:

mount --bind /boot /mnt/lfs/boot

The original text is very clear and must be executed under the host. The host of this article is the ubuntu-desktop environment, and then open a Terminal to execute it.


There is another point to note in this chapter, the following commands do not need to be modified (even if you are on an X86_64 system, you do not need to modify):

cp -iv arch/x86/boot/bzImage /boot/vmlinuz-5.2.8-lfs-9.0

The reason is because the arch/x86_64/boot/bzImage file is actually a link, and the path pointed to is.../.../x86/boot/bzImage, if the command is modified here, it points to the arch/x86_64 directory, which will cause subsequent Startup failed.

2.7. "8.4. Use GRUB to set the boot process" chapter boot settings

First of all, the command grub-install /dev/sda is not executed in this article.
Secondly, before executing the following command, make a backup of /boot/grub/grub.cfg to /boot/grub/grub.cfg.bak.
Finally, according to the description of the LFS manual (as shown below)
Insert picture description here

The /dev/sdb1 used in this article should be set to (hd1,1) in grub, and root points to /dev/sdb1.

The original script to create the /boot/grub/grub.cfg file is modified as follows:

cat > /boot/grub/grub.cfg << "EOF"
# Begin /boot/grub/grub.cfg
set default=0
set timeout=5

insmod ext2
set root=(hd1,1)

menuentry "GNU/Linux, Linux 5.2.8-lfs-9.0" {
        linux   /boot/vmlinuz-5.2.8-lfs-9.0 root=/dev/sdb1 ro
}
EOF

2.8. About the failure of the test suite

2.8.1. Chapter "6.9. Glibc-2.30"

    Refer to this article for LFS compilation. When operating in the chapter of the LFS manual "6.9. Glibc-2.30", you will find the known test failure items described in LFS inet/tst-idna_name_classify and misc/tst-ttyname, and appear in the LFS manual at the same time Tests not described fail nptl/tst-mutex10 . However, in the follow-up actual operation, it did not produce a fatal impact. This is proposed here to see the after-effects.

The specific test results are output as follows:

UNSUPPORTED: elf/tst-audit10
UNSUPPORTED: elf/tst-avx512
UNSUPPORTED: elf/tst-ldconfig-bad-aux-cache
UNSUPPORTED: elf/tst-pldd
XPASS: elf/tst-protected1a
XPASS: elf/tst-protected1b
FAIL: inet/tst-idna_name_classify
UNSUPPORTED: math/test-double-libmvec-alias-avx512
UNSUPPORTED: math/test-double-libmvec-alias-avx512-main
UNSUPPORTED: math/test-double-libmvec-sincos-avx512
UNSUPPORTED: math/test-float-libmvec-alias-avx512
UNSUPPORTED: math/test-float-libmvec-alias-avx512-main
UNSUPPORTED: math/test-float-libmvec-sincosf-avx512
UNSUPPORTED: misc/tst-pkey
FAIL: misc/tst-ttyname
UNSUPPORTED: nptl/test-cond-printers
UNSUPPORTED: nptl/test-condattr-printers
UNSUPPORTED: nptl/test-mutex-printers
UNSUPPORTED: nptl/test-mutexattr-printers
UNSUPPORTED: nptl/test-rwlock-printers
UNSUPPORTED: nptl/test-rwlockattr-printers
FAIL: nptl/tst-mutex10
UNSUPPORTED: nss/tst-nss-db-endgrent
UNSUPPORTED: nss/tst-nss-db-endpwent
UNSUPPORTED: nss/tst-nss-files-hosts-long
UNSUPPORTED: nss/tst-nss-test3
UNSUPPORTED: resolv/tst-resolv-ai_idn
UNSUPPORTED: resolv/tst-resolv-ai_idn-latin1
Summary of test results:
      3 FAIL
   6070 PASS
     23 UNSUPPORTED
     17 XFAIL
      2 XPASS
make[1]: *** [Makefile:412: tests] Error 1
make[1]: Leaving directory '/sources/glibc-2.30'
make: *** [Makefile:9: check] Error 2

2.8.2. Chapter "6.21. GCC-9.2.0"

The LFS manual "6.21. GCC-9.2.0" describes 6 known failures, and 8 failures in this article, but the correct verification results were obtained in the subsequent verification [Requesting program interpreter: /lib64/ld-linux- x86-64.so.2], according to the description of LFS and some other information, these failures may be caused by language environment, time issues, CPU instruction set issues, etc., so this issue will not be investigated for the time being. In addition, this chapter takes a total of 4 hours, so be patient. The test report is as follows:

(lfs chroot) root:/sources/gcc-9.2.0/build# ../contrib/test_summary
gawk: cmd. line:36: warning: regexp escape sequence `\=' is not a known regexp operator
cat <<'EOF' |
LAST_UPDATED: Obtained from SVN: tags/gcc_9_2_0_release revision 274275

Native configuration is x86_64-pc-linux-gnu

		=== g++ tests ===


Running target unix

		=== g++ Summary ===

# of expected passes		134787
# of expected failures		527
# of unsupported tests		5921
/sources/gcc-9.2.0/build/gcc/xg++  version 9.2.0 (GCC) 

		=== gcc tests ===


Running target unix
FAIL: gcc.target/i386/pr57193.c scan-assembler-times movdqa 2
FAIL: gcc.target/i386/pr90178.c scan-assembler-times xorl[\\\\t ]*\\\\%eax,[\\\\t ]*%eax 1

		=== gcc Summary ===

# of expected passes		139439
# of unexpected failures	2
# of expected failures		527
# of unsupported tests		2151
/sources/gcc-9.2.0/build/gcc/xgcc  version 9.2.0 (GCC) 

		=== libatomic tests ===


Running target unix

		=== libatomic Summary ===

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


Running target unix

		=== libgomp Summary ===

# of expected passes		2316
# of expected failures		2
# of unsupported tests		210
		=== libitm tests ===


Running target unix

		=== libitm Summary ===

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


Running target unix
FAIL: 22_locale/time_get/get_time/char/2.cc execution test
FAIL: 22_locale/time_get/get_time/char/wrapped_env.cc execution test
FAIL: 22_locale/time_get/get_time/char/wrapped_locale.cc execution test
FAIL: 22_locale/time_get/get_time/wchar_t/2.cc execution test
FAIL: 22_locale/time_get/get_time/wchar_t/wrapped_env.cc execution test
FAIL: 22_locale/time_get/get_time/wchar_t/wrapped_locale.cc execution test
FAIL: experimental/net/internet/resolver/ops/lookup.cc execution test
FAIL: experimental/net/internet/resolver/ops/reverse.cc execution test

		=== libstdc++ Summary ===

# of expected passes		12892
# of unexpected failures	8
# of expected failures		78
# of unsupported tests		380

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

The verification results are as follows:

(lfs chroot) root:/sources/gcc-9.2.0/build# echo 'int main(){}' > dummy.c
(lfs chroot) root:/sources/gcc-9.2.0/build# cc dummy.c -v -Wl,--verbose &> dummy.log
(lfs chroot) root:/sources/gcc-9.2.0/build# readelf -l a.out | grep ': /lib'
      [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]

3. The construction and precautions of the actual operating environment

3.0. Virtual machine operating system installation

  • Install Oracle VitrualBox
  • Download the ISO file of ubuntu20.04-desktop
  • VXBOX adds a new virtual machine ubuntu20.04, memory settings 8GB, CPU 4 cores, the first hard disk 10GB, the second hard disk 50GB
  • Choose English to install (to avoid all system errors about language that may appear later )
  • Choose minimal installation ( try to avoid unnecessary software to bring system errors )
  • Install the system to a 10G hard disk (/dev/sda)
  • ubuntu installation is complete
  • fdisk -l to view available hard disks (50GB hard disk is /dev/sdb, and there is no file system at this time)
  • fdisk /dev/sdb to create a partition (Enter n, press Enter all the way to the default value, after completion, press Enter to save and exit)
  • mkfs.ext4 /dev/sdb1 format partition
  • Create /mnt/lfs directory
  • Modify the /etc/fstab file, add mount information, and mount the 50G hard disk /dev/sdb1 to /mnt/lfs
  • Install gcc, make, perl and other necessary dependent software to install VXBOX enhanced functions
  • Install VXBOX enhanced functions ( must be installed, various unknowable situations may occur when using virtual terminals. This article will directly operate the compilation process in the virtual machine to ensure no restart, no tty disconnection and other interference. At the same time, the LFS manual is in the physical Open in the host, and use the enhanced function of VXBOX to paste the commands in the physical host into the Terminal of the virtual machine )
  • Physical machine control panel -> hardware and sound -> power options -> change plan settings -> turn on the power -> never turn off the display, never sleep -> change advanced power settings -> power button and lid -> close the lid Operation -> Power on -> Take no action -> OK -> Save changes
  • ubuntu虚拟机->Settings ->Privacy-> Screen Lock ->Blank Screen Delay -> Never
  • If you need to temporarily suspend the compilation, please wait for the current software package compilation or installation step to finish, use VXbox's mirroring function, first back up a current mirror, and then click the close button in the upper right corner of the ubuntu virtual machine, and the pop-up confirmation page selects suspend Function to avoid the risk of failure that may be caused by restart.

3.0. Virtual Machine Backup

It is recommended to use the snapshot function of vxbox to backup the current compilation environment after the following chapters are completed:

  • After the requirements of the chapter "2.2. Host System Requirements" are passed
  • After the chapter of "5.10. GCC-9.2.0-Second Pass" is completed
  • After the chapter of "5.36. Change Owner" is completed
  • After the chapter of "6.21. GCC-9.2.0" is completed
  • After the chapter of "6.77. Eudev-3.2.8" is completed
  • After the chapter "7.9. Creating the /etc/shells file" is completed, you must back up here, because the subsequent grub configuration may not be configured correctly at one time

4. LFS operation process record

In the LFS manual, CTRL+C
switch to ubuntu environment, CTRL+V
then, the result is as follows:
Insert picture description here
Insert picture description here

5. Postscript

There may be some minor problems. For example, the virtual machine has dual network cards. I forgot about this during cross-compilation and need to be adjusted later.
If netizens have any doubts about the original description of LFS when operating, you can leave a message or private message to study and study together.
In addition, the entire build process of this LFS custom release is about 12 hours, for reference only.

Guess you like

Origin blog.csdn.net/crazy_rays/article/details/112647592