Home‎ > ‎Mini-blog‎ > ‎

Linux from scratch

posted 31 Jul 2010, 04:12 by Andrew Conway   [ updated 7 Aug 2012, 01:35 ]
Linux from scratch (LFS) is a book that helps you through the process of compiling an entire, functioning linux operating system. There are several reasons you may wish to do this, but I think the most common reason is to gain a better appreciation for how an operating system works; this was my reason. It's probably worth setting out what is meant by an operating system and its kernel before talking more about LFS.

Strictly speaking, linux refers to just the kernel of the operating system. The kernel acts as an intermediary between the hardware and the applications that humans use so that developers aren't always getting dirty with very low-level programming. Any operating system that uses the linux kernel can be called linux. Apple's OS X, used in various forms by all recent Macs and iPhone/iPad/iPod products, uses a kernel partly based on BSD, which is a unix cousin of linux, whereas the kernel used by Windows is completely distinct from the linux and BSD kernels having been developed entirely by Microsoft. What makes the linux kernel different from Apple's and Microsoft's kernels is that the source code is open so that you are free to edit, configure and compile it yourself. In this context, compile means that you can take the source code (written in C) and turn it into binary code the computer understands. Both Apple and Microsoft only provide the binary code.

A kernel isn't much use by itself; you also need to compile some tools and applications to go with it so you can copy and move files or edit text or browse the internet. Almost every linux operating system uses tools from the GNU project to do this and for this reason some people prefer (actually try to insist) on using the term GNU/linux to refer to the operating system. This is actually quite fair, but unfortunately "GNU/linux" is just so clunky in print and in voice that I, like most people, stick with just saying "linux" to refer to the operating system. The key thing is that GNU also provides the source code so you can edit, configure and compile it yourself.

Anyway, returning to the main point, LFS is a book that provides instructions on how to compile the linux kernel, GNU tools and other essential software (referred to as the tool-chain) to construct a basic but functioning operating system. It's quite honest about the level of expertise you need to successfully accomplish this amazing-sounding feat: you need to be comfortable on a unix-like command line, understand some basics about compiling code (though you don't need to be able to program in C) and have some familiarity with the jargon used in linux-land. But, that said, if you can work in a methodological way, follow the book's clear instructions backed up by a very helpful community on the internet, I'd say that the process is much easier than you'd think - certainly much easier than I expected.

If you're interested in the details then have look at the LFS website. It took me about 10 hours of working and reading. Fortunately I didn't get seriously stuck along the way, only mildly confused at a couple of points mainly because I was over-thinking things rather than just pressing ahead. You might want to look at the notes I made - they may look pretty hard-core out of context from the LFS book but they're really not saying anything that complicated. (Reading back on my notes it seems that a local murder indirectly caused me to get started with LFS).

So what did I gain from the experience?

Well, I know much more about how operating systems work and what makes linux distributions different from each other. For example, the most popular linux distribution, Ubuntu, makes A LOT of changes to the source code before compiling it, especially the linux kernel itself, though the amended source code is still openly available (it has to be by law thanks to the GNU GPL license). In contrast, the linux distribution I use, Slackware, makes almost no changes to the source code and consequently it's much easier to understand and there's less to go wrong. So Ubuntu strives to have widespread appeal through simplicity to the user, whereas Slackware aims to keep the operating system itself as simple as possible offering the user greater control and stability.

But, more importantly, I now have firsthand proof and knowledge that compiling a computer operating system can be done. As I get older I find myself appreciating the value of firsthand experience more and more and realising just how much our society forces us to live without it. It's a bit like knowing how to grow your own food - it's not that you want to stop going to the shops, there's just something satisfying about actually doing it yourself that goes beyond even just knowing you could do it.