...making Linux just a little more fun!

<-- prev | next -->

# Installing Gentoo

By Mike Orr (Sluggo)

As I said in the #102 Mailbag, I've been wanting to try Gentoo. I hesitated to install it because I knew it would take three days since you have to compile your own software, and I assumed I would have lots of compilation errors to troubleshoot. But four of my friends have been running it at their workplaces and say they rarely get compilation errors -- mirable dictu. Three of them are solidly convinced for Gentoo; the other is a little tired of having to wait for a package to compile. But everyone says you just run "`emerge PACKAGE`" in a shell window and leave it alone, and 90% of the time you end up with a flawlessly installed package. No mess, no fuss, just pure impact. The way Unix was meant to be. This article describes my experience installing Gentoo, some things I learned along the way, and describes the Gentoo features I found the most interesting.

## Portage and USE flags

Gentoo brings the concept of BSD ports to Linux. Most Linux distros consist of precompiled binary packages in .rpm or .deb format. Gentoo consists of text configuration files ("ebuilds") that tell the package manager where to download the upstream source from, which patches to apply, and how to compile and install it. The package manager is called Portage (anchors away!), and its command-line tool is `emerge`. Of course, Debian and Red Hat have similar configuration files, otherwise how could the developers maintain the packages? And `emerge` does have the ability to install a precompiled package. So the difference between them is less about capability than about cultural emphasis -- and about whether the distros carry binary packages on their mirrors. Gentoo is not the first "compile your own" distro; I installed Rock Linux a couple years ago. But Gentoo has enough documentation and support now for me to actually use it as my desktop, and Rock didn't at the time.

The appeal of compiling software is not to be studly and say I did, but to eliminate a layer of potential problems. Compile-it-yourself distributions usually leave packages close to the upstream's default, compared with the heavy tweaking in some other distros. Debian's build process is so complicated you often get packages in the Unstable distribution that depend on themselves or on something that's not available. Fixing those requires you to second guess both the upstream developer and the package maintainer -- at which point it's often easier just to do a `/usr/local/` install. Unless it's a library that other stuff depends on; then you have to deal with dependencies again. Or install those things locally too.

Speaking of dependencies, one of Portage's novel features is USE flags. USE flags are direction from the local sysadmin (me and you) to the package manager about how to handle optional dependencies. This doesn't affect mandatory dependencies (e.g., the GIMP needs Gtk to run), but many programs come with extra utilities or front ends or libraries that depend on third-party stuff, even though the program as a whole does not depend on them.

For instance, a non-interactive daemon may come with a Gnome configuration dialog. Say you hate Gnome and don't want any gnomy things on your system. Other distributions don't have optional dependencies so they have to split the program into 'software' and 'software-gnome' packages. But Gentoo allows you to set a variable in /etc/make.conf specifying which optional stuff you want. For instance,

    USE="kde -gnome qt gtk gtk2 -crypt"

tells Portage not to install any optional components that require Gnome or encryption dependencies, but to install any other Gtk extensions. "gtk2" means we prefer the Gtk2 library over Gtk1 if the program can be built either way. And you'll want "mysql" in your USE string if you want to build Postfix with the ability to access MySQL tables for virtual users, domains, and the like.

Now say you want to install `links` but you haven't installed X yet. That's a problem because `links` has X11 extensions, and since the "X" USE flag is on by default, "`emerge links`" will install all of X if you don't watch what you're doing. So you set an environment variable to override the USE flag this one time:

    USE="-X" emerge links

Later, after you've installed X, you simply "`emerge links`" again, and it will rebuild itself with the X support.

## Compiling to the target CPU

Also in /etc/make.conf is the variable you configure to instruct Gentoo to build packages to match and make use of the advanced capabilities of your processor. There's a line that starts "CFLAGS =", that's where the work is done. There are a couple of decent examples right there in the make.conf file, and a whole sub-web devoted to configuring good CFLAGS settings over at Freehackers.org. The settings recommended there for my first two Gentoo machines are:

- at work (P3): `CFLAGS="-march=pentium3 -O3 -pipe -fomit-frame-pointer"`
- at home (AMD K6): `CFLAGS="-march=k6 -O3 -pipe -fomit-frame-pointer"`

