Jordan Savant // Software Engineer

Linux Kernel Dev Blog 7 - Linux From Scratch (LFS) Sources

4/7/2020

Starting back up


making source staging dir

Make a working directory to save the source files

But before I do this I am going to try and not have to do everything as root so I will change the perms to doomguy on the mount

Make the dir and make it writeable by others but not deletable with the "sticky" t flag (new stuff for me)

$ mkdir $LFS/sources

before is drwxrwxr-x 2 doomguy doomguy 4096 Apr 7 07:26 sources

$ chmod -v a+wt $LFS/sources # all + write "t" for sticky
mode of '/mnt/lfs/sources' changed from 0775 (rwxrwxr-x) to 1777 (rwxrwxrwt)

after is drwxrwxrwt 2 doomguy doomguy 4096 Apr 7 07:26 sources

downloading stuff

sources

Their guide uses wget list to pull down a full list of packages from http://www.linuxfromscratch.org/lfs/view/stable/wget-list

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

With the input file being:

http://download.savannah.gnu.org/releases/acl/acl-2.2.53.tar.gz
http://download.savannah.gnu.org/releases/attr/attr-2.4.48.tar.gz
http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.xz
http://ftp.gnu.org/gnu/automake/automake-1.16.1.tar.xz
http://ftp.gnu.org/gnu/bash/bash-5.0.tar.gz
https://github.com/gavinhoward/bc/archive/2.5.3/bc-2.5.3.tar.gz
http://ftp.gnu.org/gnu/binutils/binutils-2.34.tar.xz
http://ftp.gnu.org/gnu/bison/bison-3.5.2.tar.xz
https://www.sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz
https://github.com/libcheck/check/releases/download/0.14.0/check-0.14.0.tar.gz
http://ftp.gnu.org/gnu/coreutils/coreutils-8.31.tar.xz
https://dbus.freedesktop.org/releases/dbus/dbus-1.12.16.tar.gz
http://ftp.gnu.org/gnu/dejagnu/dejagnu-1.6.2.tar.gz
http://ftp.gnu.org/gnu/diffutils/diffutils-3.7.tar.xz
https://downloads.sourceforge.net/project/e2fsprogs/e2fsprogs/v1.45.5/e2fsprogs-1.45.5.tar.gz
https://sourceware.org/ftp/elfutils/0.178/elfutils-0.178.tar.bz2
https://dev.gentoo.org/~blueness/eudev/eudev-3.2.9.tar.gz
https://prdownloads.sourceforge.net/expat/expat-2.2.9.tar.xz
https://prdownloads.sourceforge.net/expect/expect5.45.4.tar.gz
ftp://ftp.astron.com/pub/file/file-5.38.tar.gz
http://ftp.gnu.org/gnu/findutils/findutils-4.7.0.tar.xz
https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz
http://ftp.gnu.org/gnu/gawk/gawk-5.0.1.tar.xz
http://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.xz
http://ftp.gnu.org/gnu/gdbm/gdbm-1.18.1.tar.gz
http://ftp.gnu.org/gnu/gettext/gettext-0.20.1.tar.xz
http://ftp.gnu.org/gnu/glibc/glibc-2.31.tar.xz
http://ftp.gnu.org/gnu/gmp/gmp-6.2.0.tar.xz
http://ftp.gnu.org/gnu/gperf/gperf-3.1.tar.gz
http://ftp.gnu.org/gnu/grep/grep-3.4.tar.xz
http://ftp.gnu.org/gnu/groff/groff-1.22.4.tar.gz
https://ftp.gnu.org/gnu/grub/grub-2.04.tar.xz
http://ftp.gnu.org/gnu/gzip/gzip-1.10.tar.xz
http://anduin.linuxfromscratch.org/LFS/iana-etc-2.30.tar.bz2
http://ftp.gnu.org/gnu/inetutils/inetutils-1.9.4.tar.xz
https://launchpad.net/intltool/trunk/0.51.0/+download/intltool-0.51.0.tar.gz
https://www.kernel.org/pub/linux/utils/net/iproute2/iproute2-5.5.0.tar.xz
https://www.kernel.org/pub/linux/utils/kbd/kbd-2.2.0.tar.xz
https://www.kernel.org/pub/linux/utils/kernel/kmod/kmod-26.tar.xz
http://www.greenwoodsoftware.com/less/less-551.tar.gz
http://www.linuxfromscratch.org/lfs/downloads/9.1/lfs-bootscripts-20191031.tar.xz
https://www.kernel.org/pub/linux/libs/security/linux-privs/libcap2/libcap-2.31.tar.xz
ftp://sourceware.org/pub/libffi/libffi-3.3.tar.gz
http://download.savannah.gnu.org/releases/libpipeline/libpipeline-1.5.2.tar.gz
http://ftp.gnu.org/gnu/libtool/libtool-2.4.6.tar.xz
https://www.kernel.org/pub/linux/kernel/v5.x/linux-5.5.3.tar.xz
http://ftp.gnu.org/gnu/m4/m4-1.4.18.tar.xz
http://ftp.gnu.org/gnu/make/make-4.3.tar.gz
http://download.savannah.gnu.org/releases/man-db/man-db-2.9.0.tar.xz
https://www.kernel.org/pub/linux/docs/man-pages/man-pages-5.05.tar.xz
https://github.com/mesonbuild/meson/releases/download/0.53.1/meson-0.53.1.tar.gz
https://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz
http://www.mpfr.org/mpfr-4.0.2/mpfr-4.0.2.tar.xz
https://github.com/ninja-build/ninja/archive/v1.10.0/ninja-1.10.0.tar.gz
http://ftp.gnu.org/gnu/ncurses/ncurses-6.2.tar.gz
https://www.openssl.org/source/openssl-1.1.1d.tar.gz
http://ftp.gnu.org/gnu/patch/patch-2.7.6.tar.xz
https://www.cpan.org/src/5.0/perl-5.30.1.tar.xz
https://pkg-config.freedesktop.org/releases/pkg-config-0.29.2.tar.gz
https://sourceforge.net/projects/procps-ng/files/Production/procps-ng-3.3.15.tar.xz
https://sourceforge.net/projects/psmisc/files/psmisc/psmisc-23.2.tar.xz
https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tar.xz
https://www.python.org/ftp/python/doc/3.8.1/python-3.8.1-docs-html.tar.bz2
http://ftp.gnu.org/gnu/readline/readline-8.0.tar.gz
http://ftp.gnu.org/gnu/sed/sed-4.8.tar.xz
https://github.com/shadow-maint/shadow/releases/download/4.8.1/shadow-4.8.1.tar.xz
http://www.infodrom.org/projects/sysklogd/download/sysklogd-1.5.1.tar.gz
https://github.com/systemd/systemd/archive/v244/systemd-244.tar.gz
http://anduin.linuxfromscratch.org/LFS/systemd-man-pages-244.tar.xz
http://download.savannah.gnu.org/releases/sysvinit/sysvinit-2.96.tar.xz
http://ftp.gnu.org/gnu/tar/tar-1.32.tar.xz
https://downloads.sourceforge.net/tcl/tcl8.6.10-src.tar.gz
http://ftp.gnu.org/gnu/texinfo/texinfo-6.7.tar.xz
https://www.iana.org/time-zones/repository/releases/tzdata2019c.tar.gz
http://anduin.linuxfromscratch.org/LFS/udev-lfs-20171102.tar.xz
https://www.kernel.org/pub/linux/utils/util-linux/v2.35/util-linux-2.35.1.tar.xz
http://anduin.linuxfromscratch.org/LFS/vim-8.2.0190.tar.gz
https://cpan.metacpan.org/authors/id/T/TO/TODDR/XML-Parser-2.46.tar.gz
https://tukaani.org/xz/xz-5.2.4.tar.xz
https://zlib.net/zlib-1.2.11.tar.xz
https://github.com/facebook/zstd/releases/download/v1.4.4/zstd-1.4.4.tar.gz
http://www.linuxfromscratch.org/patches/lfs/9.1/bash-5.0-upstream_fixes-1.patch
http://www.linuxfromscratch.org/patches/lfs/9.1/bzip2-1.0.8-install_docs-1.patch
http://www.linuxfromscratch.org/patches/lfs/9.1/coreutils-8.31-i18n-1.patch
http://www.linuxfromscratch.org/patches/lfs/9.1/glibc-2.31-fhs-1.patch
http://www.linuxfromscratch.org/patches/lfs/9.1/kbd-2.2.0-backspace-1.patch
http://www.linuxfromscratch.org/patches/lfs/9.1/sysvinit-2.96-consolidated-1.patch

