Linux From Scratch Compilation Progress(System Preparation)
Linux From Scratch (System Preparation)
This article provides a brief introduction to partition-related knowledge in LFS . Personally, I believe that the content covered in this section is quite valuable and worth understanding. Many subsequent tasks mainly involve compiling various components, and so on. If you are interested in learning about the specific compilation process, application, and principles of each package, you can refer to the relevant content in the LFS/BLFS manual. The manual is regularly updated at each stage, and there may be some minor differences in the compilation methods. Paying attention to these distinctions will help avoid significant issues.
- First, we need to have a host operating system. Personally, I am using the AlmaLinux system . To avoid partitioning our main system and risking damage, it is more cost-effective to use VirtualBox as a virtualization software to set up the host system. Alternatively, we can use VMware on Windows for system setup. In this case, we will use the Gentoo live image file for the host system. This allows for easier packaging of the image and partitioning. VirtualBox provides executable installation files for both Windows and Linux. For Debian and RedHat-based operating systems, software installation can be done directly through the dpkg or rpm package managers.
- Next, it is important to develop a good habit of taking timely snapshots after completing each phase of operations in the virtual machine. Additionally, during the process of preparing the host system with Gentoo, it is recommended to perform all operations with root privileges. Now let’s move on to the more specific disk partitioning operations.
1 | sudo su - |
1.Host System Prepartion
After performing the “fdisk -l” operation, typically the disk partitions listed in the Gentoo live CD are labeled as /dev/sda. However, this situation does not include cases where users have already performed disk partitioning using other systems such as Ubuntu as the host system.
If the /dev/sda partition appears after executing the “fdisk -l” command, proceed to select this partition for further disk partitioning. The main partitions consist of three major divisions: /boot partition, /swap partition, and /root partition. The /boot partition is used for system booting, the /swap partition is used for memory swapping, and the /root partition is used for user or administrator data storage. They are sequentially designated as /dev/sda1, /dev/sda2, and /dev/sda3. The overall data storage partition should have a minimum space of 30GB. Next, change the swap partition type to “Linux swap/solaris” in Linux. After completing all the steps, you need to format each newly created partition. Finally, before formatting, make sure to write the partition changes to the disk. Otherwise, when you restore the system using snapshots, the partitioning changes will not have any substantial effect. The following is a list of commands and the order of operations:
1 | fdisk /dev/sda |
Once all the previous steps have been completed, we have successfully partitioned the disk and performed the basic formatting operations. Now, we will proceed to create the /boot partition for LFS and mount the previously created /dev/sda1 partition (with a size of 256MB) to the specified location. To ensure the safety of the host system and avoid any interference, all the partition mounting operations will be performed under the /mnt directory. For convenience in subsequent operations, we have set the environment variable export LFS=/mnt/lfs
in the host system beforehand. You can verify if this command is effective by using the echo $LFS
command. Next, to mount the /boot partition and create the /boot directory, follow the steps below:
1 | mkdir -pv $LFS && mkdir -pv $LFS/boot |
Next, since we previously created the /swap partition for memory swapping, we still need to activate the /swap partition in LFS. However, it’s worth noting that with the continuous development of devices and underlying hardware, the significance of /swap has become less necessary compared to ancient times. In reality, it is optional. Nevertheless, for the sake of completeness in the LFS build process, we will still create and activate the /swap partition. You can use the following command to activate it:
1 | /sbin/swapon -v /dev/sda2 |
2.Package Download
After preparing the host system, it is necessary to download the source code for all the software following the instructions in the LFS manual. After downloading, refrain from immediately extracting the packages. First, perform an MD5 checksum verification for these installation packages using the command “md5sum” (e.g., man md5sum). Start by creating a “sources” folder in the $LFS directory using the command mkdir -pv $LFS/sources
. Once all the source code files have been downloaded and verified, ensure that all the files in the “sources” folder have root permissions using the command chown root:root $LFS/sources/\*
.
3.Group Useradd and file structure demonstration
After completing the above steps, you can use the ls
or ls -l
command to view the structure of the $LFS directory as follows:
Partition | Specific application |
---|---|
/lost+found | Default guide partition will be installed here |
/sources | Downloaded package and patches |
/boot | Boot filesystem |
The file structure mentioned above does not conform to the typical Linux root directory file structure. Next, we will create symbolic links according to the instructions in the LFS manual to obtain the following file structure. Please refer to the LFS manual mentioned at the beginning for the specific steps.
1 | LFS/ |
Next, we need to create a user for the LFS system. You can choose any username you prefer. In this case, we will use “lfs” to be consistent with the manual. The command to create the “lfs” user is as follows. Please note that the following operations are applicable to almost all Linux distributions. The primary purpose of creating the “lfs” user is to avoid contaminating the host system:
1 | groupadd lfs && useradd -s /bin/bash -g lfs -m -k /dev/null lfs |
At this point, we can use the command su - lfs
to switch to the LFS environment. By doing so, we can create the .bashrc file according to the manual, which will establish environment variables in the Bash terminal environment.
- Title: Linux From Scratch Compilation Progress(System Preparation)
- Author: Keith
- Created at : 2024-03-19 23:02:57
- Updated at : 2024-03-19 23:09:14
- Link: https://redefine.ohevan.com/2024/03/19/Linux-From-Scratch-Compilation-Progress-System-Preparation/
- License: This work is licensed under CC BY-NC-SA 4.0.