## Installing the beast

The first thing I did was to print out the the ninety-page Gentoo Linux/x86 Handbook and read it several times. The Handbook does a good job of predicting what issues you might be concerned about at each step. Gentoo 2004.2 had just come out, but my CD was 2004.1. But the website reassured me that after "`emerge system`" I would be completely up to date, so I decided to go with the install that had worked on my friend's machine.

But first I had to shrink my NT partition. This was a work computer so I couldn't just get rid of Windows completely. I borrowed PartitionMagic but the version was too old to deal with the current NTFS partitions. I googled and found ntfsresize. It's a bit scary though because ntfsresize only shrinks the filesystem; you then have to delete the partition with fdisk and recreate it with the new size. There's also an ominous warning about getting the cylinder numbers right: if you make the NTFS partition too small, Windows wouldn't boot. I googled some more and found qtParted, a graphical program that handles both parts. Then I found a System Rescue CD that includes qtParted. I figured a rescue disk is always a good thing to have on hand anyway, and I was doubly impressed that it's Gentoo based. The Gentoo install disk is also a rescue CD, but this one has better hardware support and a wider selection of utilities. I availed myself of the hardware detection by watching the boot messages to see which drivers I'd need. Then I ran qtParted without a hitch, created my Linux partitions, and began the install. I wrote down every command I issued in case I had to do it again.

I opted for a stage 3 install, meaning I unpacked a tarball that contains a text-based developer's environment with the standard gcc tools precompiled (and Python, which Portage uses internally). If I wanted to be studlier I could have started at stage 1 where you do absolutely everything from scratch: first compiling a bootstrapper, then gcc, etc. But I didn't want to spend an extra day doing that.

The CD contained the following stage tarballs:

    % ls /mnt/cdrom/stages
    stage1-x86-2004.1.tar.bz2        stage3-pentium3-2004.1.tar.bz2
    stage3-athlon-xp-2004.1.tar.bz2  stage3-pentium4-2004.1.tar.bz2
    stage3-i686-2004.1.tar.bz2       stage3-x86-2004.1.tar.bz2

The computer is a Pentium III at 1 GHz so it was an obvious choice. But it took me quite a while to figure out which tarball to choose for my home computer (AMD K6 Duron at 450 MHz), and there was no compatibility list. I set it up as i686, then read somewhere on the Gentoo site that AMD Durons are i586, and since there wasn't a tarball for that I had to reluctantly re-set it up with the x86 tarball. But I haven't had the time to actually boot it and finish the install.

The biggest thing I was concerned about on the Pentium III was the nVidia video chip. The Answer Gang is constantly getting questions from people who have this chip and can't get their video to work, and you have to go to the nVidia site, find, download and install the politically incorrect binary-only kernel driver. But here I just ran "`emerge nvidia-kernel`" as the Handbook said and it worked. However, after I updated to the current ebuilds, nvidia-kernel would no longer compile. That's OK though because the old one is still working.

You have a choice of four kernel sources; I chose 2.6.5 with the Gentoo tweaks. You then have a choice to compile it manually or with genkernel. Genkernel creates a kernel with an initrd that does the same hardware detection as the install disk. I tried that first but for some reason it wouldn't create the initrd file. I f*cked around with it for a while and finally just built my own kernel, which went without a hitch. Grub also installed itself smoothly.

Gentoo comes with an initial set of binary packages so you can install KDE and OpenOffice without huge downloads, 1.5 GB free disk space, and an extra day to compile. But I didn't have the disk with those packages, so I just "`emerge sync`"'d to get the current set of ebuilds and let it run overnight. One night to update the existing installed packages ("`emerge world`"), and one night for X. I was going to be studly about that and install X.org instead of xfree86. That went OK although the graphical configurator wouldn't work with my system so I had to use the text configurator.

## The screamer

A week after I finished that, my boss told me I was getting a new computer. It's a screamin' Pentium IV black beauty at 2.6 GHz, twice as fast as any other computer I've ever used. Kernel compiles now take two minutes. Fortunately I had written down the commands I had used to install, so I was able to mostly follow them.

