Linux From Scratch

This blog will be to document my exploits and adventures with “Linux From Scratch”. I’ve recently made the full time switch to Linux, and after a few months (time really flies) I’m loving it. However, I keep running into issues as one does, and I feel like every time I learn how something works, and how to fix something, another problem occurs a layer below. So I’ve decided to flip the situation on its head, and learn from the ground up.

My hope is that knowledge of how Linux works from the bootloader up to the desktop will enable me to use the operating system in a more powerful, directed way. I’m also hoping it will give me the starting knowledge that I need to eventually contribute to the project. Plus, it just seems like fun.

The Setting
I’ll be doing this project over some time. I know it’s intended for 1-2 sittings, but I’m a PhD student in the completely unrelated field of biochemistry, I take classes, do research, and teach multiple chemistry labs. So I know it’s going to take me a while, because free time is not exactly something I have a lot of right now.

Another reason it’s going to take a while is that I’m installing it on an old Lenovo IdeaPad S405. This thing cost me $300 in 2013, and was sluggish then. It has a 2.1GHz AMD A6-4455M. I did upgrade the RAM to 8GB, but the hard drive is as slow as molasses that just woke up from a nap. So that’s another reason why this will be taking a while. Compiling is not going to be quick.

In addition to LFS, I intend to also do the “Beyond Linux From Scratch” to further build out the system, although I may actually switch to my much more capable desktop PC once I get that far, assuming it’s stable.

I will update this blog with the progress I am making, issues I’m encountering, and just general thoughts as I progress throughout the project.

9 Likes

Love this!

Have been thinking of doing this myself - The knowledge gained should be immense!

4 Likes

Yes! I always wanted to see someone do it and document it.

I wish you luck, bro!

2 Likes

Linux From Scratch is a great learning experience. From doing it myself I would advice running and paying close attention to the tests as they really do help a lot to understand whats going on and pin point issues with your build early so you don’t get any nasty surprises, also if you can try and take backups after each major section e.g. building the toolchain, installing the basic system, configuration (the toolchain at the very least) as if something goes horribly wrong later in the build you can revert back without having to spend a day building the entire system again. I had to do this a couple of times due to issues with my build and killing two usb drives that I attempted to install it on and would’ve saved me a lot of time and headache.

Most of all good luck and have fun with it.

3 Likes

I can’t agree with or stress this enough. The likelihood of something going irrecoverably wrong — and needing to ‘start over’ from scratch — is extremely high unless you do this. Anyone with a limited amount of free time must do this in order to preserve their own sanity and give themselves a fighting chance of making it all the way through.

4 Likes

Setting Up

The first step was setting up the partitions on the host system. I’m running Kubuntu 18.04 acting as my host. Unfortunately, when I installed it, I mindlessly clicked “Use entire disk”, so I had to boot a live drive, and repartition the disk (which I did with KDE Partition Manger). I then made a 40GB /dev/sda3 partition, and an 8gb /dev/sda4 which I wanted to use as a swap drive.

However, running /sbin/swapon -v /dev/sda4 did not work, so I need to look into that. In the meantime, I decided to get the jump on downloading the files. I’ve never used a list before, but literally you just put a URL on each line, and use --input-file (or possibly -i?), and it downloads them one by one. Below is my wget-list in case anyone would like it:

