Status: ✅ Complete (6 packages built) Build Environment: Rootless Podman worker (no sudo required) Execution: Inside chroot using temporary tools from Chapter 6
Chapter 7 marks a critical transition in the LFS bootstrap process. We enter the chroot environment and build essential tools that will be used to compile the final system in Chapter 8+.
The chroot (change root) operation isolates our build environment:
- Prevents contamination from the host system
- Forces use of our temporary tools (not host tools)
- Creates a controlled environment for the final system build
- Simulates the environment of a bootable LFS system
These packages are required by Chapter 8 build scripts but weren't needed in Chapter 6:
| Package | Purpose | Why Now? |
|---|---|---|
| Gettext | Internationalization (i18n) and localization tools | Required by many Chapter 8 builds |
| Bison | Parser generator (creates compilers from grammar files) | Used by several build systems |
| Perl | Powerful scripting language | Many configure scripts use Perl |
| Python | Modern programming language | Modern build systems (Meson, etc.) |
| Texinfo | Documentation system (creates info, HTML, PDF from source) | Needed for package documentation |
| Util-linux | Essential system utilities (mount, lsblk, etc.) | Core system management tools |
Before building Chapter 7, ensure:
- ✅ Rootless Podman configured (test with
podman run --rm hello-world) - ✅ Chapter 6 temporary tools built:
bazel build //packages/chapter_06:all_temp_tools - Build Chapter 7 end-to-end:
bazel build //packages:bootstrap_ch7 - Or run just Chapter 7:
bazel build //packages/chapter_07:chroot_finalize
Chapter 7 uses the rootless Podman worker system - the same system used for Chapter 8+. All builds run as a regular user with no sudo requirements.
How it works:
- Podman creates a rootless container with user namespaces
- Inside the container namespace, processes run as root
- Container mounts virtual filesystems (
/dev,/proc,/sys,/run) - All chroot operations happen inside the container (no host sudo needed)
cd src
# 1. Prepare the chroot environment (create directories, seed files)
bazel build //packages/chapter_07:chroot_prepare
# 2. Build all Chapter 7 packages (runs in parallel via Podman worker)
bazel build //packages/chapter_07:chroot_toolchain_phase
# 3. Verify installations
bazel build //packages/chapter_07:chroot_smoke_versions
# 4. (Optional) Perform Chapter 7 cleanup (removes libtool archives, /tools)
bazel build //packages/chapter_07:chroot_finalizeNote: No source staging needed! The lfs_package rule automatically extracts tarballs from Bazel's external repos.
- Podman Worker Launch - Rootless container starts with Bazel JSON worker protocol
- Environment Prep - Directories created, essential files seeded (
/etc/passwd,/etc/group, etc.) - Virtual Filesystems - Container mounts
/dev,/proc,/sys,/run - Package Extraction - Tarballs extracted from Bazel external repos
- Build Execution - Commands run inside chroot following LFS book
- Cleanup - If requested, removes libtool archives and
/tools
Parallel Build Support: Chapter 7 packages build in parallel using the Podman worker. Bazel handles scheduling automatically. Use --jobs=N to control concurrency if needed.
Chapter 7 uses the lfs_package macro with phase="chroot" for all builds:
lfs_package(
name = "perl",
phase = "chroot",
srcs = ["@perl_src//file"],
configure_cmd = "./Configure -des -Dprefix=/usr ...",
build_cmd = "make -j$(nproc)",
install_cmd = "make install",
deps = [":chroot_prepare"],
)How it works:
- Worker launcher creates Podman container with Bazel JSON worker protocol
- Container mounts sysroot at
/lfsand virtual filesystems - Build script extracts source tarball and sets up environment
- Executes configure, build, and install commands inside chroot
- Creates
.donemarker file for Bazel caching - Worker stays alive across builds for performance
Key Advantage: No sudo required! Podman's user namespaces allow chroot operations without host privileges.
HOME="/root"
LC_ALL="C"
PATH="/usr/bin:/usr/sbin:/bin:/sbin"
TERM="linux"
LFS="/" # Inside chroot, we ARE the root!The temp_tools_toolchain from Chapter 6 provides additional environment variables.
Check all packages installed correctly:
bazel build //packages/chapter_07:chroot_smoke_versionsExpected output (in build log):
bison (GNU Bison) 3.8.2
msgfmt (GNU gettext-tools) 0.22.5
version='5.40.0';
Python 3.12.4
info (GNU texinfo) 7.1
lsblk from util-linux 2.40.2
Problem: Container fails to start or worker crashes.
Solution: Verify rootless Podman is configured:
podman --version # Should be 3.0+
podman run --rm hello-world # Test basic functionalitySee docs/troubleshooting.md for detailed Podman setup.
Problem: Build command fails with "command not found".
Solution: Ensure Chapter 6 temporary tools are fully built:
bazel build //packages/chapter_06:all_temp_tools
ls -la sysroot/usr/bin/ # Verify tools existProblem: Configure scripts fail with "cannot execute: required file not found".
Solution: Verify essential symlinks exist. The preparation step should create:
/bin→/usr/bin/bin/sh→/usr/bin/bash/bin/bash→/usr/bin/bash
If missing, rebuild: bazel build //packages/chapter_07:chroot_prepare
Good News: With the Podman worker approach, sysroot ownership is no longer a concern!
- Chapter 5-6: Builds run on host, write to sysroot as regular user
- Chapter 7-8+: Podman container uses user namespaces to run as root inside container
- No chown needed: Sysroot remains owned by your user throughout the entire build process
✅ No sudo required - Entire build runs as regular user ✅ No ownership transitions - Sysroot ownership never changes ✅ Simpler iteration - Can rebuild any chapter without permission issues ✅ Better security - No need to grant sudo permissions
- Build Time: ~2 minutes
- Install Size: ~50 MB
- Purpose: Provides
msgfmt,xgettext, and other i18n tools
- Build Time: ~1 minute
- Install Size: ~15 MB
- Purpose: Parser generator for building compilers
- Build Time: ~3-5 minutes
- Install Size: ~150 MB
- Purpose: Scripting language used by many configure scripts
- Build Time: ~5-10 minutes (with optimizations)
- Install Size: ~400 MB
- Purpose: Required by Meson and modern build systems
- Build Time: ~1 minute
- Install Size: ~30 MB
- Purpose: Creates documentation in various formats
- Build Time: ~2 minutes
- Install Size: ~100 MB
- Purpose: Essential utilities like
mount,lsblk,fdisk
After completing Chapter 7:
- Backup your sysroot - Create a tarball of
sysroot/for safety - Move to Chapter 8 - Build the final system (~80 packages)
- Stripping - Remove debug symbols to save space (optional)
- Chapter 7.2 - Changing Ownership
- Chapter 7.3 - Preparing Virtual Kernel File Systems
- Chapter 7.4 - Entering the Chroot Environment
- Chapter 7.5-7.13 - Package Builds
- docs/tools.md - Chroot rule reference
- DESIGN.md - Chroot architecture
- docs/status.md - Overall build status
Status: Chapter 7 complete! Ready for Chapter 8. 🎉