Get started Bring yourself up to speed with our introductory content.

Build Linux from scratch to improve admin skills

There's a sure-fire way to increase your knowledge about the Linux kernel and how to troubleshoot Linux servers: Build one yourself.

As a system administrator, what better way to know the platform you work with than to put it together into a working,...

cohesive whole?

When you build Linux from scratch, you come to fully and completely understand the Linux platform. Linux admins already have a certain mystique in the IT community for knowing more about the inner workings of a computer than any other IT pro. Although that isn't exactly quantifiable, it is a logical conclusion, in part because of the ability to build your own Linux operating system from scratch (LFS). You can specify everything you want on that distribution, package it and distribute or simply use it for yourself.

You might want to build your own Linux distribution to have one specifically tailored to unique needs, or to learn as much about the Linux platform as possible and fully understand the operating system.

The process to build Linux from scratch is complicated. For anyone serious about building a Linux distribution, the book Linux From Scratch is a must. You can download a copy of the book for free or view the online version and interact with the LFS community. First though, plan your approach to learning Linux from scratch to avoid being overwhelmed by the complexity of the endeavor.

Prerequisites for success

Building Linux from scratch takes time and an understanding of Unix/Linux system administration. If you do not already administer Unix or Linux systems, or have a background in the field, get familiar with Linux first.

You'll need to have a solid understanding of the Linux command line; there are no GUI tools to aid you when you start from scratch.

Be sure that you can:

  • Copy and move files and folders via the command line;
  • List files and folders via the command line;
  • Change the current working directory from the command line; and
  • Use and install Linux software (installing software from source is a must).

While this will get you started on the build, without proper admin skills, you still might get a bit lost.

Construct your distribution on an established Linux host system such as Debian, Ubuntu, openSUSE or Fedora. The host must have enough space on its drive to create a dedicated partition for your distro build. A minimal LFS build requires a partition of around 4 GB, but 10 GB is best suited to provide growth and additional packages. If your host doesn't have a lot of RAM, consider creating a swappartition. The LFS system can use the same swap partition found on the host.

Aim to put the LFS build on a modern release of your distro. However, the Linux From Scratch manual recommends specific versions of every piece of software -- these versions are known to work without causing problems for the LFS build.

Prepping for the build

One of the most important steps is to create the new partition for your Linux build, which has to be installed on a dedicated partition on your host system. If you do not know how to use the command-line partitioning tools, pause your LFS build and familiarize yourself with this skill.

Use a command-line tool such as cfdisk or fdisk, making sure to name the partitions according to the standard Linux naming scheme, such as /dev/sda for the primary IDE device. More information on partitioning requirements, such as required and optional partitions for the LFS build, is in the Linux From Scratch manual.

Name the directory where you will be building your LFS; create the directory /mnt/lfs and build within it. Set an environment variable LFS as well, which will be short for the explicit path /mnt/lfs. This is done with the export command:

export LFS=/mnt/lfs

Now, you can run such commands as mkdir $LFS/tools to create the subdirectory /mnt/lfs/tools (a temporary location to build a set of temporary packages). This saves time on the build process.

The bare minimum of packages required:

Bash, Binutils, Bison, Bzip2, Coreutils, Diffutils, Findutils, Gawk, GCC, Glibc, Grep, Gzip and Linux Kernel.

Packages and building

One of the most tedious aspects of LFS is downloading all the packages you need. There's a complete list (including links) to all packages you need for a minimal LFS. Create a source directory within $LFS (such as $LFS/sources) to store the packages.

You will also have to download multiple patches. These patches correct mistakes made by maintainers that cause problems with the LFS build.

The final steps of preparation are to create an LFS user and set up the working environment. You must create startup files for the bash shell to use. What you gain at this step is crucial for Linux system administration -- bash scripting is one of the first things administrators tend to overlook.

Bash scripts add a lot of flexibility to a system. For example, admins can use bash scripting to create an automated backup process for a Linux server. As you build LSF, you'll learn how bash scripting works by creating a user environment.

The more you know

The Linux from scratch build is split into two sections: the minimal tools that construct the final LFS system, and then that system itself. Build each package one at a time. Make sure you follow the specific directions in the LFS manual to know which tools to build for which section and in what order.

Building packages is a task that will follow you throughout your Linux admin career. Even if you primarily use platforms that have package management systems, there will be times when you must install a package from source. You might even want to compile a package (such as PHP) specific to your environment. The package build process also gives Linux users a fundamental understanding of package dependency and how to resolve issues that it creates.

Once you have all of the tools built, configure the LFS system configuration, create the boot scripts, and make the LFS bootable.

The process of creating Linux from scratch is not an endeavor for the everyday user. But once you have accomplished a successful LFS build, your knowledge of Linux and ability to administer Linux systems will be far greater than those that have never encountered LFS.

Next Steps

Which Linux distribution is right for you?

Interview questions every sys admin should prepare for

This was last published in June 2015

PRO+

Content

Find more PRO+ content and other member only offers, here.

Essential Guide

Expert tips for a next-generation data center

Join the conversation

4 comments

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

What advice do you have for others building Linux from scratch? What was the build process like?
Cancel
I've been distro hopping for a long time, mostly because I found Ubuntu etc. to be too "heavy", but I've used Arch Linux for the last year and been very happy with it.
I think maybe I should look into this some day, both to learn more and get what I want without all the other "useless" packages around, even though I find Arch kinda "light".
I did try Gentoo but the wiki (not really up to date) and the USE flags was a bit much. My main reason for thinking so is that I also tried Arch Linux around the same time. The wiki on Arch Linux is the best I've ever seen. It's usually the only thing I need to get up and running. Forums and IRC also feels very friendly.
They also have the combo of being able to build packages and/or install pre-built ones so I could get my computers up and running fast, or just take my time and get the packages built.
I do love the thought of being able to learn more about Linux in general from the LFS, but I'm not really convinced that I can use it in other distros. Maybe I'm just lazy and need a kick in the butt :P
Cancel
Better yet, buy a book and learn how operating systems work. Operating Systems by Andrew Tanenbaum or something similar.

Learning how to build a LFS from scratch is very different from understanding how the operating system works. Any real expert in Linux must not only know how to assemble Linux, he needs to know how it works.

Just like any good mechanic must really know how the engine and the components in your car works.
Cancel
The best resources for learning or improving your admin skills are the books that prepare you for the RHCSA or LPI certifications. These books are very comprehensive, detailed and accurate.
Cancel

-ADS BY GOOGLE

SearchWindowsServer

SearchServerVirtualization

SearchCloudComputing

Close