wget-list

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-4.4.18.tar.gz
http://ftp.gnu.org/gnu/bc/bc-1.07.1.tar.gz
http://www.gnu.org/software/binutils/
http://ftp.gnu.org/gnu/binutils/binutils-2.31.1.tar.xz
http://ftp.gnu.org/gnu/bison/bison-3.0.5.tar.xz
http://anduin.linuxfromscratch.org/LFS/bzip2-1.0.6.tar.gz
https://github.com/libcheck/check/releases/download/0.12.0/check-0.12.0.tar.gz
http://ftp.gnu.org/gnu/coreutils/coreutils-8.30.tar.xz
http://ftp.gnu.org/gnu/dejagnu/dejagnu-1.6.1.tar.gz
http://ftp.gnu.org/gnu/diffutils/diffutils-3.6.tar.xz
https://dev.gentoo.org/~blueness/eudev/eudev-3.2.5.tar.gz
https://downloads.sourceforge.net/project/e2fsprogs/e2fsprogs/v1.44.3/e2fsprogs-1.44.3.tar.gz
https://sourceware.org/ftp/elfutils/0.173/elfutils-0.173.tar.bz2
https://prdownloads.sourceforge.net/expat/expat-2.2.6.tar.bz2
https://prdownloads.sourceforge.net/expect/expect5.45.4.tar.gz
ftp://ftp.astron.com/pub/file/file-5.34.tar.gz
http://ftp.gnu.org/gnu/findutils/findutils-4.6.0.tar.gz
https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz
http://ftp.gnu.org/gnu/gawk/gawk-4.2.1.tar.xz
http://ftp.gnu.org/gnu/gcc/gcc-8.2.0/gcc-8.2.0.tar.xz
http://ftp.gnu.org/gnu/gdbm/gdbm-1.17.tar.gz
http://ftp.gnu.org/gnu/gettext/gettext-0.19.8.1.tar.xz
http://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.xz
http://ftp.gnu.org/gnu/gmp/gmp-6.1.2.tar.xz
http://ftp.gnu.org/gnu/gperf/gperf-3.1.tar.gz
http://ftp.gnu.org/gnu/grep/grep-3.1.tar.xz
http://ftp.gnu.org/gnu/groff/groff-1.22.3.tar.gz
https://ftp.gnu.org/gnu/grub/grub-2.02.tar.xz
http://ftp.gnu.org/gnu/gzip/gzip-1.9.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-4.18.0.tar.xz
https://www.kernel.org/pub/linux/utils/kbd/kbd-2.0.4.tar.xz
https://www.kernel.org/pub/linux/utils/kernel/kmod/kmod-25.tar.xz
http://www.greenwoodsoftware.com/less/less-530.tar.gz
http://www.linuxfromscratch.org/lfs/downloads/8.3/lfs-bootscripts-20180820.tar.bz2
https://www.kernel.org/pub/linux/libs/security/linux-privs/libcap2/libcap-2.25.tar.xz
ftp://sourceware.org/pub/libffi/libffi-3.2.1.tar.gz
http://download.savannah.gnu.org/releases/libpipeline/libpipeline-1.5.0.tar.gz
http://ftp.gnu.org/gnu/libtool/libtool-2.4.6.tar.xz
https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.18.5.tar.xz
http://ftp.gnu.org/gnu/m4/m4-1.4.18.tar.xz
http://ftp.gnu.org/gnu/make/make-4.2.1.tar.bz2
http://download.savannah.gnu.org/releases/man-db/man-db-2.8.4.tar.xz
https://www.kernel.org/pub/linux/docs/man-pages/man-pages-4.16.tar.xz
https://github.com/mesonbuild/meson/releases/download/0.47.1/meson-0.47.1.tar.gz
https://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz
http://www.mpfr.org/mpfr-4.0.1/mpfr-4.0.1.tar.xz
https://github.com/ninja-build/ninja/archive/v1.8.2/ninja-1.8.2.tar.gz
http://ftp.gnu.org/gnu/ncurses/ncurses-6.1.tar.gz
https://openssl.org/source/openssl-1.1.0i.tar.gz
http://ftp.gnu.org/gnu/patch/patch-2.7.6.tar.xz
https://www.cpan.org/src/5.0/perl-5.28.0.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.1.tar.xz
https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
https://docs.python.org/ftp/python/doc/3.7.0/python-3.7.0-docs-html.tar.bz2
http://ftp.gnu.org/gnu/readline/readline-7.0.tar.gz
http://ftp.gnu.org/gnu/sed/sed-4.5.tar.xz
https://github.com/shadow-maint/shadow/releases/download/4.6/shadow-4.6.tar.xz
http://www.infodrom.org/projects/sysklogd/download/sysklogd-1.5.1.tar.gz
http://download.savannah.gnu.org/releases/sysvinit/sysvinit-2.90.tar.xz
http://ftp.gnu.org/gnu/tar/tar-1.30.tar.xz
https://downloads.sourceforge.net/tcl/tcl8.6.8-src.tar.gz
http://ftp.gnu.org/gnu/texinfo/texinfo-6.5.tar.xz
https://www.iana.org/time-zones/repository/releases/tzdata2018e.tar.gz
http://anduin.linuxfromscratch.org/LFS/udev-lfs-20171102.tar.bz2
https://www.kernel.org/pub/linux/utils/util-linux/v2.32/util-linux-2.32.1.tar.xz
ftp://ftp.vim.org/pub/vim/unix/vim-8.1.tar.bz2
https://cpan.metacpan.org/authors/id/T/TO/TODDR/XML-Parser-2.44.tar.gz
https://tukaani.org/xz/xz-5.2.4.tar.xz
https://zlib.net/zlib-1.2.11.tar.xz
http://www.linuxfromscratch.org/patches/lfs/8.3/bzip2-1.0.6-install_docs-1.patch
http://www.linuxfromscratch.org/patches/lfs/8.3/coreutils-8.30-i18n-1.patch
http://www.linuxfromscratch.org/patches/lfs/8.3/glibc-2.28-fhs-1.patch
http://www.linuxfromscratch.org/patches/lfs/8.3/kbd-2.0.4-backspace-1.patch
http://www.linuxfromscratch.org/patches/lfs/8.3/ninja-1.8.2-add_NINJAJOBS_var-1.patch
http://www.linuxfromscratch.org/patches/lfs/8.3/sysvinit-2.90-consolidated-1.patch

