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
-
Linux Kernel Reducing Long-Term Support
LTS support for the Linux kernel is about to undergo some serious changes that will have a considerable impact on the future.
-
Fedora 39 Beta is Now Available for Testing
For fans and users of Fedora Linux, the first beta of release 39 is now available, which is a minor upgrade but does include GNOME 45.
-
Fedora Linux 40 to Drop X11 for KDE Plasma
When Fedora 40 arrives in 2024, there will be a few big changes coming, especially for the KDE Plasma option.
-
Real-Time Ubuntu Available in AWS Marketplace
Anyone looking for a Linux distribution for real-time processing could do a whole lot worse than Real-Time Ubuntu.
-
KSMBD Finally Reaches a Stable State
For those who've been looking forward to the first release of KSMBD, after two years it's no longer considered experimental.
-
Nitrux 3.0.0 Has Been Released
The latest version of Nitrux brings plenty of innovation and fresh apps to the table.
-
Linux From Scratch 12.0 Now Available
If you're looking to roll your own Linux distribution, the latest version of Linux From Scratch is now available with plenty of updates.
-
Linux Kernel 6.5 Has Been Released
The newest Linux kernel, version 6.5, now includes initial support for two very exciting features.
-
UbuntuDDE 23.04 Now Available
A new version of the UbuntuDDE remix has finally arrived with all the updates from the Deepin desktop and everything that comes with the Ubuntu 23.04 base.
-
Star Labs Reveals a New Surface-Like Linux Tablet
If you've ever wanted a tablet that rivals the MS Surface, you're in luck as Star Labs has created such a device.