KNOW-HOW

Installing and Managing COOKINGCOOKING WITHWITH GENTOOGENTOO

Gentoo is a powerful and flexible Linux system that you can custom- ize to fit perfectly into your environment. Our workshop describes how to set up Gentoo. We’ll also show you how to install and manage on your Gentoo system with the popular software went without saying in the early days of Linux; users were more or less forced to management system. BY ALEXANDER REITERER explore their own systems, editing con- figuration files, and searching forums for answers to any problems they or some users, the powerful Gen- other distributions you may be familiar encountered. GUI-based install wizards, too is the ideal Linux, but for with. We will then go on to explore how and central system administration tools Fmany, Gentoo is an inaccessible to manage software on your Gentoo (such as Yast on Suse Linux, for exam- system for the experts. Whatever your system. ple), have really taken the hard work out impressions of this daunting distro, once of installing, configuring, and managing you know your way around, you'll find Gentoo Quirks today’s Linux systems. At the same time, that Gentoo provides some very conve- Although you can install Gentoo from these tools obscure the underlying pro- nient tools that make the system as easy prebuilt packages, it is more typical to cesses. Gentoo brings more light into the as any other Linux. build the system directly from the source gloom. code. This gives you the advantage of Of course, this flexibility comes at a Installation in 12 Steps being able to tailor the system perfectly price. If you are set on getting to know Many users consider Gentoo Linux to match your needs. This is why Gentoo Gentoo, you should be prepared to read synonymous with “hard to install,” is often referred to as a meta-distribu- lengthy manuals and not be afraid of “a system for geeks,” or “unfriendly to tion. Both the system setup and the firing up your editor to modify configu- newbies.” It is hard to deny that there is installation of new programs are nor- ration files. In daily life, these apparent a smattering of truth in these prejudices, mally quite different from most other disadvantages often turn out to be less but even if you are new to Linux, it is popular distributions. of a hindrance than you might expect. still worth your while to investigate this Before we move on to look at the young distribution. In this article, I will install, let’s first review some of Gen- Installation Stages try to take the fear out of Gentoo [1]. too’s advantages and disadvantages. The Gentoo Linux install starts with We will start by looking at Gentoo One of the advantages should be fairly downloading a Live CD image. There are basics, focusing on the installation, obvious by now: as a user, you maintain two different installation media available which is completely different from any complete control of the system. This for the current version (which is version

WWW.LINUX - MAGAZINE.COM ISSUE 58 SEPTEMBER 2005 49 KNOW-HOW Gentoo Linux