This computer has an Intel i810 video chipset. I assumed anything would be better than the nVidia. Wrong. I had to boot the non-framebuffer kernel on the CD in order to install, and it seemed to ignore the VGA mode so I couldn't get the text console above 80x24. Likewise, I couldn't make an X configuration that would go above 640x480; it kept on saying mode "1024x768" doesn't exist even though it's supposed to be a standard VESA mode built into X 4. Googling found contradictory advice, including one message saying i810 isn't supported very well on Linux, and an apparently obsolete HOWTO on Intel's site. Finally I stole a 3dfx (Voodoo) PCI card from an unused computer. That one still took a while to configure but I finally got it up to 1280x1024. Then I moved it down to 1152x864 because that looks better on my 19" monitor. But I still can't get the text screen better than 80x24, and I'm not sure about the framebuffer. Curiously, the BIOS doesn't have an option to disable the i810 chip, you can only set it to "on" or "auto". Leaving it at "auto" makes the PCI card the main one (card 0) and the i810 the secondary (card 1), but both are active. In `/etc/X11/xorg.conf` you tell it which card and monitor to use. In Windows it assumes you have monitors connected to both cards (I don't) and you want the desktop to span both monitors (so each monitor shows half). The "Monitors" control panel has controls to ignore one card or make it primary. These all work fine although it's disconcerning when the screen suddenly goes dark or the taskbar disappears onto the other screen as you change the settings (because Windows assumes you have a second monitor connected to the other card, which I don't). I hate to say it, but it was easier to configure the two cards in Windows than Linux.

KDE 3.3 came out the day before I did this install, but for some reason it's still in the "masked" section in Gentoo (meaning Unstable), so I'm sticking with 3.2 for now.

Printing was a breeze to set up once I found the Printing HOWTO on the Gentoo site. I had to connect to an HP LaserJet 8000 using IPP (Internet Print Protocol) over TCP/IP. LinuxPrinting.org provided a prebuilt driver, and the Printing HOWTO told me which directory to put it in so CUPS would see it.

The main thing I can't get to work is smbfs. Our shared files are kept on an NT server. My colleague who has Gentoo can do it using Konqueror or this command:

`mount -t smbfs //SERVER/directory /mnt/smb -o "ip=111.222.333.444,username=USER%PASSWORD,workgroup=WORKGROUP,fmask=666,dmask=000"`

... but for me although I connect without error, "ls /mnt/smb" says permission denied, and "ls /mnt" doesn't even show "smb" while it's mounted. I tried several variations of the network directory and username, with and without the fmask/dmask, but nothing has worked. So I still have to switch to Windows to save my backups to the network, and to run a Java applet that won't run in Firefox or Galeon.

I made a DOS partition to share files between Linux and Windows. That works although it's sometimes surprising when permissions don't work the way you expect, even though you've known about that for years. You set the permissions in the mount command. I finally gave them all permission for all users so I wouldn't have to fuss with them any more.

Here's the non-default packages I've felt the need to install so far:

