A Beginner's Guide to Linux From Scratch
February 16, 2021
Objective
- Gain a top-level understanding of how Linux works and its foundational principles.
- Gather useful tips and tricks from someone who has already gone through the process.
- Learn to install Linux on any hardware without using ISO images.
For reference, I have used the following blogs, which provide some of the best open-source documentation available:
My Host Machines During Compilation
- Round 1: Dedicated host with base OS as Ubuntu
- Round 2: Ubuntu VM installed on a base Ubuntu-operated laptop
Let's Get Started
Step 1: Creating a Dedicated Partition for LFS Compilation and Base Installation
We will compile all the packages needed to build a Linux system and install our Linux OS in the same directory.
The utility I used to make partitions is an app called Gparted, which is preinstalled in the Ubuntu flavor.
Here's a quick overview of the partition setup:
- Root mount:
/dev/sda1
- Swap memory: 8GB partition
/dev/sda5
- Unallocated space: 20GB for LFS compilation and installation (recommended to create a partition of about 30–35 GB).
Commands for Partition Setup:
Step 2: Download LFS Binaries from Official LFS Repos
The above command should return all packages checked with "OK" as a result.
Step 3: Adding LFS User and Setting Up the Environment
Environment Setup:
Step 4: General Steps for the Compilation Process
For compiling all the packages/binaries, follow these steps:
Compile all packages in the exact order given below and follow every step mentioned in the LFS book:
Example Packages to Compile:
- Binutils-2.32 — Pass 1
- GCC-8.2.0 — Pass 1
- Linux-4.20.12 API Headers
- Glibc-2.29
- Libstdc++ from GCC-8.2.0
- ... (and many more as listed in the LFS book)
Step 5: Continued Compilation
Continue compiling the next set of packages as mentioned in the LFS book. Ensure you follow the exact sequence and steps.
Step 6: Udev, Hostname, IP Configuration, and Final Steps for Booting Linux
After compiling the Linux kernel, it's essential to set up network scripts correctly to maintain connectivity.
Final Command for Boot Configuration:
General Tips for the Entire Journey
- Don’t deviate from the book at any point.
- Write sensible network configuration scripts if your host system is not accessible geographically.
- Be patient and maintain a positive attitude throughout the process.
Conclusion
Thanks for reading my blog. Keep coding, keep smiling!