olly - Fotolia
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:
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.
Which Linux distribution is right for you?
Interview questions every sys admin should prepare for