Building Linux from Scratch
Loading Packages and Patches
Chapter 3 of the LFS documentation defines LFS with its later feature set. In addition to the build tools, you need to download the desired sources for a choice of software packages that define the system. The makers of LFS have taken the trouble to make a preselection, resolve their version dependencies, and list them in a text file that you can download and conveniently pass into Wget (Listing 2).
Listing 2
Downloading a Software Set
$ wget http://lfs.linux-sysadmin.com/lfs/downloads/stable-systemd/wget-list $ wget --input-file=wget-list --continue --directory-prefix=$LFS/sources
The LFS developers provide a number of patches that fix bugs or adapt the packages to the future target system. In addition, they explain all the options of the configure
calls. An Md5sum checksum list, which is also provided, helps to check the checksums of the almost 90 packages that are downloaded.
Concluding Work
In LFS chapter 4, the root user creates the directory structures required for the build $LFS/{bin,etc,lib,lib64,sbin,tools,usr,var}
, as well as the lfs user as owner of the build directories. Then it is a matter of becoming the lfs user and emptying and optimizing the shell environment for this account.
Since the new environment is a non-login shell, it needs a .bashrc
file to extend and customize the shell environment – for example, to set environment variables such as $LFS
, LC_ALL
, or PATH
. The $LFS/tools/
directory will contain the cross-compiler later on.
The next step is to restart the build host to make sure there are no problems and that it works. At this point at the latest, it is advisable to create a VM snapshot.
Compiling the Cross Toolchain
In chapter 5 of the LFS manual, you remain logged in as the lfs user, for whom the real work now begins: building the cross-compiler and its tools (Listing 3). The cross-compiler and its tools are temporarily stored in $LFS/tools/
; you can already install the libraries where they will need to be in the future.
Listing 3
Testing the Cross-Compiled GCC
$ echo 'int main(){}' > dummy.c $ $LFS_TGT-gcc dummy.c ### Shows the information from the segment headers ### of the file, if any $ readelf -l a.out | grep '/ld-linux' ### Should return something like: ### [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
The workflows for building the software packages almost always remain the same until the end. You change to the sources/
directory, where you unpack the source files using tar xf
. Then change to the new directory created in the process, where you create a build/
directory, if necessary.
Now the package can be compiled and installed. Then delete the source code directory again. You can do this in a first run for the linker and assembler, the cross-compiler, the Linux API headers, glibc, and libstdc++.
« Previous 1 2 3 4 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Endless OS 6 has Arrived
After more than a year since the last update, the latest release of Endless OS is now available for general usage.
-
Fedora Asahi 40 Remix Available for Macs with Apple Silicon
If you've been anticipating KDE's Plasma 6 for your Apple Silicon-powered Mac, then you're in luck.
-
Red Hat Adds New Deployment Option for Enterprise Linux Platforms
Red Hat has re-imagined enterprise Linux for an AI future with Image Mode.
-
OSJH and LPI Release 2024 Open Source Pros Job Survey Results
See what open source professionals look for in a new role.
-
Proton 9.0-1 Released to Improve Gaming with Steam
The latest release of Proton 9 adds several improvements and fixes an issue that has been problematic for Linux users.
-
So Long Neofetch and Thanks for the Info
Today is a day that every Linux user who enjoys bragging about their system(s) will mourn, as Neofetch has come to an end.
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.