LowEndBox - Cheap VPS, Hosting and Dedicated Server Deals

Linux From Scratch: The Best Way to Learn Linux the Hard Way

Linux From ScratchWay back in the early days of Linux – and I do mean way back – there were no distributions.  People who wanted to play with Linux had to knit together various packages and tools to make a functional system.

This era didn’t last long.  Within a year there were distributions (such as Slackware) that eliminated a lot of this drudgery and trial-and-error by providing you with package management tools.  These distributions pre-built code, make sure everything was compatible, and provided configurations that worked without you having to read endless reams of documentation and creating your own init system.

The tradeoffs here are obvious: you’re surrendering flexibility for convenience.  For most people, this exchange is a no-brainer.  Sure, the ability to completely customize your system the way you want is cool, but if you just want to get some work done, you probably don’t care how things are laid out in /etc.

But what if you want that complete freedom?  If so, you want Linux From Scratch.

What Is Linux From Scratch?

Linux From Scratch is a project that teaches you how to build a complete Linux system from source code. You begin with an existing Linux system, create a clean build environment, compile a temporary toolchain, enter a chroot, and then build the real system piece by piece.

By the time you are done, you’ll have assembled the familiar guts of Linux yourself:

  • binutils
  • gcc
  • glibc
  • Bash
  • coreutils
  • an init system
  • the Linux kernel and bootloader
  • filesystem layout
  • basic networking
  • essential users, groups, logs, and device handling

In other words, you’ll have created your own distro.

The Book

The neat thing about LFS is that there is a step-by-step book that walks you through each stage.  So you don’t have to get the gcc sources and then read through the docs to figure out how to compile the compiler.  LFS does a lot of this heavy lifting for you.

But you’ll still be the one typing the commands and making some decisions.

Will you use it on a LowEnd VPS?  You could – assuming your provider allows a custom ISO.  Are you going to really gain anything practical vs. running Debian?  Probably not.  But you certainly could.

What You Need Before Starting

Linux From Scratch is not beginner Linux. You do not need to be a kernel developer, but you should be comfortable with:

  • The command line
  • Editing files with a terminal editor (for example, Vim)
  • Partitions and filesystems
  • Shell scripts
  • Compiling software

LFS is not hard because each individual command is mysterious but rather because the process is long and exact.  It’s easy to derail your build, which means figuring out what went wrong, backing up, and redoing things.

My personal advice is to do this on a VM, such as Virtualbox, where you can take snapshots and checkpoint your progress.  That way if you mess things up, you can effortlessly back up to the beginning of the chapter and try again.

The High-Level Build Process

The LFS process goes ike this:

  • Prepare your host system.  The book has tools to help with this.
  • Create a new partition that will hold your new LFS system
  • Build the temporary toolchain – just enough compiler and system tools to build the final system
  • Enter chroot (make your new partition “live”)
  • Finish building your system
  • Configure everything
  • Reboot
  • Pray!

When it works, it feels terrific.  When it doesn’t…congratulations, you are now learning Linux for real 😄

Should You Try It?

You will definitely learn a lot about how Linux works by building it from nothing.  Will this help you get a got as a Linux sysadmin?  Probably not.  If that’s your goal, go study RHEL.

But if you want a deeper appreciation of what all the piece parts do, then this is an excellent project.  It’s satisfying as a DIYer to point to a VM and say “I built every bit on that”.

You will definitely be a better sysadmin when you’re done.  You’ll also know more about the packages, tools, and choices that go into a distribution.  And if some day you want to build your own distro, this is a great place to start.

No Comments

    Leave a Reply

    Some notes on commenting on LowEndBox:

    • Do not use LowEndBox for support issues. Go to your hosting provider and issue a ticket there. Coming here saying "my VPS is down, what do I do?!" will only have your comments removed.
    • Akismet is used for spam detection. Some comments may be held temporarily for manual approval.
    • Use <pre>...</pre> to quote the output from your terminal/console, or consider using a pastebin service.

    Your email address will not be published. Required fields are marked *