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
-
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.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
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.