- a2ps
- apache (2.0.50)
- bind-tools (host, nslookup, dig)
- cups
- dosfstools (mkfs.vfat)
- foomatic (not needed after all)
- fvwm
- fvwm-crystal
- galeon
- gentoolkit (package query tools)
- ghostscript
- gimp-print (not needed after all)
- gvim
- kde
- links
- mmv
- mod_php
- mozilla-firefox
- mozilla-thunderbird
- mutt
- mysql
- ncftp
- netkit-telnet
- openoffice (it wouldn't compile)
- php
- php-accellerator
- php-docs
- stow
- subversion
- sun-jdk
- vim
- xorg-x11
- xpdf

... not including various Python libraries and PHP libraries.

## More critiques of Gentoo

Gentoo's package query tools (`equery` and `qpkg`) aren't complete. They'll list the files a package contains but several other features are marked "not implemented". There didn't seem to be a way to quickly see which version of a package is installed: something equivalent to "`rpm PACKAGE`" or "`dpkg -l PACKAGE`". "`emerge search PACKAGE`" does it, but it takes several seconds, and you have to page through other information and entries for any other packages the substring matches. After a fair bit of trial and error, I found that `qpkg` can show me the information, but it doesn't take concatenated flags, so I had to type "`qpkg -i -I PACKAGE`", where `-i` gets me package info, and `-I` limits the list to installed packages only. By the way, "`emerge info PACKAGE`" does not do what you expect. I'd expect it to give extended information about the package à la "`dpkg -s PACKAGE`", but instead it reports on your installation environment; e.g., which USE flags are in effect.

It's bloody hard to figure out which package you need if you don't know the name. I wish Gentoo had a webpage similar to packages.debian.org you could search. In fact, I still use packages.debian.org to figure out which Gentoo packages I want! The biggest problems I had were finding the package for `mkfs.vfat` (dosfstools) and `host`/`dig`/`nslookup` (bind-tools). I needed the former to make my DOS filesystem. Finally I found a couple messages in the Gentoo forums with the name of the package, showing that several other people have had the same problem.

"`emerge search`"'s package descriptions are one-liners rather than the paragraph(s) Debian provides at the web site or via "`apt-cache search PACKAGE`". The missing info is stuff I want to know to decide whether to install the package.

Gentoo-specific package documentation also seems to be missing -- equivalent to `/usr/share/doc/PACKAGE/README.Debian` . One would like a file describing the Gentoo way to configure and use the package, especially since Gentoo's configuration framework is different from other distributions. The framework looks impressively flexible; many packages have a separate file for local overrides, so the standard configuration file can be upgraded without stomping on anything. The overrides are almost invariably in the form of variable definitions. To enable SSL and PHP in Apache2, no need to edit the config file, just set:

    APACHE2_OPTS="-D SSL -D PHP"

... in `/etc/conf.d/apache2` . The trouble is, if you forget where to set what, there's a lot of places to look for it: `/etc/conf.d/*`, `/etc/rc`, `/etc/make.conf`, `/etc/profile`, and there may be more that slip my mind. This is where a `README.Gentoo` file would come in useful. The init.d scripts are different from other distributions', although they're robust. "`rc-update show default`" shows which services are set to start at boot, and "`rc-update add PACKAGE default`" adds it. When an init.d service fails to start, check /var/log/*! That's true for any distro, but I find it quite useful on Gentoo since packages have no `README.Gentoo` to guide you. Somewhere I set `kdm` to shutdown when I log out rather than presenting the login dialog. Now I want to change it but darned if I can find the setting.

Another thing I haven't figured out is how to compile a package with different `./configure` options than the maintainer set, or how to install a development version that Gentoo doesn't have. I need to reinstall PHP with the msysqli option (an object-oriented MySQL library). I finally found a USE flag called, unsurprisingly, "mysqli", but the general problem remains. Also, I often use alpha versions of Python, which I put in `/usr/local` now but I'd like to install them like Gentoo packages. I assume I just have to sit down and figure out how to customize ebuilds, and where to put them so they don't get deleted at the next "`emerge sync`". There's also a nifty "`emerge inject PACKAGE`" feature that tells Portage you've installed something locally that's the equivalent of PACKAGE. I haven't used it yet but it certainly sounds a lot easier than `dpkg-equivs`.

For those with lots of disk space but little time, "`emerge ccache`" sets up a compilation cache that saves intermediate files so you don't have to regenerate them. There's also a distcc package for replicating installs in a network, although I haven't used it.

## Conclusion

Although I've found a bunch of little shortcomings in Gentoo, it's still my favorite distro because it has so much potential. Eventually the gaps will be filled, and the lightweight layer they add to packages ensures that upstream versions are quickly ported to Gentoo because there's not much overhead to get in the way.

Mike is a Contributing Editor at Linux Gazette. He has been a Linux enthusiast since 1991, a Debian user since 1995, and now Gentoo. His favorite tool for programming is Python. Non-computer interests include martial arts, wrestling, ska and oi! and ambient music, and the international language Esperanto. He's been known to listen to Dvorak, Schubert, Mendelssohn, and Khachaturian too.

Copyright © 2004, Mike Orr (Sluggo). Released under the Open Publication license

Published in Issue 106 of Linux Gazette, September 2004

<-- prev | next -->