Post
The first big scare in Linux From Scratch
Segmentation fault in Chapter 8
Linux From Scratch is a project with step-by-step instructions for building your own Linux distribution, entirely from source code. In other words, everything has to be compiled. The project's main goal, according to its creators, is to teach how Linux works internally. When I started following LFS (Linux From Scratch), I knew I would run into problems. What I didn't know was that the first big scare would come right in chapter 8, in a part that, at first glance, seemed routine: installing glibc.
The context
I was installing LFS version 13.0 with systemd, on a partition of an external SSD, with Ubuntu as the host. I had already gone through the first chapters — toolchain, temporary glibc, binutils, GCC, etc. — and was in chapter 8, which is where the final system itself is built. I had compiled glibc and run make check without major problems.
Until, when trying to install the locales, everything collapsed.
The error
Segmentation fault
Simple, direct, and scary. Segmentation fault (or segfault) occurs when a program tries to access a region of memory that isn't allowed, such as an invalid address or dereferencing a null pointer. On top of that, the worst happened: after that, Ubuntu (the host) stopped booting.
What happened
After investigating, it became clear what had occurred: installing LFS's glibc ended up affecting Ubuntu's libraries. The make localedata/install-locales of LFS's glibc can, under certain conditions, end up installing things in the wrong place — especially if the LFS variable isn't correctly set or if DESTDIR/prefix points to the wrong place.
The result was that Ubuntu's glibc got corrupted or partially broken, and the entire system started giving a segfault on almost everything.
The diagnosis
Using the live USB, I mounted the Ubuntu partition and checked:
ls -l /mnt/ubuntu/lib/x86_64-linux-gnu/libc.so
ls -l /mnt/ubuntu/lib64/ld-linux-x86-64.so
sudo chroot /mnt/ubuntu /usr/bin/ldd --version
ldd inside the chroot gave a segfault — confirmation that the host's glibc was corrupted.
The recovery options
In that context, I basically had three paths:
-
Reinstall Ubuntu's glibc packages (if the chroot still worked partially).
-
Restore from backup/snapshot (if one existed). Since I was just doing an experiment, I had installed Ubuntu only for that. My work system is Arch Linux.
-
Reinstall Ubuntu (the safest route when there's no backup).
What I did
Since I had no backup of Ubuntu, but had made a backup of LFS up to chapter 7 (as the book's instructions say), the solution was:
-
Reinstall Ubuntu on the SSD's internal partition.
-
Restore the LFS backup (up to chapter 7) on the external SSD.
-
Continue LFS from chapter 8, now more carefully.
Lessons learned
Backups are essential. LFS already recommends making backups at critical points (such as before strip, at the end of chapter 7). I learned that the hard way.
Never install glibc without DESTDIR=$LFS. The book itself warns: “If LFS is not properly set, and despite the recommendations, you are building as root, the next command will install the newly built Glibc to your host system, which will almost certainly render it unusable.”
Don't run as root unless necessary. Building as a normal user and using sudo only to mount/create devices is safer.
Check the environment before make install. Before any make install of glibc, check echo $LFS and grep prefix ..glibc-config.make.
Avoid make localedata/install-locales on the host. In LFS, this is done inside the chroot, after the temporary system is ready.
Consider doing LFS in a VM or container. Since I already use Docker and am familiar with isolated environments, a safer option would be to run LFS inside a VM (QEMU/KVM, VirtualBox) or in a container with a bind-mount of the external SSD. That way, even if glibc breaks, the damage stays confined to the isolated environment. This is a measure that ensures the continuity of your work environment. The solution I adopted (installing on an external SSD) is also good, as long as you have that resource available.
Final considerations
That first big scare taught me that LFS isn't just about following commands — it's about understanding what each command does and where it will install things. An environment variable mistake or a misconfigured make install can break the entire host.
But it also taught me that, with backup and patience, it's possible to recover and continue. Reinstalling Ubuntu and restoring the backup up to chapter 7 allowed me to resume LFS with more safety and awareness.



Comments
Loading comments…
Leave a comment