Linux From Scratch
This is a review of my experience of building a complete Linux
system from scratch using the tools and information provided by
I've been using Linux for several years now, mostly Debian and
although I am mostly happy, I've always thought I was missing
something. I've also found myself having to install unstable
packages just to get some features I wanted.
Now that I'm unemployed and have loads of time on my hands I
figured I see what I've been missing out on.
I've got an idle Dell OptiPlex GL 5100 with;
- 200Mhz PentiumMMX
- 128M RAM
- 6G hard drive
- On-Board S3Trio64+ with 1M video memory
- GVX1 PCI 32M video card
- 3C509 network card.
The Linux From Scratch project is basically a set of documentation that
explains, step-by-step, how to build a minimal Linux system purely from
sources. They also provide all the sources to go with the documentation.
Either as separate .tar.bz files or all the .tar.bz file in one 85M tarball.
This is handy because you know that the versions all match and work together.
I won't explain the entire process, their document does a great job of that,
but I will highlight the general steps followed.
Also, since Linux From Scratch leaves you with a minimal system, I also built
XFree86 and KDE3 using a mix of other information provided by Linux From
Scratch and the README's and INSTALL files from the relevant packages.
Before you can build Linux on a computer, you have to have Linux on the
computer. After all you need to have compilers and shells and such before you
can compile anything, even compilers, shell and such. It is also highly
recommended to build the system into a separate partition.
What I did was to partition the hard drive for the new Linux from scratch
system with separate partitions for /, /usr, /var, and /home. By using this
partition scheme, / can be kept very small for easy backup. Here is the layout
- hda1 100M /
- hda2 256M swap
- hda3 2G /home
- hda5 1G /var
- hda6 2G /usr
But I made hda3 bootable. Next I installed a minimum Debian Woody system into
hda3 and using the swap file but left the rest of the partitions alone.
Now the system boots from hda3 as a regular Debian system. Now I can create
the filesystems on the other partitions and mount them under a convenient
The general idea is, using this Linux system, you build the absolute minimum
tools into the new partitions that will be the Linux from scratch /.
These packages are built from an unprivileged user to avoid trashing the
existing system and they are built statically since the partitions they are
being installed to do not have any libraries on it. Once there are enough
tools on the new partitions to build packages chroot is used to become root
within the new partition scheme. Now everything is rebuilt within the new file
structure with shared libs rather than statically linked. Finally initial
config files are created, the bootscripts are made and the last step is to
modify lilo on the original Linux to boot the new system properly.
Once the new system is booted, you re-run lilo from the new system so
everything is in sync.
Since I wanted the system to be fully optimized for the PentiumMMX I set
CFLAGGS and CXXFLAGS="-O3 -march=i586 -mcpu=i586". The documentation
recommends NOT using these with binutils, GlibC or GCC. I found that once I
chroot'd I was unable to build GlibC with the optimized GCC. The simple fix
was <ALT> <F2> to a new terminal and rebuilt GCC without the optimizations.
However, I did build GlibC and binutils with the optimizations enabled. I'll
have to wait and see if it causes any problems.
Since many of the tools are first built from the old system statically with
prefix set to $LFS/usr and then re-built in the new system dynamically with
prefix set to /usr it's a good idea to just remove the original build
directory as soon as you've installed the program. Then when you re-build it,
you do so from a fresh directory and don't have to worry about and dodgy
The instructions provided are rather complete, including several patches and
even a few sed scripts to fix temporary problems, like telling GlibC that perl
will be in /usr/bin/perl since it's not installed when GlibC is built.
Once the instructions are finished, you will have an absolute minimum Linux
system. Even vi is a softlink to vim and yacc is a shell script that calls
bison in yacc mode. Of course even the most hardened CLI jockey would not
consider this to be Linux. But you know exactly what programs are installed,
where they are and how the bootscripts run since you have written them!
The first problem I had is there is absolutely nothing about setting up
modules. Since this has never been my strong point I had quite a bit of time
just getting my network card to load at bootup. I still need to play around
with the other modules but there is plenty of time for that.
The last step of my particular build is, once I get the lfs system running
from hda1 is to wipe the old Debian from hda3 and mount this as /home. A
simple mke2fs /dev/hda3 wipes the partition clean and a quick edit of
/etc/fstab adds the /home partition.
So now I've got a minimal Linux system that boots fine, but I want X and a
decent Desktop/Window manager. No fear, Linux From Scratch also has Beyond
Linux From Scratch, but it's a work in progress. There are also loads of
'hints' available covering topics from improving the shadow setting to how to
build various print setups.
Since I'm already tracking XFree86 and DRI cvs, I just tar.bz'd my cvs
directory and fpt'd it to the new box. But, the new box does not even have ftp
so now I need to find it. Have you ever tried to google for the ftp source code?
I eventually found it at freshmeat under netkit-combo. So a quick
./configure && make && make install and I've got ftp. Having checked the x hints and the BLFS
doc's I know the X requires zlib to work, so I just fetch zlib and build and
install it. Now I can build X. If you've never built X before it's fairly
simple but different from most Linux projects. Rather than ./configure && make
&& make install you just run make World.
Rather than building X in the source tree, I was going to use a trick from the
DRI instructions to use a parallel build tree. This way, if things go wrong,
you can rm -r the build directory and still have fresh sources.
In the XFree directory:
ln -s xc XFree420
lndir -silent -ignorelinks ../XFree420
Unfortunately lndir is part of XFree86. In order to use it I need to build
XFree86 first. Talk about a chicken and an egg;-)
If you want DRI as well you have to build and install XFree86 first then build
and install the DRI stuff. You will also need to copy the DRI kernel modules
to the proper libs directory.
http://www.xfree86.org/4.2.0/DRIcomp.html has the basic instructions, and
http://dri.sourceforge.net/doc/DRIuserguide.html has specific instructions.
If you want DRI then you probably already know this. If not, RTFM.
Now that X is installed, it need to be configured. With my GVX1 card the
graphical configure fails. There is also the problem that this box has two
video chips and XFree86 gets confused. Fortunately there is a -textmode that
uses a nice ncurses interface to walk you through the setup. Once the config
file is working I can use either startx or xinit to test X. I still need to
figure out if I can get the S3trio64+ and the GVX1 to play nicely in dual-head
mode. But that will be another story.
Now that I've got X working, I need a decent Window Manager. twm just does not
cut it for me. For simplicity and speed, I decided to start with xfce since
it's nice and small and shouldn't take too much extra to build.
A quick check of the xfce web site tells me everything I need. It also
recommends a very small web browser, dillo that is less than 300k source! Most
of what's needed are just various graphics libs, such as jpeg, png and gif,
but gif falls under a copyright dispute, so I get ungif to convienently
side-step the copyright issues. This is my first major deviation from the
guides, but having compiled the rest of the system, I've a fairly good idea of
what I need to do. The main issue is that most packages expect to go into
/usr/local/ and since I am building the system from scratch, I
want to change this to /usr instead in most cases. The main thing is to read
the doc's provided and check the ./configure options first.
Now that I've got a basic Desktop/Window manager, the X desktop is quite
usable, though there are many things that need adjusting now. For instance,
xfce assumes that you have netscape installed as the regular browser. Of
course this is one of the few tools that xfce doesn't provide. Having
installed dillo instead, based on the previous recommendation, it's a quick
config file change to select this as the default browser. Dillo is quite good
and quick, but it's lacking in one important aspect, it does NOT support
passwords, this means that I can't use CUPS, which I installed for printing
without disabling the security first, and I can't use my SmoothWall gateway at
all. I'm NOT going to disable the security on that! However, I can use
SmoothWall from my regular desktop and once I've dialed up, I can surf from
the new box just fine!
I mentioned CUPS. This deserves a bit of forewarning. CUPS, Common UNIX
Printing System requires GhostScript, of course, to work. GhostScript is the
basic printing software for ALL of UNIX. Unfortunately, there was a lot of
work added to GhostScript in the 5.50 series to support a lot of printers that
was subsequently dropped by GhostScript. The bottom line is, if you need
printer support, the 5.50 series of GhostScript has much better support than
the latest. Fortunately CUPS comes to the rescue! EasySoft, the makers of CUPS
have been diligently maintaining all the new printer drivers and provides
their own version of GhostScript that has all the latest and greatest printer
drivers included. I spent several days fighting this problem until I found
this out. Their version is called espgsX.X and has been kept up to date with
the regular GhostScript versions. Save yourself loads of time and just fetch
the espgs version first. Before you can compile GhostScript, either version,
you will need the sources for zlib, libpng and libjpeg. Not just the lib's but
the actual sources, linked into the GhostScript build directory. Be sure to
checkout the documentation for all the gory details. But, the latest version
now has a configure script that is only briefly mentioned. It's a good idea,
once you've added the links for zlib, libpng and libjpeg to try ./configure
first. Then you can run make and make install. Just watch that you put it
where you want it, I.E. /usr/bin instead of /usr/local.
Once I had GhostScript installed properly, then I could build and install
CUPS. Again, this was fairly straight forward. The only problems I've had was
that the web interface tends to miss a lot of the configuration. I found it
was much more reliable to configure it from the commandline and use the web
interface just for testing.
Now it's time to try KDE3.0Beta2 that I've got on a dvd. First I need to build
the qt libs. I had a bit of trouble with this until I realized I was trying to
use object prelinking wich is more trouble than it's worth. Once I disabled
object prelinking, I was able to build qt libs. These are a little strange. qt
libs expects to be installed in the directory it's built in. And remember, I
want everything to be based from /usr instead of /usr/local, so to make things
easy to upgrade, I unpack qt libs in /usr/qt3.0.2, build it there and then
create a symlink to /usr/qt. There is a lot of reading before you start. The qt
doc's explain how to set you environment variables and the BLFS book has a few
tips, but it expects to install in /usr/local as well, so you need to modify
these instructions. Once the qt libs are built, it's time to build KDE3.
Or so you would think. KDE requires even more tools before you can build it. The
BLFS book has most of the details for these. Once I've got the requirements,
like arts, openssl and such, I can finally build KDE. I did have one other
problem. While building kdebase, it was not able to find one of the font tools
it needed for international fonts. After a bit of trial and error, I eventually
just disabled this in the Makefile and built again. KDE is a large system and
has many parts, so it's important to compile them in the right order. First you
need to compile kdelibs, then kdebase. Once these are done, the rest are not as
important but it's a good idea to check the output of ./configure before running
make because some of the packages will warn you if you should compile something
else first. So now I have a full KDE3.0BETA2 desktop on the system I built from
This takes care of most of my requirements in a desktop, but there are still
more app's I want. First, POV-Ray. It took a bit of looking to find the source
code version. Again, compiling and installing was quite straight forward by now.
The next was KPovModeler, a KDE graphical front-end for POV-Ray. This required
the glut lib in addition to the OpenGL stuff provided by the XFree86-DRI. This,
in turn led to some more problems. KPovModeler could not figure out how to
include the proper lib's to compile. I found out that this was due to libglut.la
missing. This provides a list of required libraries for compiling. Once I got a
copy of this, I was in business again. I'll still be adding to this. I've
installed OpenOffice, but not from source. I may be crazy, but I'm not insane!
I've also installed Creatures Internet Edition. Both are dog slow, but it's only
a 200Mhz PentiumMMX.
Well, it's been a long, slow process. Just fetching all the sources took quite
a bit of time on my dialup connection. The problem with compiling GCC with
optimizations enabled caused me to backtrack a bit. Fortunately, the
documentation was very complete. I feel I've learned a lot about just what it
takes to make a Linux system tick. I certainly have a better idea of what's
installed on this box than my regular desktop. It's been a great learning
experience, which was why I started it in the first place. I've considered
re-building my regular box this way, but I don't think I'm ready for that just
yet. However, I do feel ready to build custom Linux systems from scratch now.
I've got a good starting point and I have a better understanding of the entire
Would I recommend this to anyone? If you're familiar with Linux, absolutely!
It's a great way to get under the bonnet. Even if you've only used ready-made
distro's before, you've probably got enough experience to follow the doc's
provided and successfully build a bootable system.
If you're new to Linux, this might be a bit too far just yet. An alternative
is try to find someone with experience who is willing to build one of these
for you. As I often say in reply to arguments that Linux was too difficult
for the average Joe, the configuration can be difficult, but there is no
reason why ANYONE can not use a Linux system once it's been setup. My
daughter's been using one for two years now and rarely needs my help. In fact
I have to help her with her Windows system more than the Linux one.
One thing that still amazes me is just how fast the system boots! Since it
doesn't load anything that is not absolutely nesessary, the boot time is a few
seconds rather than the several minutes my Dual PII350 takes to boot Debian.
I hope this has encouraged some of you to have a closer look at Linux From
About the author, John Gay.