User Tools

Site Tools


computing:linuxfromscratch

This is an old revision of the document!



  • lfs
  • Jonathan Haack
  • Haack's Networking
  • netcmnd@jonathanhaack.com

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 version-check.sh contents into your terminal, then run

bash version-check.sh

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 library-check.sh, and remember it should have none of them or all of them only

cd ~

Copy and paste the library-check.sh contents into your terminal, then run

bash library-check.sh

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 http://www.linuxfromscratch.org/lfs/view/7.9/wget-list 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 http://www.linuxfromscratch.org/lfs/view/7.9/md5sums and then execute

pushd $LFS/sources
md5sum -c md5sums
popd

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
EOF

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=/media/lfs
LC_ALL=POSIX
LFS_TGT=$(uname -m)-lfs-linux-gnu
PATH=/tools/bin:/bin:/usr/bin
export LFS LC_ALL LFS_TGT PATH
EOF

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 example.bz
cd example
make 
make install clean
cd ../
rm example.bz

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              \
             --disable-werror
make
case $(uname -m) in
  x86_64) mkdir -v /tools/lib && ln -sv lib /tools/lib64 ;;
esac  
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/03/23 23:26

computing/linuxfromscratch.1577673402.txt.gz · Last modified: 2019/12/30 02:36 by oemb1905