So gonna download those... which holy seemed to work and all be available

We can checksum them with md5sum using their predefined sum file to make sure they are legit from http://www.linuxfromscratch.org/lfs/view/stable/md5sums

$ md5sum
007aabf1dbb550bcddde52a244cd1070  acl-2.2.53.tar.gz
bc1e5cb5c96d99b24886f1f527d3bb3d  attr-2.4.48.tar.gz
50f97f4159805e374639a73e2636f22e  autoconf-2.69.tar.xz
53f38e7591fa57c3d2cee682be668e5b  automake-1.16.1.tar.xz
2b44b47b905be16f45709648f671820b  bash-5.0.tar.gz
6582c6fbbae943fbfb8fe14a34feab57  bc-2.5.3.tar.gz
664ec3a2df7805ed3464639aaae332d6  binutils-2.34.tar.xz
49fc2cf23e31e697d5072835e1662a97  bison-3.5.2.tar.xz
67e051268d0c475ea773822f7500d0e5  bzip2-1.0.8.tar.gz
270e82a445be6026040267a5e11cc94b  check-0.14.0.tar.gz
0009a224d8e288e8ec406ef0161f9293  coreutils-8.31.tar.xz
e1b07516533f351b3aba3423fafeffd6  dejagnu-1.6.2.tar.gz
4824adc0e95dbbf11dfbdfaad6a1e461  diffutils-3.7.tar.xz
6d35428e4ce960cb7e875afe5849c0f3  e2fsprogs-1.45.5.tar.gz
5480d0b7174446aba13a6adde107287f  elfutils-0.178.tar.bz2
dedfb1964f6098fe9320de827957331f  eudev-3.2.9.tar.gz
d2384fa607223447e713e1b9bd272376  expat-2.2.9.tar.xz
00fce8de158422f5ccd2666512329bd2  expect5.45.4.tar.gz
3217633ed09c7cd35ed8d04191675574  file-5.38.tar.gz
731356dec4b1109b812fecfddfead6b2  findutils-4.7.0.tar.xz
2882e3179748cc9f9c23ec593d6adc8d  flex-2.6.4.tar.gz
f9db3f6715207c6f13719713abc9c707  gawk-5.0.1.tar.xz
3818ad8600447f05349098232c2ddc78  gcc-9.2.0.tar.xz
988dc82182121c7570e0cb8b4fcd5415  gdbm-1.18.1.tar.gz
9ed9e26ab613b668e0026222a9c23639  gettext-0.20.1.tar.xz
78a720f17412f3c3282be5a6f3363ec6  glibc-2.31.tar.xz
a325e3f09e6d91e62101e59f9bda3ec1  gmp-6.2.0.tar.xz
9e251c0a618ad0824b51117d5d9db87e  gperf-3.1.tar.gz
111b117d22d6a7d049d6ae7505e9c4d2  grep-3.4.tar.xz
08fb04335e2f5e73f23ea4c3adbf0c5f  groff-1.22.4.tar.gz
5aaca6713b47ca2456d8324a58755ac7  grub-2.04.tar.xz
691b1221694c3394f1c537df4eee39d3  gzip-1.10.tar.xz
3ba3afb1d1b261383d247f46cb135ee8  iana-etc-2.30.tar.bz2
87fef1fa3f603aef11c41dcc097af75e  inetutils-1.9.4.tar.xz
12e517cac2b57a0121cda351570f1e63  intltool-0.51.0.tar.gz
ee8e2cdb416d4a8ef39525d39ab7c2d0  iproute2-5.5.0.tar.xz
d1d7ae0b5fb875dc082731e09cd0c8bc  kbd-2.2.0.tar.xz
1129c243199bdd7db01b55a61aa19601  kmod-26.tar.xz
4ad4408b06d7a6626a055cb453f36819  less-551.tar.gz
e9249541960df505e4dfac0c32369372  lfs-bootscripts-20191031.tar.xz
52120c05dc797b01f5a7ae70f4335e96  libcap-2.31.tar.xz
6313289e32f1d38a9df4770b014a2ca7  libffi-3.3.tar.gz
169de4cc1f6f7f7d430a5bed858b2fd3  libpipeline-1.5.2.tar.gz
1bfb9b923f2c1339b4d2ce1807064aa5  libtool-2.4.6.tar.xz
3ea50025d8c679a327cf2fc225d81a46  linux-5.5.3.tar.xz
730bb15d96fffe47e148d1e09235af82  m4-1.4.18.tar.xz
fc7a67ea86ace13195b0bce683fd4469  make-4.3.tar.gz
897576a19ecbef376a916485608cd790  man-db-2.9.0.tar.xz
da25a4f8dfed0a34453c90153b98752d  man-pages-5.05.tar.xz
9bf73f7b5a2426a7c8674a809bb8cae2  meson-0.53.1.tar.gz
4125404e41e482ec68282a2e687f6c73  mpc-1.1.0.tar.gz
320fbc4463d4c8cb1e566929d8adc4f8  mpfr-4.0.2.tar.xz
cf1d964113a171da42a8940e7607e71a  ninja-1.10.0.tar.gz
e812da327b1c2214ac1aed440ea3ae8d  ncurses-6.2.tar.gz
3be209000dbc7e1b95bcdf47980a3baa  openssl-1.1.1d.tar.gz
78ad9937e4caadcba1526ef1853730d5  patch-2.7.6.tar.xz
f399f3aaee90ddcff5eadd3bccdaacc0  perl-5.30.1.tar.xz
f6e931e319531b736fadc017f470e68a  pkg-config-0.29.2.tar.gz
2b0717a7cb474b3d6dfdeedfbad2eccc  procps-ng-3.3.15.tar.xz
0524258861f00be1a02d27d39d8e5e62  psmisc-23.2.tar.xz
b3fb85fd479c0bf950c626ef80cacb57  Python-3.8.1.tar.xz
edc8c97f9680373fcc1dd952f0ea7fcc  python-3.8.1-docs-html.tar.bz2
7e6c1f16aee3244a69aba6e438295ca3  readline-8.0.tar.gz
6d906edfdb3202304059233f51f9a71d  sed-4.8.tar.xz
4b05eff8a427cf50e615bda324b5bc45  shadow-4.8.1.tar.xz
c70599ab0d037fde724f7210c2c8d7f8  sysklogd-1.5.1.tar.gz
48cebffebf2a96ab09bec14bf9976016  sysvinit-2.96.tar.xz
83e38700a80a26e30b2df054e69956e5  tar-1.32.tar.xz
97c55573f8520bcab74e21bfd8d0aadc  tcl8.6.10-src.tar.gz
d4c5d8cc84438c5993ec5163a59522a6  texinfo-6.7.tar.xz
f6987e6dfdb2eb83a1b5076a50b80894  tzdata2019c.tar.gz
27cd82f9a61422e186b9d6759ddf1634  udev-lfs-20171102.tar.xz
7f64882f631225f0295ca05080cee1bf  util-linux-2.35.1.tar.xz
f5337b1170df90e644a636539a0313a3  vim-8.2.0190.tar.gz
80bb18a8e6240fcf7ec2f7b57601c170  XML-Parser-2.46.tar.gz
003e4d0b1b1899fc6e3000b24feddf7c  xz-5.2.4.tar.xz
85adef240c5f370b308da8c938951a68  zlib-1.2.11.tar.xz
487f7ee1562dee7c1c8adf85e2a63df9  zstd-1.4.4.tar.gz
c1545da2ad7d78574b52c465ec077ed9  bash-5.0-upstream_fixes-1.patch
6a5ac7e89b791aae556de0f745916f7f  bzip2-1.0.8-install_docs-1.patch
a9404fb575dfd5514f3c8f4120f9ca7d  coreutils-8.31-i18n-1.patch
9a5997c3452909b1769918c759eff8a2  glibc-2.31-fhs-1.patch
f75cca16a38da6caa7d52151f7136895  kbd-2.2.0-backspace-1.patch
4900322141d493e74020c9cf437b2cdc  sysvinit-2.96-consolidated-1.patch