a prompt. You are mkdir /mnt/gentoo/boot, and mount automatically /dev/hda1 /mnt/gentoo/boot will mount logged on as root the partitions you just created in your and can now start filesystem tree. configuring the network settings. Downloading Archives If your machine is Now type cd /mnt/gentoo to change on a network with the default directory to the Gentoo a DHCP server, mountpoint, and enter links2 http:// Gentoo will typi- www.gentoo.org to select a mirror server. cally get these set- There is a list of mirrors in the naviga- tings right. tion bar on the left below Resources: | Enter ping -c 3 Download Mirrors. www.google.de to On the selected mirror server, change check if you have the directory to releases//2005.0/ an Internet con- stages/x86, select the Stage 1 archive, Figure 1: Booting your Gentoo Linux system. nection. If you and press [D] to download. Then change don’t, you will to the snapshots directory and download 2005.0 at the time I am writing this arti- need to run net-setup (adding the name the current Portage archive – at this time cle): a minimal image and a universal of your network interface) or adsl-setup of writing, the current Portage archive is image. You should not use the universal (for ADSL connections) to set up your portage-20050331..bz2. image unless you want to avoid building network environment. You can install the system from scratch. The installation Gentoo over a WLAN, if needed; if you Stage 1 and Portage process itself is divided into three stages. intend to do so, refer to the online docu- Unpack the Stage archive by entering tar Which stage you will need to start from mentation at [2]. -xvjpf stage?-*.tar.bz2. The option -p is depends on how much of the system you important here, as it tells tar to keep the will be building from scratch, and which Hard Disk Preparation file permissions when unpacking the prebuilt components you will be using. The next thing to do is to set up hard files. When you are finished, extract the Stage 1 gives you the full gamut of sys- disk partitions for Gentoo. We will be Portage branch in the right directory by tem optimization options; on the down- assuming your hard disk is /dev/hda. entering tar -xvjpf portage-20041022.tar. side, the install takes a long time to com- Give the fdisk /dev/hda command to bz2 -C /mnt/gentoo/usr. plete. A Stage 2 install gives you fewer launch the partitioning tool. You can optimization options, but the whole pro- now press p to display the current parti- Options cess is far quicker. This makes Stage 2 a tion table or d to delete all the partitions As mentioned earlier, Gentoo has a vari- good compromise between optimization on the disk. Create a boot partition by ety of system optimization options. We and speed. Stage 3 is the quickest pressing n, and then press p. Assign this will just be scratching the surface here, approach to installing Gentoo; you only partition as number 1, and set the size so you might like to check out the online need to accept the defaults for optimiz- (e.g., 32M for 32 MB.) The next thing to documentation at [2] if you need a more ing the basic system. Additionally, Stage do is to create a swap partition. To do so, detailed description. To make changes, 3 fulfills the requirements for using pre- enter the following in this order (press first enter nano -w /mnt/gentoo/etc/ built packages for the install. In the fol- Enter after each entry): n, 2, +512M, t, make.conf to open the make.conf file. lowing sections, we will assume you are 2, 82. Then set up a root partition by To keep this simple, let’s just say the file using the minimal image for the remain- pressing p and 3. When prompted for contains all the system optimization ing installation steps and that you have the partition size, press Enter to accept options. opted for a Stage 1 install. the default setting (this uses the remain- The CHOST variable specifies the pro- You only need the Live CD to boot the ing hard disk space for the root parti- cessor type, i686-pc-linux-, for exam- system, detect the hardware, and set up tion). When you are finished, press [W] ple, or x86_64-pc-linux-gnu (if you have a network connection. To give you a bet- to store the partition table. an AMD64.) The CFLAGS and CXX- ter overview, I have divided the installa- FLAGS variables define the C and C++ tion into 12 steps. Formating compiler optimizations. The following Now format the newly created partitions settings would work for an AMD Ath- Starting the Installation with a filesystem of your choice, for lonXP CPU: Download the minimal image from [1], example, by typing the command mke2fs burn a CD with the image (you can use /dev/hda1 (boot partition using ext2) or CFLAGS="-march=athlon-xp U k3b to do so), and boot your system the command mke2fs -j /dev/hda3 (root -pipe -O2" from the CD. partition using ext3). Finally, create and CXXFLAGS="${CFLAGS}" enable the swap partition by entering Network Configuration mkswap /dev/hda2 and swapon /dev/ You can also use MAKEOPTS to specify After booting (Figure 1), you should see hda2. mount /dev/hda3 /mnt/gentoo, how many processors your system has.

50 ISSUE 58 SEPTEMBER 2005 WWW.LINUX - MAGAZINE.COM Gentoo Linux KNOW-HOW

