Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Distcc & Distributed Computing


Gentoo Linux

By Trevor Marshall

It has been 10 years since Patrick Volkerding announced the Slackware 1.00 Linux distribution (http://www.slackware.org/announce/1.0.php). The succeeding Slackware releases served me well, but for a few years Slackware fell a little behind in the GUI race and the lure of a well-integrated KDE forced me to take a look at Red Hat and SuSE.

When I first booted the SuSE installation CD I became aware of a major problem—new distributions were "optimized" for the most recent CPUs. My aging Toshiba Libretto mini-laptop has a 133-MHz Pentium MMX, but even when I cross-compiled the SuSE kernel specifically for PENTIUM-MMX, utilities and compilers would not run unless they, too, were recompiled. (I ran into the same problem when upgrading my DSL firewall/server, which even today runs a 450-MHz Celeron Mendocino.)

After weeks of chasing my tail, I decided to take the plunge into a source-code-based distribution—one where I had source code for everything, and where I could select the level of optimization needed for each of my machines. I found this in Gentoo Linux (http://www.gentoo.org/), which in some ways is a distribution created primarily for programmers who optimize and reoptimize their code.

In addition to being source based, Gentoo has Portage, a package-handling system inspired by the package tools available within BSD. Whenever an update is required for a component (for example, if a security glitch is found in Apache), you don't need to manually integrate the patches. Two Gentoo commands—emerge sync and emerge -u apache—download a new package source tree, compile it, and bring your system fully up to date.

The first command (emerge sync) merges in a new sync tree, effectively downloading a list of the latest versions of each package in the Gentoo distribution. The second command (emerge -u apache) then downloads and installs the latest version of Apache, together with all the libraries and applications it needs to function.

Portage automatically handles package interdependencies. For instance, it used to take hours to compile a new version of AirSnort or Kismet into SuSE. Interdependence upon each other, Ethereal, and PCAP usually created a version nightmare. But installation of the component from the latest Gentoo net-wireless package (http://www.gentoo-portage.com/browseportage.php?category=66/) ensures all dependencies are satisfied, and makes installation and maintenance a breeze.

Portage has a -p switch (the "pretend" function) that lets you test the functions performed by an emerge command. For example, emerge -pu apache lists all the tasks needed to upgrade apache, so that you can manually assure yourself that Portage is going to do all the right things.

Installing Gentoo

When installing Gentoo, you first must keep the target processor in mind—x86, PPC, Sparc, Alpha, AMD64, MIPS, ARM, or IA64. Different targets have different levels of support. I have only used the x86 and PPC versions. Although both were complete and reliable, in this article I'll focus on the x86 installation process.

Gentoo has a database dedicated to cataloging the most recent versions of each available module for each available architecture (http://packages.gentoo.org/). The database is updated daily with a list of all upgraded packages and is worth watching—not so much to keep track of updates, but to look at new applications and features as they are integrated into Gentoo.

Gentoo initially boots from a 96-MB CD (called the "basic LiveCD"), then brings down source for each application package from Internet mirrors. LiveCD is an excellent mini-distribution on its own, and can be used for system maintenance and debug, performing many of the system disk recovery tasks for which the Knoppix distribution (http://www.knopper.net/knoppix/index-old-en.html) has proven useful. Both LiveCD and Knoppix seem to be able to boot on just about any x86 system, and "magically" recognize all the installed hardware and peripherals. The ISO image for the LiveCD can be downloaded from any of the mirrors using the path gentoo/releases/x86/1.4/livecd/basic/.

Step-by-step instructions (http://www.gentoo.org/doc/en/gentoo-x86-install.xml) make the installation straightforward, although you do have to use your brain cells a little. Gentoo installation puts you in control. There is no master installation program. The Portage packages you select are downloaded from the Internet, compiled, and installed onto your target hard disk. You get to do all the configuration, and you get the gratification when your kernel first boots.

One of the first tasks is to select a kernel version. There's an array of choices (http://packages.gentoo.org/packages/?category=sys-kernel), but "gentoo-sources" is a good place for starting your first system. Then, you need to select how many of the really fundamental utilities you want in place at that first boot. There are three tarballs to choose from. The smallest contains only the kernel and the most basic tools, while tarball level III contains a good assortment of system utilities.

It can take 24 hours to compile the larger applications (such as X, KDE, or Gnome), so the most recent distribution (1.4) has been streamlined with the addition of a number of precompiled executables. basic LiveCD has therefore swollen to fill a complete disk. A second CD has been added, with precompiled versions of KDE, GNOME, OpenOffice, and Mozilla. Downloading or purchasing the two-CD set saves time.

In addition to Gnome and KDE, most of the compact X11 window managers (http:// packages.gentoo.org/packages/?category=x11-wm/) are available for installation. My Libretto laptops only have 32 MB of RAM, which makes trying to run Gnome or KDE frustrating. Consequently, I installed IceWM (http://www.icewm.org/) and ended up with enough remaining physical memory to comfortably run either Mozilla-Firebird (http://packages.gentoo.org/packages/?category=net-www;name=mozilla-firebird/) or Kismet (http://www.kismetwireless.net/).

Once you have created your installation, you can easily maintain it with the Portage utilities. Still, the initial Gentoo setup does exercise your programming abilities since just about every system parameter is configurable. Not only does the normal Linux require CPU variables to be manually configured, but because this is a kernel you compile locally, you also have to remember to change the default CPU definitions in /etc/make.conf. The CFLAGS variable passes the default host CPU type to the C/C++ compilers during Linux system and application builds. A list of switches for all the supported processor types—from i386 to SPARC—is available from freehackers.org (http://www.freehackers.org/gentoo/gccflags/flag_gcc3.html).

Gentoo.org has made available a Linux Installation LiveCD (http://store.gentoo.org/index.php?cat=21&action=browse/) optimized for processors such as:

  • i386 (called the "x86 version").
  • i686 (Pentium Pro/II, Celeron 266533 MHz, original Athlon).
  • Pentium 3 (Pentium 3, Celeron 1 GHz1.4 GHz).
  • Pentium 4 (Celeron 1.7GHz+, Pentium 4, Pentium M/Centrino, P4 Xeon).
  • Athlon XP (Athlon XP, MP, Opteron in 32-bit mode).
  • PowerPC G3.
  • PowerPC G4.

In addition, a PowerPC G3/G4 LiveCD that boots directly in Linux, and which includes KDE, GNOME, and the OpenOffice and Koffice applications, is available. Consequently, there is no longer any need to struggle with CFLAGS during the initial boot, or to cross-compile your Linux executable on another system. Just select a CD with the level of processor optimization you want for any particular target machine, and then install Gentoo with confidence.

Gentoo's BSD influence also shows in the choice of Grub as the boot loader. If you are more familiar with Lilo, you should execute emerge -u lilo, then edit /etc/lilo.conf in the usual way. Being a source-code-based distribution, Gentoo has solid native C and C++ support. Since you rely on these native compilers to make your Gentoo kernel work properly, they need to be complete, with up-to-date revisions of the native libraries (libc6/glibc2).

Gentoo also has excellent support for cross-platform software development. It provides a cc-config wrapper that is able to call any of the available cc compilers, including the cross-compilers for x86, PPC, Sparc, Alpha, MIPS, ARM, and AMD64 targets. Similarly, the gcc-config wrapper changes the active GCC compiler. GCC additionally can produce code for HPPA and IA64 target processors. There are a number of special GCC builds for the Sparc and MIPS kernels, as well as a hardened GCC with transparent and semitransparent -pie -fPIC -fstack-protector support.

Among Gentoo's specialty C/C++ compilers are: tcc (http://fabrice.bellard.free.fr/tcc/), a small (100K) x86 C compiler; ccc, Compaq's enhanced C compiler for the Alpha platform; and icc, Intel's Pentium-optimized C++ compiler for Linux. uclibc is a C library for developing embedded Linux systems. Gentoo also has standard packages for the C++ implementation of the Atlas protocol (used in role playing games at Worldforge) and SIP (http//www.riverbankcomputing.co.uk/sip/), a tool for generating bindings for C++ classes so that they can be used by Python.

Conclusion

For the most part, programmers don't need a Linux distribution with the ability to simultaneously deploy 200 copies across an enterprise. What we need is a distribution where bugs are fixed quickly, and where new tools can be smoothly integrated. Gentoo has proven itself just such a programmer's distribution.


Trevor Marshall is an engineering consultant, specializing in RF and hardware design and Linux internals. He can be contacted at http//www.trevormarshall.com/.

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.