Skip to content

A fully commented docker image and bunch of scripts that makes building Linux From Scratch easy, while striving to keep it educational.

Notifications You must be signed in to change notification settings

golddranks/lfs_docker

Repository files navigation

Docked Linux From Scratch

This is a docker image that makes building Linux From Scratch easy.

What is Linux From Scratch?

Linux From Scratch (LFS) is a working Linux-based operating system, hand-build from sources, by you.

Its purpose is to be a minimal and self-contained Linux system; enough so that the user can throughly understand which components the system consists of.

Linux From Scratch is also a book that describes and teaches building such a system. The book is freely available here: https://www.linuxfromscratch.org/

Here's a rough overview what steps building LFS consists of. The exact steps and requirements are described in the book. Note that the numbering here doesn't correspond to the chapters of the book!

  1. Start with some, working Linux system with Gnu Compiler Collection (GCC) and related build tools
  2. Download source releases of GCC and the build tools, their dependencies, Linux kernel, C and C++ standard libraries and a bunch of system essentials, daemons and utilities that are needed for a working system.
  3. Build GCC and the build tools using cross-compilation to restrict the accidental linking of the host system libraries.
  4. Using these newly-build compilation tools, build a minimal system that is self-contained enough to work as a build environment for the LFS itself.
  5. Chroot to the minimal system. The Linux kernel is still the one of the host system, but all the tools and libraries of the host system are made unavailable by the chroot. We do this to ensure reproducibility; both the tools we use to build the LFS system, and the system itself are built from source by us.
  6. Using the minimal toolset, we build and install all the programs and libraries we need to build a working Linux system.
  7. After building and installing, we configure the system.
  8. Finally, we build and install the Linux kernel, and make the system bootable.
  9. We have a working LFS we can boot into!

What is this Docker image?

This Docker image makes building a LFS system easy. It provides a host system mentioned in step 1. This means that you don't have to have a working Linux distro at hand – you can get a virtualized one with Docker. Additionally, it provides automated scripts to perform the steps 2 - 4, to build a minimal, self-contained build environment for building LFS itself.

One of the main ideas of LFS is to get a good grasp of what components a working, minimal Linux system needs by building it by hand. One could argue, that the steps 1 - 4, while educational, aren't strictly needed to get this understanding. Some build steps consist of building the same packages twice or even thrice.

The steps 2 - 3 of building the minimal system provide some insight to cross-compiling, bootstrapping and the GCC toolchain and its dependencies, but the most important steps to get understanding about a minimal Linux system are arguably the steps from 5 onwards.

This is why this image provides automated scripts to get to that stage, but expects you to build the final LFS system by hand, following the directions of the book (chapter 6 onwards).

Be sure to read the Dockerfile, it's fully commented.

Reading the scripts chapter2.sh, chapter3.sh, chapter4.sh and chapter5.sh are also highly recommended. They are also fully commented.

How to get started

Run this to build the Dockerfile and enter the host environment.

docker build --tag lfs .
docker run -it --privileged lfs

The image needs to be run as privileged, because mounting doesn't work inside the container without that capability. We need to mount the LFS system image during the preparation steps.

The book recommends you to check the versions of the tools of the host system. This Docker image has the expected versions, but you can verify this yourself by running:

./version-check.sh

At your choice, you can automatically perform the steps in the LFS book by running script files that correspond to the chapters in the book. At least running the chapter2.sh is recommended, since it finishes preparing the host system provided by this image. (It, among other things, prepares and mounts a virtual filesystem used for the LFS installation.)

./chapter2.sh

Once you have done everything through chapters 2 to 5, you are on your own; all that is left is to build the LFS system itself. Follow the instructions here: https://www.linuxfromscratch.org/lfs/view/stable/chapter06/introduction.html

About

A fully commented docker image and bunch of scripts that makes building Linux From Scratch easy, while striving to keep it educational.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published