Total size was 367 megabytes.

I then moved on to Chapter 4, which is the last few steps before really getting started. First I had to make the tools directory, and then make a symlink to the host / directory as well. I made a user and group lfs so I wouldn’t have to work from sudo, and made them the owner of lfs/tools and lfs/sources. I then logged in as the lfs user, and created their .bash_profile and .bashrc

Ready to go. I will probably do a backup and start system building later in the week.


Any suggestions on good backup methods? I’ve never really done much backing up of stuff on Linux.

3 Likes

It depends on how far you want to go. What I ended up doing was taking a compressed gz image of the entire drive I was installing LFS ans saved it as a file on another hard drive using dd and just flashed it back if I ever needed it, this can take a while though depending on how large your drive is so might not be your everyone. additionally if that doesn’t work you could also rsync your /mnt/lfs dir someplace else making sure to perverse permissions etc and copy the files back if it ever gets messed up, either should get you back where you were when you took the backup.

1 Like

When I’m doing this sort of stuff I make use of the ancient (up to 9 year old) SSDs that I have lying around, and just clone the whole SSD to another (same size or larger) SSD.

You can do it in software:

…or you can get yourself a drive dock that supports cloning. I use an ORICO 2.5 / 3.5 inch 2 Bay USB3.0 1 to 1 Clone Hard Drive Dock that I picked up years ago. Can’t say it’s particularly fast, but in my mind you can’t beat:

  1. plug in source drive
  2. wait a few seconds
  3. plug in destination drive
  4. wait a few seconds
  5. press the clone button
  6. walk away

No host computer or software required.

I realise that you’re doing this on a laptop (or whatever the heck a Lenovo IdeaPad S405 is), so dock-based cloning might not be practical. I mention it more for the benefit of others that might come across this thread and have more easily-accessible drives.

NB: The above is not a recommendation for the Orico dock. At the time of purchase (quite a few years ago) I was in a hurry and it was all I could source locally at the time. I’ve never used the 3.5" slots and it took a while to learn the dock’s ‘quirks’. It has, however, cloned flawlessly for years. If I was in the market for a new one I’d get a smaller unit that just has two 2.5" slots and stand-alone cloning — that’s a must as far as I’m concerned.

2 Likes

“Linux from scratch” includes a lot of packages that are extraneous from the point of view of a barebones, usable linux system.

If you want something leaner, Rob Landley’s Aborinal Linux (https://landley.net/aboriginal/about.html) and its successor project mkroot (https://github.com/landley/mkroot) might interest you.

Both projects aim to be the smallest possible, self-hosted system (build itself under itself from source). Conceptually it’s a kernel, c library, tool-chain and busybox/toybox as a GNU cli replacement that at one point was only 5 actual packages. They even have a build script that will download the packages, build an image, and then boot it up in qemu.

Landley walked through it in a Linux foundation talk :

Unfortunately He stopped maintaining Aborignal Linux (https://landley.net/aboriginal) for its musl/toybox moral equivalent “mkroot” ( with the ultimate purpose of making Android self hosted.

1 Like

extraneous but still nice to have

2 Likes

I don’t at all intend to derail the thread but thought it might be a good spot to ask for advice on LFS. I’ve considered doing it for some time but kept getting sidetracked, now have some time and this thread is inspiring me to start.

Is it recommended to use the ‘default’ book or the systemd variant? I’ve poked around at Mint and a couple of other distros but never as a dedicated daily driver - what are the advantages / detriments to either option when starting LFS? My googling has led me to strong opinions in either directions with arguments that are above my experience level.

Thanks in advance.

2 Likes

How goes it @COGlory?

4 Likes