My Linux From Scratch build downloads every source tarball and patch itself, with curl, from a Makefile, and it's meant to run unattended from an empty directory to a finished system. Downloads turned out to be one of the least reliable parts of that. Three separate problems in August each stopped or quietly damaged a run, and each has a fix worth copying into any build that fetches its own sources.
1. The GNU server that timed out
During a rebuild, ftp.gnu.org stopped answering, timing out over both IPv4 and IPv6, and the packages step stalled partway through. Every GNU package in the build, autoconf, bash, coreutils and many more, came from that one host.
The fix pointed all of those URLs at ftpmirror.gnu.org instead. GNU's own page on downloading describes it as a generic address that automatically chooses a nearby, up-to-date GNU mirror, serving the same release files. One host going down no longer stops the build.
A small detail from checking it for this article: GNU's page says ftpmirror.gnu.org corresponds to ftp.gnu.org/gnu, so the documented form of a URL has no /gnu/ in its path. The build's URLs kept the /gnu/. In my test, both forms redirected to the same file on a mirror, which answered 200, so the build works either way. The form without /gnu/ is the one GNU documents.
2. Patches that were 404 pages
The Python build script for the book's chapter 7 applied two patches, an OpenSSL one and a security-fixes one, downloaded by the Makefile from the LFS patches directory. Neither file had ever existed there. Today the LFS 13.0 patches directory holds six patches, and none is for Python; the book's chapter 7 page for Python applies no patches at all.
What made this easy to miss is the same mistake that bit the coreutils patch in this build: the download rule ran curl -L -o without --fail. Without that option, curl treats an HTTP error page as a successful download and writes it to the output file. So the build had two "patches" on disk that were HTML error pages, and nothing complained until chapter 7 ran for real and tried to apply them. The fix removed both the patch steps and their download rules.
The general fix is one flag. With curl --fail, a 404 makes curl exit with an error and write nothing, so a missing file stops the build at the download instead of surfacing much later as a strange patch failure.
3. Checksums for files you deliberately don't have
The build checks downloads against the book's own list of MD5 checksums, with md5sum -c. But the build intentionally pins newer versions than the book for several packages, among them linux, mpc, perl, texinfo, util-linux and xz. The book's list names files that this build never downloads, so md5sum -c reported them missing and failed, and with it every run of make.
The fix added --ignore-missing, which, in the words of its manual, doesn't fail or report status for missing files. Every file that is present and listed is still verified.
There's a gap in that fix worth stating plainly, because it's easy to read past. md5sum -c only checks the files named in the list. The newer versions this build pins aren't in the book's list at all, so those packages aren't checked by anything. The proper fix is the project's own checksum list for the versions it actually uses, which the book's list can't provide.
What generalises
For any build that fetches its own sources: use a mirror redirector where one exists instead of a single origin server, always use curl --fail so an error page can't become a file, and know exactly which files your checksum step covers, since "all checks passed" only speaks for the files it was given.
Leave a comment
Comments are reviewed before they appear.