Then go on to enter the fol- nection. As neither of these points is lowing commands to build Gentoo-specific, you may already know the basic Gentoo system: how to do this; if not you can find out by reading the how-to at [4], for example. cd /usr/portage scripts/bootstrap.sh Installing the Bootloader emerge system The bootloader ensures that the kernel loads when you boot your machine. In this example, I’ll use the Grub boot- Configuring the loader [5]. Enter emerge grub to build Kernel the bootloader before going on to config- To build the kernel, you first ure and install: need to download the current kernel sources: give the nano -w /boot/grub/grub.conf emerge gentoo-sources com- cp /proc/mounts /etc/mtab Figure 2: Output from the emerge search function. mand to do this. Besides grub-install U this typical variant, there are --root-directory=/boot /dev/hda For a single CPU system, type a few other kernel sources, such as MAKEOPTS="-j2". gentoo-dev-sources or vanilla-sources. Rebooting the system Then type cd /usr/src/kernelsource and This completes the steps required to Installing the Basic System make menuconfig for the configuration. boot the system for the first time. Enter Before you can build the basic system, Instead of “kernelsource” in the follow- the following commands to boot the you need to select a mirror server from ing commands, specify the name of the system: which you will be downloading the kernel source you are using. You can required Gentoo packages. The following then build and install the kernel: exit command handles this for you automati- cd cally: make && make modules_install umount /mnt/gentoo/boot U cp arch/i386/boot/bzImage U /mnt/gentoo/proc /mnt/gentoo mirrorselect -a -s4 -o | grep U /boot/kernelsource reboot 'GENTOO_MIRRORS=' >> U cp System.map U /mnt/gentoo/etc/make.conf /boot/System.map-kernelsource Your system should now boot cleanly, and you should be able to log on as root. The system then needs DNS informa- This actually completes the installation tion, and you need to mount the proc Configuring the System of your basic Gentoo system. filesystem: Before you can use your system, you still need to complete two important configu- System Management cp -L /etc/resolv.conf U ration steps. First, you need to modify Once you have installed Gentoo, you can /mnt/gentoo/etc/resolv.conf /etc/fstab to bind the partitions. Second, use the Portage software management mount -t proc none U you need to configure the network con- tool to install additional packages (such /mnt/gentoo/proc

You can now enter the environment and update the Portage branch. Use the fol- lowing commands to do so:

chroot /mnt/gentoo /bin/bash env-update source /etc/profile emerge -sync

When you are finished, go on to make some more changes using the USE vari- able, which contains a few general com- piler options. To do so, open make.conf again. The Use variable for a KDE-based system might look like this:

USE="- - qt U dvd alsa cdr" Figure 3: Searching for programs via the web interface on the Gentoo project homepage.

WWW.LINUX - MAGAZINE.COM ISSUE 58 SEPTEMBER 2005 51 KNOW-HOW Gentoo Linux

as KDE, OpenOffice.org, etc.). The on the Portage branch Portage tool is the control center for all stored on your system, software management tasks on Gentoo so make sure you update Linux. Portage has an incredible number your ebuilds regularly (or of options and is regarded by many (not at least before you install without good reason) as being the best a new program). The software management tool for Linux. emerge -sync command When we refer to programs that are updates your ebuilds. available to Gentoo, we mean programs emerge program_name that are available in the Portage branch. installs a program. To In Gentoo-speak, these programs are find out which programs also known as ebuilds. An ebuild con- Portage would install to tains all the information Portage needs resolve dependencies, to handle the program in question type: (download branch, version, etc). Ebuilds are stored in /usr/portage on your sys- emerge --pretend U tem, and you can expect the content to program_name change continually as new program ver- sions are released. Before you start to Figure 4 shows you what Figure 4: A sample run of emerge shows you which depen- work with Portage, you should always the output from this com- dencies need to be resolved to install a package. update the Portage branch. The follow- mand might look like. ing command does this: emerge --sync. The program lists details of the packages You can then launch the build and install After completing the update, you can that would be installed (in the straight steps at your leisure by entering emerge install a program by entering emerge brackets.) The following list will help program name. program_name (e.g., emerge kde); to you with the abbreviations: There are times when you need to uninstall, enter emerge unmerge pro- • B (Blocks): The package to the left update the whole system, rather than gram_name. To search the Portage blocks the installation of the package just set up a program. The following branch for a specific software package, to the right. command handles this task of updating type emerge search program_name. The • N (New): emerge will re-install the your Gentoo system: output is a list of the latest program ver- package. sions available in your Portage branch • R (Reemerge): The package is not emerge --update world and details on the program versions new, but it has to be re-installed. installed on your system at present • F (Fetch): You need to download the This command updates all the programs (Figure 2). for this package manually. installed on your system, but without As an alternative, you could use the • U (Update): The package already updating the dependencies. To update web interface on the Gentoo project page exists on your system, however, an dependencies too, enter the following (Figure 3) to search for programs. This update is available. command: lets you know all about the various • UD (Downgrade): The package development stages of a project from already exists on your system, how- emerge --update --deep world masked (developer version), via testing, ever, emerge needs to install an older through to stable. You will also find use- version. Portage also has the ability to remove ful links for the program in question • U- (slot warning): The package will orphaned packages. The following com- (project page, license, etc.). not work with another version on your mand handles this for you: system. emerge will handle the instal- System Management with lation and uninstall the older version emerge --update --deep U Portage in the process. --newuse world As previously mentioned, Gentoo nor- When you tell Portage to set up a pro- emerge depclean mally doesn’t use prebuilt packages, but gram, the tool downloads any required revdep-rebuild so-called ebuilds with all the informa- sources from the Internet before immedi- tion you need to handle the program in ately going on to build and install the You need to install the Gentoolkit to run question (download branch, version, package. If you do not have a leased line the revdep-rebuild command. etc.). To keep this simple, let’s say that or a fixed-rate broadband connection, Besides having the ability to install the Portage branch is the sum of all you might like to download the required programs directly from the source code, ebuilds available for Gentoo. packages first and postpone the build Gentoo also lets you install prebuilt pro- The Portage software management tool and install steps. The following com- gram packages. The following command is extremely flexible and gives adminis- mand tells emerge to download without handles this for you: trators an incredible range of options. installing Before you use Portage, you should be emerge --usepkg U aware that anything you do will be based emerge --fetchonly program name --getbinpkg program_name

52 ISSUE 58 SEPTEMBER 2005 WWW.LINUX - MAGAZINE.COM Gentoo Linux KNOW-HOW

