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
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.