Bash script to build LFS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Cyril CONSTANTIN 64afc2724e Fix anos and add linux config for 64 bits 3 weeks ago
build Fix anos and add linux config for 64 bits 3 weeks ago
COPYING initial successfull build 4 weeks ago
LICENSE initial successfull build 4 weeks ago
Makefile initial successfull build 4 weeks ago
README.md Fix anos and add linux config for 64 bits 3 weeks ago
build.sh Fix anos and add linux config for 64 bits 3 weeks ago
linux-config-i686.txt initial successfull build 4 weeks ago
linux-config-x86_64.txt Fix anos and add linux config for 64 bits 3 weeks ago
md5sums initial successfull build 4 weeks ago
wget-list-systemd.txt initial successfull build 4 weeks ago

README.md

cclfs

It's a compliant bash script that builds Linux From Scratch.

If you don't know what this is, or haven't built Linux From Scratch on your own before, you should go through the LFS book before using this script.

This is a script based on https://github.com/krglaws/MyLFS.git. It was developped on debian (bookworm i686, trixie x86_64).

Requirements

The requirements are those of the book : https://www.linuxfromscratch.org/lfs/view/stable-systemd/

The /mnt/lfs partition is not created by the script. You have to create it by yourself. Some commands are provided by the script.

The lfs user is mandatory :

groupadd lfs
useradd -s /bin/bash -g lfs -m -k /dev/null lfs
passwd lfs

Some additionnal requirements :

  • the lfs user is mandatory
    • The script should by executed by lfs user
  • sudo command is necessary
    • a sudoers file is provided for lfs user to restrict rights to stricts requirements.
    • this sudoers file allow to protect the host and restrict command only to /mnt/lfs directory
    • it allow the following commands on /mnt/lfs : chown mount install chroot
  • build directory is hardcoded : /mnt/lfs
  • mount |grep -q "/mnt/lfs type ext4 should return ok
  • /etc/bash.bashrc should not be used on host
    • sudo mv -v /etc/bash.bashrc /etc/bash.bashrc.NOUSE
  • cross compilation for glibc seems to need some specific packages
    • sudo apt install flex libzstd-dev pkgconf
  • you can't execute in parallel the script on the same namespace.

How It Works

Copy the repository under any location <build_directory>.

The script do some writings only under :

  • <build_directory>
  • LFS_PACKAGE_DIR if it does not contains all required packages
  • ~lfs/
  • /tmp/lfs*
  • /mnt/lfs/
  • /mnt/lfs/sources/

The script builds LFS by completing the following steps:

  1. Download package source code and save to the packages directory.
  2. Build initial cross compilation tools. This corresponds to chapter 5 in the LFS book, and "phase 1" of the script.
  3. Begin to build tools required for minimal chroot environment. (chapter 6/phase 2)
  4. Enter chroot environment, and build remaining tools needed to build the entire LFS system. (chapter 7/phase 3)
  5. Build the entire LFS system from within chroot envirnment, including the kernel, GRUB, and others. (chapter 8+/phase 4)

The script ask for validation for each step. You can disable validation until desired step with a number as argument. The number is the chapter (of the books) on 5 digits until you validate. If you want to start validation at 5. Compiling a Cross-Toolchain, it's 50000.

To configure it, execute a first time the make command. A file ~lfs/.lfsbuild_config will be created. You can customize it by setting the BREAKPOINT var.

Or create the file before :

cat /home/lfs/.lfsbuild_config << EOSF
# location of local package sources
LFS_PACKAGE_DIR=/home/lfs/packages
# Number of processors to use
LFS_NPROC=$(nproc)
# Bypass step by step validation until a breakpoint
LFS_BREAKPOINT=1
# strip binaries or not
LFS_STRIP_BINARIES=false
# bypass network config validation by taking network config from host
LFS_NETWORKSAMEASHOST=false
# bypass network configuration for full offline build
LFS_NETWORKOFFLINE=false
# bypass linux config validation by taking linux config from host
# !!! LFS doesn't built a initramfs. If your host load required drivers as modules in it, you won't be able to boot.
# It may be convenient if you build from an LFS host.
# You can also put a config file in your home ( $HOME/linux-config-*version* e.g. linux-config-6.8.10 ) and it will be taken as config file.
LFS_LINUXCONFIGSAMEASHOST=false
EOSF

Examples

Execute as lfs user.

make