User Tools

Site Tools


  • lfs
  • Jonathan Haack
  • Haack's Networking

Building a linux from scratch (lfs) system. [in progress, see associated Repository.]

First, set up the host system with min requirements

sudo apt install bash binutils bison bzip2 coreutils diffutils findutils gawk gcc g++ grep m4 make patch perl sed tar texinfo xz-utils

Verify that the versions are good

cd ~

Copy and paste the contents into your terminal, then run


Update or add anything missing, and if you need to symlink sh to bash that would be

cd /bin/
sudo ln -sf bash /bin/sh

Now check your libraries with, and remember it should have none of them or all of them only

cd ~

Copy and paste the contents into your terminal, then run


We can now start preparing the partition for the LFS work

sudo -i
sudo apt install gparted
sudo gparted

Inside gparted, create one partition. In a future tutorial, I will do more than one partition. Once set up, edit fstab

sudo nano /etc/fstab

Here are some suggested defaults

/dev/vda3     /media/lfs            ext4    defaults            1     1

Now that you have created that entry, add environment variables to .bashrc for your user and for your root

nano ~/.bashrc
nano /root/.bashrc  

In the file that opens, add this env variable to the body

export LFS=/media/lfs

Reboot the system, make sure the external partition auto-mounts, and its location matches the output of

echo $LFS

Ok, now we will create a sources directory on the partition and create a file called wget-list

mkdir -v $LFS/sources
chmod -v a+wt $LFS/sources
nano wget-list

In the file that opens, copy and paste the contents of then execute this within same directory as above

wget --input-file=wget-list --continue --directory-prefix=$LFS/sources

You can do similar trick with md5sum to ensure every download completed with integrity

nano $LFS/sources/md5sums

In that file, enter the contents of and then execute

pushd $LFS/sources
md5sum -c md5sums

Now, add a non-privileged user to prepare for building

groupadd lfs
useradd -s /bin/bash -g lfs -m -k /dev/null lfs
passwd lfs
chown -v lfs $LFS/tools
chown -v lfs $LFS/sources
su - lfs

Once you are logged in to the user, set up your bashrc and profile and re-establish the environment variables

cat > ~/.bash_profile << "EOF"
exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash

And, make sure that the $LFS variable matches your mount point above, and not the default from the text

cat > ~/.bashrc << "EOF"
set +h
umask 022
LFS_TGT=$(uname -m)-lfs-linux-gnu

Now, source both

source ~/.bash_profile
source ~/.bashrc

Once this is done, you are ready to start building the packages in $LFS/sources from source. Make sure you are logged in as lfs, and env are set

su - lfs
echo $LFS

For building the packages from source … the basics are as follows …

cd $LFS/sources
tar xvf
cd example
make install clean
cd ../

But, each package has special build instructions, so this is a point where we need to proceed slowly. Starting with binutils:

tar xvf binutils-2.26.tar.bz2
mkdir -v build
cd       build
../configure --prefix=/tools            \
             --with-sysroot=$LFS        \
             --with-lib-path=/tools/lib \
             --target=$LFS_TGT          \
             --disable-nls              \
case $(uname -m) in
  x86_64) mkdir -v /tools/lib && ln -sv lib /tools/lib64 ;;
make install
cd ../../
rm binutils-2.26.tar.bz2

Ok, so now you can see how despite the general rules for building from source, there will be significant variations for each package

oemb1905 2019/12/30 02:37

computing/linuxfromscratch.txt · Last modified: 2019/12/29 19:37 by oemb1905