You can uninstall a program by entering The command outputs details of the get to know the system; after completing emerge unmerge program_name. Note compiler version, kernel version, use the install, new users are familiar with that Portage will not check if the pro- flags, etc. for your system. many of the basic Gentoo system com- gram in question is required by other You also have the option of displaying mands. In contrast to this, a Suse or programs. the use flags for a specific program. The Fedora GUI-style installation removes For more information on the use of following command does this for you: the user from this very important learn- emerge, read the manpages (you need ing process. Users with the new Gentoo to type man emerge to access the man- emerge --pretend U installer will no longer need to plum the pages.) The Gentoo documentation at --verbose program_name depths of the Gentoo system in order to [2] also has a detailed description of get their systems running. the tool. Table 1 has an overview of the etcat uses program name gives you more most common Portage commands. detailed output; note that you need to Conclusions install “Gentoolkit” to run this com- I hope this peek behind the drapes at the Optimization Options mand. fascinating Gentoo distribution has whet At the beginning of this article, I men- your appetite for more Gentoo. Let me tioned that Gentoo’s ability to optimize Gentoo Roadmap just restate that we have only scraped more or less any system is one of its 2004 saw the introduction of a new the surface; if you really want to get to strongest features. Gentoo provides so- release labeling format comprising the know the Gentoo system in detail, the called use flags for this purpose. Use year and version (e.g., 2004.3, 2005.0, techniques described in this article will flags can be global or local. etc.). The project has a quarterly release help you get started on your Gentoo As the names suggest, global use flags cycle, but note that these releases are journey. optimize system parameters for all pro- only relevant to the CD image. Once you Despite the fairly convoluted install, grams, whereas local use flags optimize have installed a Gentoo system, Portage Gentoo’s popularity is growing by the a single program. A list of all global use will help you keep it up to date. minute, and this growing popularity is flags is in /usr/portage/profiles/use.desc. It is nice to see how quickly recently reflected in the growing numbers of par- Gentoo defines a default for many use released programs find their way into the ticipants in the various Gentoo forums. flags. The defaults are listed in the /etc/ Portage branch. For example, it normally Let’s hope that you too catch the Gentoo make.profile/make.defaults file. You can takes less than a month for a KDE bug and have fun moving your system change default settings by adding or release to enter the stable Portage to Gentoo. ■ removing use flag keywords. The use branch. variables are defined in /etc/make.conf. New software goes through three inte- INFO To remove a variable, simply add a gration stages in Gentoo: masked, test- [1] Gentoo homepage: dash before the variable, for example: ing, and stable. A program is referred to http:// www. gentoo. org. -gnome. If you are defining use flags for as masked immediately after entering specific programs, you need to edit the the Portage branch; it then goes through [2] Gentoo documentation: http:// www. gentoo. org/ doc/ en. /etc/portage/package.use file. This the testing stage until the maintainers means specifying both the program decide that it is stable. Of course, this [3] Gentoo forum: package and the use flag you wish to will not prevent you installing programs http:// forums. gentoo. org define, for example dev-/php -java. from any of the three “development [4] Linux Installation, Configuration and To declare a temporary use flag that stages.” Use, by Michael Kofler; will be used for a single emerge opera- At present, the Gentoo developers are Addison-Wesley, 2004. tion, specify the flag before the emerge working on a program wizard that will [5] Grub: statement: simplify the system installation proce- http:// www. gnu. org/ software/ grub dure and make Gentoo more accessible [6] Planet Gentoo homepage: USE="-java" emerge php to Linux newcomers. Although this is a http:// planet. gentoo. org welcome development for some, many [7] Linux Installation and Getting Started, emerge info shows you the current set- serious Linux users frown at it. The cur- by Welsh, Dalheimer, Dawson, and tings for the use flags on your system. rent installation really forces a user to Kaufman; O’ Reilly, 2003. Table 1: Common Portage Commands Command Function Dr. Alexander emerge --sync Updates the Portage branch. Reiterer is an author emerge program name Installs a program and scientist who emerge --pretend program_name Checks dependencies works for the emerge --fetchonly program_name Downloads the program source code Technical Universiy emerge unmerge program_name Uninstalls a program of Vienna, Austria. emerge --update world Updates the whole system If you wish contact

emerge --update --deep world Updates the system and all dependencies THEAUTHOR Dr. Reiterer, you can reach him at emerge --usepkg --getbinpkg program_name Installs a prebulit program [email protected].

WWW.LINUX - MAGAZINE.COM ISSUE 58 SEPTEMBER 2005 53