Build a Linux system from scratch, Linux from Scratch installation tips and experience

Ivon Huang
·
·
IPFS
·
LFS has to compile software and systems from scratch, which makes people feel the hardships of developing systems when Linux first came out in the 1980s.

Linux From Scratch teaches you to compile and install a Linux system from scratch. It is to compile the software and the Linux kernel completely from the source code, without the assistance of the package administrator, and even the file system structure is set by itself.

This article records the process and tricks of installing Linux From Scratch 11.2 system. It took about 2 days to see and implement, and X window system has not been installed.

## 1 Introduction

Linux From Scratch (LFS, literally translated as Linux from scratch) is a Linux installation manual, written by Gerard Beekmans and others, available for free on the official website .

(Click Read Online → Stable LFS to start reading)

LFS mainly teaches users how to compile and install Linux systems from the source code. There is not much theory in the whole book, and most of them are installed according to the instructions in the book. The content of this book is constantly being updated, and the versions of LFS-related tools have caught up with the latest Linux kernel. Users can also download the software source code "teaching materials" in the book from the LFS website.

In addition, there is no graphical interface after installing according to LFS. Also read the second episode "Beyond Linux From Scratch" to learn how to compile and configure the X Window System.

Although LFS has a simplified Chinese translation version, it is better to read the English version if you can.

## 2. LFS installation notes

Here are some tips for those who want to install LFS according to the steps in the book.


1. First of all, it is recommended to install Linux From Scratch through a Linux host. That is to say, cut a partition on the hard disk of an existing Linux computer or virtual machine to install LFS, and set up everything about LFS with chroot. The advantage of this is that you can directly copy and paste the instructions from the book.

My method is to use Gpared to cut a 64GB hard disk partition on the computer for installing LFS, the file system is EXT4, the boot partition of LFS is shared with the host computer, and UEFI is used to boot.


2. LFS only talks about the traditional BIOS boot method. When you go to Chapter 10.4 , users need to refer to the GRUB section of BLFS to learn how to switch to UEFI boot.


3. LFS has a total of 10 chapters, but you do not need to install LFS from the beginning to the end without shutting down. You can exit the chroot and then take a break. As long as it is confirmed that the LFS variable is still there after rebooting, then mount the LFS partition , and then follow the steps of Chapter 7.3 and Chapter 7.4 , chroot into the LFS system, and then continue the installation.


4. When you want to download the software source code in Chapter 3.1 , you can use wget-lists-sysv to download all the software and patches needed by LFS at one time:

 wget --input-file=https://www.linuxfromscratch.org/lfs/view/stable/wget-list-sysv --continue --directory-prefix=$LFS/sources
wget --input-file=$LFS/sources/wget-list-sysv --continue --directory-prefix=$LFS/sources


5. Chapter 4.5 mentions the "SBU" unit of measurement, which allows users to evaluate the compilation time of a certain software. All the calculations in the book are based on 1 thread. For example, Binutils is 1 SBU, and GCC is 11 SBU. You know that GCC compilation will take a long time. If your computer hardware is better, you can add the "-j" parameter when executing the `make` command to speed up the compilation. For example, my computer has 4 cores, so it is written as `make -j8`.


6. After entering Chapter 5, the software will be compiled. When the book says to compile a certain software, the user must manually switch to the `$LFS/sources` directory, decompress the corresponding software source code with tar, and switch to this directory to continue the operation. For example Chapter 5.2. Binutils-2.39 - Pass 1 :

 cd $LFS/sources
tar -xvf binutils-2.39.tar.xz
cd binutils-2.39
# Then follow the instructions in this chapter to compile the software


7. Chapter 8 After compiling the software in each chapter, there will be a step of `make check`, which cannot be skipped, because to check whether the compiled software is executed normally, you can add `-j8` to the instruction to speed up the speed.


8. The Pip3 installation kit in Chaper 8.50 always uses root. The Wheel of Chapter 8.51 is to decompress `wheel-0.37.1.tar.gz` and enter the directory before executing the `pip3 install` command.


9. Chapter 10.3 To compile the Linux kernel, it is recommended to enable the UEFI option. If the hard disk is NVME, you need to enable NVME config in the core, otherwise it will fail to mount at boot.


10. If you want to share the boot partition with the host, first mount the host's boot partition to the /boot directory of LFS, and then install the Linux kernel and GRUB. grub.cfg does not need to be adjusted manually, it can be generated automatically by `grub2-mkconfig -o /boot/grub/grub.cfg`. After rebooting into the BIOS, you will see the LFS boot options.

## write at the end

LFS requires people to compile all the software from scratch, which makes people feel the hardships of developing systems when Linux first came out in the 1980s.

I use chroot to install, and most of the time I just copy and paste the instructions... But I have compiled more than 50 software manually, and I roughly remember how to compile and install software from the source code. The most difficult part is the Linux kernel configuration. Sometimes I feel that I just copy the official Gentoo kernel configuration file and use it.

However, this is just the beginning. More than 50 softwares have been manually compiled for the system without graphics, and the sequel "Beyond Linux From Scratch" has more software to be compiled. After all, it's hard to use Linux as a desktop system without Windows X.

Let's meet next time, on the other side of Linux (Beyond).


Thank you for reading, and welcome to my Blog to see more free software information when you have time.

CC BY-NC-ND 2.0

Like my work? Don't forget to support and clap, let me know that you are with me on the road of creation. Keep this enthusiasm together!

Ivon Huang自由軟體、航空、20世紀歷史愛好者。 這裡記載的東西究竟會成為未來的碎片,在那最果之處,反射出匯集各處思念的光芒。 My Blog: https://ivonblog.com
  • Author
  • More

將suckless.org極簡網頁設計哲學付諸實現

Linux電腦好用的必裝軟體,從文書處理到玩遊戲一次滿足

半回憶錄形式的2022年Matters回顧問卷