Some new commands are pushd and popd which basically are doing cd on a virtual stack

You pushd [dir] to cd into that dir then can popd to cd back to the dir you were in before

pushd $LFS/sources
md5sum -c md5sums
popd

Showed we had some missing packages, namely openssl which was no longer 1.1.1d and was 1.1.1d

They had their "d" release on Github so i got it ehre: https://github.com/openssl/openssl/archive/OpenSSL_1_1_1d.tar.gz

then reneamed it to openssl-1.1.1d.tar.gz but it failed checksum test...

So I looked into the openssl site and found the old release at https://www.openssl.org/source/old/1.1.1/openssl-1.1.1d.tar.gz

ALL GOOD at that point \ o /

patches

I also downloaded the patches it required:

http://www.linuxfromscratch.org/patches/lfs/9.1/bash-5.0-upstream_fixes-1.patch
http://www.linuxfromscratch.org/patches/lfs/9.1/bzip2-1.0.8-install_docs-1.patch
http://www.linuxfromscratch.org/patches/lfs/9.1/coreutils-8.31-i18n-1.patch
http://www.linuxfromscratch.org/patches/lfs/9.1/glibc-2.31-fhs-1.patch
http://www.linuxfromscratch.org/patches/lfs/9.1/kbd-2.2.0-backspace-1.patch
http://www.linuxfromscratch.org/patches/lfs/9.1/sysvinit-2.96-consolidated-1.patch

