Linux From Scratch
This is a breakdown of the LFS book.
Notes
- sticky bit - file can be removed only by its owner even if directory is
accessible to multiple users.
/tmp
uses 777 with sticky-bit. Thanks to it anyone is able to create/read/execute in/tmp
, but only owner of a given file can remove it. - login and non-login shell - login shell loads
bash_profile
(which loads other things like.bashrc
). Non-login shell may be started only when login shell session exists, and it loads.bashrc
directly.
Cross-compilers
Cross-compiler is a compiler that builds programs on machine A, but the programs are supposed to run on machine B.
Toolchain
Some of the most important packages on linux:
- binutils - contains
ld
(linker) andas
(assembler), and lots of other tools - glibc - GNU standard C library (provides basic things like
open
,read
,write
,printf
, etc.). - gcc - GNU Compiler Collection (C and C++ among others)
- libgcc - internal library used by GCC
The installation order:
- binutils - linker and assembler are required by gcc’s and glibc’s
configure
scripts. - gcc
- sanitized Linux API headers - allows glibc to interface with kernel’s features
- glibc
- libstdc++
Package Managers
Package manager tracks the files installed by applications making it easy to update and remove software.
Approaches:
- installing each package in separate directory, and creating a symlink to
executable in some shared directory (e.g.
/usr
). - timestamp-based - package manager records the time of package installation. Later it can find package’s files by looking at timestamp of the files on the system. This will not work if multiple packages are being installed at the same time.
- package archives - RPMs and DEBs use that. The package’s structure is made in an archive and recreated on the target system.
Issues
- Kernel 3.2 - I have 5.x…
- After downloading all packages from FTP, and checking their md5 I got the
following:
md5sum: man-pages-5.12.tar.xz: No such file or directory
. It turns out that FTP had version 5.13 of that package only. Is it a problem?
Steps
Chapter 2 - prerequisites
- Install Ubuntu 20.04 in a VM (I used Gnome Boxes)
- Install all the missing packages (accoridng to version-check.sh)
- Create a new partition for LFS (~20GB) and mount it.
- Create
/sources
directory on the LFS partition.
Chapter 3 - downloading sources
- Download all software packages and patches from the FTP mirror of LFS, and check md5 checksums.
Chapter 4 - bootstrap LFS partition
- Create some dirs in LFS partition (
/etc
,/var
,/lib64
,/usr/bin
,/usr/sbin
,/usr/lib
). - Create
/tools
directory for cross-compiler to be installed in. - Add
lfs
user and group to the host system. chown
directories in the LFS partition by thelfs
user.- Log in as
lfs
in a terminal session. - Create
.bash_profile
and.bashrc
files forlfs
user.
Chapter 5 - building cross-compiler and its associated tools
- Build Binutils (pass 1)
- Build GCC (pass 1)
- Build sanitized Linux API headers
- Build glibc
- Build libstdc++ (pass 1)
Chapter 6 - cross-compiling temporary tools
- Build M4
- Build Ncurses
- Build Bash
- Build Coreutils
- Build Diffutils - by mistake I did make install before make. Later I rerun make install. Is it OK?
- Build File - File on host needs to be in version 5.40? I have 5.38
- Build Findutils
- Build Gawk
- Build Grep
- Build Gzip
- Build Make
- Build Patch
- Build sed
- Build tar
- Build Xz
- Build Binutils (pass 2)
- Build GCC (pass 2)
Chapter 7 - chroot
- Change ownership of dirs in $LFS to root.
- Create console and null devices in $LFS/dev.
- Mount Virtual Kernel File Systems on $LFS (
dev
,proc
,sys
,run
). - Chroot on
$LFS
-$LFS/etc/passwd
doesn’t exist so “I have no name!” will appear instead of user name in bash.
- Create Linux directories according to FHS (Filesystem Hierarchy Standard).
- Link
/etc/mtab
to/proc/self/mounts
- Create
/etc/hosts
. - Create
/etc/passwd
. - Create
/etc/group
. - Create “tester” user (needed for some tests later on).
- Start a new shell to make use of the
/etc/passwd
and/etc/group
. Shell now properly shows “root” as a user. - Create files for logs for various programs (login, agetty, init)
- Build Libstdc++ (pass 2).
- Build Gettext.
- Build Bison.
- Build Perl.
- Build Python.
- Build Texinfp.
- Build Util-linux
- Cleanup doc files and .la files
- Delete the
$LFS/tools
directory, we no longer need it. - Backup current work (
$LFS
)
Chapter 8
- Build man-pages
- Copy Iana-Etc
services
andprotocols
to/etc
. - Build and test Glibc - hard to say if
make check
was successful or not (44 fails, 67 unsupported, 16 xfail) - Install locales, timezones
- Build Zlib
- Build Bzip2
- Build Xz
- Build File
- Build Readline
page 116 (M4 is next)