I built my own md5 sums and it worked

c1545da2ad7d78574b52c465ec077ed9 bash-5.0-upstream_fixes-1.patch
6a5ac7e89b791aae556de0f745916f7f bzip2-1.0.8-install_docs-1.patch
a9404fb575dfd5514f3c8f4120f9ca7d coreutils-8.31-i18n-1.patch
9a5997c3452909b1769918c759eff8a2 glibc-2.31-fhs-1.patch
f75cca16a38da6caa7d52151f7136895 kbd-2.2.0-backspace-1.patch
4900322141d493e74020c9cf437b2cdc sysvinit-2.96-consolidated-1.patch

Other helpful patches from the community can be found here: http://www.linuxfromscratch.org/patches/downloads/

tools dir

created /mnt/lfs/tools and symlinked it as sudo to /tools

The created symlink enables the toolchain to be compiled so that it always refers to /tools, meaning that the compiler, assembler, and linker will work both in Chapter 5

LFS User

We are going to build packages as a unprivileged user to be safe lfs:lfs

$ sudo groupadd lfs
# bash as default shell, in group lfs, with [m] a home dir [-k null] as empty
$ sudo useradd -s /bin/bash -g lfs -m -k /dev/null lfs
# give the user a password
$ sudo passwd lfs
# made it "lfs"
# give this user ownership of of source and tools
$ sudo chown -v lfs $LFS/tools
$ sudo chown -v lfs $LFS/sources
# switch into a login shell for lfs user
$ su - lfs

Setup user so he has safe and clean environment as lfs user

$ cat > ~/.bash_profile << "EOF"
exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
EOF
$ cat > ~/.bashrc << "EOF"
# disable remembering paths already found for commands
set +h
# new files are writable by us, read and exec by others
umask 022
# again lfs mount point
LFS=/mnt/lfs
# languages to default
LC_ALL=POSIX
# compiler technical thingy
LFS_TGT=$(uname -m)-lfs-linux-gnu
# put tool bin in front of normal bin and with hashing off it wont get wonked on wrong bin tools for this user
PATH=/tools/bin:/bin:/usr/bin
export LFS LC_ALL LFS_TGT PATH
EOF