Files
memex/0_inbox/in/Gentoo Linux Documentation -- Gentoo Linux x86 Handbook.html
2026-03-15 14:37:05 -04:00

9646 lines
503 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link title="new" rel="stylesheet" href="../../../css/main.css" type="text/css">
<link REL="shortcut icon" HREF="../../../favicon.ico" TYPE="image/x-icon">
<link rel="search" type="application/opensearchdescription+xml" href="//www.gentoo.org/search/www-gentoo-org.xml" title="Gentoo Website">
<link rel="search" type="application/opensearchdescription+xml" href="//www.gentoo.org/search/forums-gentoo-org.xml" title="Gentoo Forums">
<link rel="search" type="application/opensearchdescription+xml" href="//www.gentoo.org/search/bugs-gentoo-org.xml" title="Gentoo Bugzilla">
<link rel="search" type="application/opensearchdescription+xml" href="//www.gentoo.org/search/packages-gentoo-org.xml" title="Gentoo Packages">
<link rel="search" type="application/opensearchdescription+xml" href="//www.gentoo.org/search/archives-gentoo-org.xml" title="Gentoo List Archives">
<title>Gentoo Linux Documentation
--
Gentoo Linux x86 Handbook</title>
</head>
<body bgcolor="#ffffff">
<h1>Gentoo Linux x86 Handbook</h1>
<a href="mailto:swift@gentoo.org" class="altlink"><b>Sven Vermeulen</b></a>
 <i>Author</i><br>
<a href="mailto:g2boojum@gmail.com" class="altlink"><b>Grant Goodyear</b></a>
 <i>Author</i><br>
Roy Marples
 <i>Author</i><br>
<a href="mailto:drobbins.daniel@gmail.com" class="altlink"><b>Daniel Robbins</b></a>
 <i>Author</i><br>
<a href="mailto:chouser@bluweb.com" class="altlink"><b>Chris Houser</b></a>
 <i>Author</i><br>
<a href="mailto:jalexand@wlgore.com" class="altlink"><b>Jerry Alexandratos</b></a>
 <i>Author</i><br>
<a href="mailto:seemant@kulleen.org" class="altlink"><b>Seemant Kulleen</b></a>
 <i>Gentoo x86 Developer</i><br>
<a href="mailto:taviso@gmail.com" class="altlink"><b>Tavis Ormandy</b></a>
 <i>Gentoo Alpha Developer</i><br>
Jason Huebel
 <i>Gentoo AMD64 Developer</i><br>
<a href="mailto:gmsoft@gentoo.org" class="altlink"><b>Guy Martin</b></a>
 <i>Gentoo HPPA developer</i><br>
<a href="mailto:pvdabeel@gmail.com" class="altlink"><b>Pieter Van den Abeele</b></a>
 <i>Gentoo PPC developer</i><br>
<a href="mailto:jkallar@yahoo.com" class="altlink"><b>Joe Kallar</b></a>
 <i>Gentoo SPARC developer</i><br>
<a href="mailto:john_davis@pauldavisautomation.com" class="altlink"><b>John P. Davis</b></a>
 <i>Editor</i><br>Pierre-Henri Jondot <i>Editor</i><br>
<a href="mailto:stocke2@gmail.com" class="altlink"><b>Eric Stockbridge</b></a>
 <i>Editor</i><br>
<a href="mailto:rajiv-gentoo@imagineblue.com" class="altlink"><b>Rajiv Manglani</b></a>
 <i>Editor</i><br>
<a href="mailto:seo@gentoo.or.kr" class="altlink"><b>Jungmin Seo</b></a>
 <i>Editor</i><br>
<a href="mailto:zhware@hotpop.com" class="altlink"><b>Stoyan Zhekov</b></a>
 <i>Editor</i><br>
Jared Hudson
 <i>Editor</i><br>
<a href="mailto:gentoo@random-chaos.org.uk" class="altlink"><b>Colin Morey</b></a>
 <i>Editor</i><br>
Jorge Paulo
 <i>Editor</i><br>
<a href="mailto:canderson@wayne.edu" class="altlink"><b>Carl Anderson</b></a>
 <i>Editor</i><br>
<a href="mailto:avenj@tellink.net" class="altlink"><b>Jon Portnoy</b></a>
 <i>Editor</i><br>
Zack Gilburd
 <i>Editor</i><br>
<a href="mailto:jmorgan@gentoo.org" class="altlink"><b>Jack Morgan</b></a>
 <i>Editor</i><br>
<a href="mailto:benny@coolbee.net" class="altlink"><b>Benny Chuang</b></a>
 <i>Editor</i><br>
<a href="mailto:erw1n@pmail.ntu.edu.sg" class="altlink"><b>Erwin</b></a>
 <i>Editor</i><br>
<a href="mailto:kumba@gentoo.org" class="altlink"><b>Joshua Kinard</b></a>
 <i>Editor</i><br>
<a href="mailto:tobias@tobias-scherbaum.de" class="altlink"><b>Tobias Scherbaum</b></a>
 <i>Editor</i><br>
Xavier Neys
 <i>Editor</i><br>
<a href="mailto:nightmorph@gentoo.org" class="altlink"><b>Joshua Saddler</b></a>
 <i>Editor</i><br>
Gerald J. Normandin Jr.
 <i>Reviewer</i><br>
<a href="mailto:dberkholz@gentoo.org" class="altlink"><b>Donnie Berkholz</b></a>
 <i>Reviewer</i><br>
<a href="mailto:drake_stuff@yahoo.com" class="altlink"><b>Ken Nowack</b></a>
 <i>Reviewer</i><br>
<a href="mailto:lars@weiler-online.name" class="altlink"><b>Lars Weiler</b></a>
 <i>Contributor</i><br><br><i>Page updated September 25, 2014</i><p>Content:</p>
<ul>
<li>
<b><a href="#book_part1">Installing Gentoo</a></b><br>
In this part you learn how to install Gentoo on your system.
<ol>
<li>
<b><a href="#book_part1_chap1">About the Gentoo Linux Installation</a></b><br>
This chapter introduces you to the installation approach documented in this
handbook.
</li>
<li>
<b><a href="#book_part1_chap2">Choosing the Right Installation Medium</a></b><br>
You can install Gentoo in many ways. This chapter explains how to install
Gentoo using the minimal Installation CD.
</li>
<li>
<b><a href="#book_part1_chap3">Configuring your Network</a></b><br>
To be able to download the latest source code, you will need to setup
networking.
</li>
<li>
<b><a href="#book_part1_chap4">Preparing the Disks</a></b><br>
To be able to install Gentoo, you must create the necessary partitions.
This chapter describes how to partition a disk for future usage.
</li>
<li>
<b><a href="#book_part1_chap5">Installing the Gentoo Installation Files</a></b><br>
Gentoo installs work through a stage3 archive. In this chapter we
describe how you extract the stage3 archive and configure Portage.
</li>
<li>
<b><a href="#book_part1_chap6">Installing the Gentoo Base System</a></b><br>
After installing and configuring a stage3, the eventual result is that you
have a Gentoo base system at your disposal. This chapter describes how
to progress to that state.
</li>
<li>
<b><a href="#book_part1_chap7">Configuring the Kernel</a></b><br>
The Linux kernel is the core of every distribution. This chapter
explains how to configure your kernel.
</li>
<li>
<b><a href="#book_part1_chap8">Configuring your System</a></b><br>
You need to edit some important configuration files. In this chapter
you receive an overview of these files and an explanation on how to
proceed.
</li>
<li>
<b><a href="#book_part1_chap9">Installing Necessary System Tools</a></b><br>
In this chapter we help you choose and install some important tools.
</li>
<li>
<b><a href="#book_part1_chap10">Configuring the Bootloader</a></b><br>
Several bootloaders exist for the x86 architecture. Each one of them has its
own way of configuration. We step you through the process of configuring a
bootloader to your needs.
</li>
<li>
<b><a href="#book_part1_chap11">Finalizing your Gentoo Installation</a></b><br>
You're almost done. We'll just create one (or more) users for your
system.
</li>
<li>
<b><a href="#book_part1_chap12">Where to go from here?</a></b><br>
Now you have your Gentoo system, but what's next?
</li>
</ol>
</li>
<li>
<b><a href="#book_part2">Working with Gentoo</a></b><br>
Learn how to work with Gentoo: installing software, altering variables, changing
Portage behaviour etc.
<ol>
<li>
<b><a href="#book_part2_chap1">A Portage Introduction</a></b><br>
This chapter explains the "simple" steps a user definitely needs to know to
maintain the software on his system.
</li>
<li>
<b><a href="#book_part2_chap2">USE flags</a></b><br>
USE flags are a very important aspect of Gentoo. In this chapter, you learn to
work with USE flags and understand how USE flags interact with your system.
</li>
<li>
<b><a href="#book_part2_chap3">Portage Features</a></b><br>
Discover the features Portage has, such as support for distributed compiling,
ccache and more.
</li>
<li>
<b><a href="#book_part2_chap4">Initscripts</a></b><br>
Gentoo uses a special initscript format which, amongst other features, allows
dependency-driven decisions and virtual initscripts. This chapter explains all
these aspects and explains how to deal with these scripts.
</li>
<li>
<b><a href="#book_part2_chap5">Environment Variables</a></b><br>
With Gentoo you can easily manage the environment variables for your system.
This chapter explains how you do that, and also describes frequently used
variables.
</li>
</ol>
</li>
<li>
<b><a href="#book_part3">Working with Portage</a></b><br>
"Working with Portage" provides an in-depth coverage of Portage, Gentoo's
Software Management Tool.
<ol>
<li>
<b><a href="#book_part3_chap1">Files and Directories</a></b><br>
Once you want to know Portage in-depth you need to know where it stores its
files and data.
</li>
<li>
<b><a href="#book_part3_chap2">Configuring through Variables</a></b><br>
Portage is completely configurable through various variables you can set in the
configuration file or as environment variable.
</li>
<li>
<b><a href="#book_part3_chap3">Mixing Software Branches</a></b><br>
Gentoo provides software separated in several branches, depending on stability
and architectural support. "Mixing Software Branches" inform you how these
branches can be configured and how you can override this separation
individually.
</li>
<li>
<b><a href="#book_part3_chap4">Additional Portage Tools</a></b><br>
Portage comes with a few extra tools that might make your Gentoo experience even
better. Read on to discover how to use dispatch-conf and other tools.
</li>
<li>
<b><a href="#book_part3_chap5">Diverting from the Official Tree</a></b><br>
"Diverting from the Official Tree" gives you some tips and tricks on how to use
your own Portage tree, how to synchronise only the categories you want, inject
packages and more.
</li>
<li>
<b><a href="#book_part3_chap6">Advanced Portage Features</a></b><br>
As times goes by, Portage evolves and matures further and further. Additional
features are continuously being put in - many of these are only of use by more
advanced users. This chapter will go into more detail of these specific
features.
</li>
</ol>
</li>
<li>
<b><a href="#book_part4">Gentoo Network Configuration</a></b><br>A comprehensive guide to Networking in Gentoo.<ol>
<li>
<b><a href="#book_part4_chap1">Getting Started</a></b><br>
A guide to quickly get your network interface up and running in most common
environments.
</li>
<li>
<b><a href="#book_part4_chap2">Advanced Configuration</a></b><br>
Here we learn about how the configuration works - you need to know this
before we learn about modular networking.
</li>
<li>
<b><a href="#book_part4_chap3">Modular Networking</a></b><br>
Gentoo provides you flexible networking - here you are told about choosing
different DHCP clients, setting up bonding, bridging, VLANs and more.
</li>
<li>
<b><a href="#book_part4_chap4">Wireless Networking</a></b><br>
Wireless configuration can be tricky. Hopefully we'll get you working!
</li>
<li>
<b><a href="#book_part4_chap5">Adding Functionality</a></b><br>
If you're feeling adventurous, you can add your own functions to networking.
</li>
<li>
<b><a href="#book_part4_chap6">Network Management</a></b><br>
For laptop users or people who move their computer around different networks.
</li>
</ol>
</li>
</ul>
<a name="book_part1"></a><h2>A. Installing Gentoo</h2>
<a name="book_part1_chap1"></a><h3>1. About the Gentoo Linux Installation</h3>
<p class="chaphead"><a name="book_part1_chap1__chap1"></a><span class="chapnum">1.a. </span>Introduction</p>
<p class="secthead"><a name="book_part1_chap1__chap1_sect1">Welcome!</a></p>
<p>
First of all, <span class="emphasis">welcome</span> to Gentoo. You are about to enter the world
of choices and performance. Gentoo is all about choices. When
installing Gentoo, this is made clear to you several times -- you can
choose how much you want to compile yourself, how to install Gentoo,
what system logger you want, etc.
</p>
<p>
Gentoo is a fast, modern metadistribution with a clean and flexible
design. Gentoo is built around free software and doesn't hide from its
users what is beneath the hood. Portage, the package maintenance system
which Gentoo uses, is written in Python, meaning you can easily view and
modify the source code. Gentoo's packaging system uses source code
(although support for precompiled packages is included too) and
configuring Gentoo happens through regular textfiles. In other words,
openness everywhere.
</p>
<p>
It is very important that you understand that <span class="emphasis">choices</span> are what
makes Gentoo run. We try not to force you onto anything you don't like.
If you feel like we do, please <a href="https://bugs.gentoo.org">bugreport</a> it.
</p>
<p class="secthead"><a name="book_part1_chap1__chap1_sect2">How is the Installation Structured?</a></p>
<p>
The Gentoo Installation can be seen as a 10-step procedure,
corresponding to chapters 2 - 11. Every step results in
a certain state:
</p>
<ul>
<li>
After step 1, you are in a working environment ready to install Gentoo
</li>
<li>
After step 2, your internet connection is ready to install Gentoo
</li>
<li>
After step 3, your hard disks are initialized to house your Gentoo
installation
</li>
<li>
After step 4, your installation environment is prepared and you are
ready to chroot into the new environment
</li>
<li>
After step 5, core packages, which are the same on all Gentoo
installations, are installed
</li>
<li>
After step 6, you have compiled your Linux kernel
</li>
<li>
After step 7, you have written most of your Gentoo system
configuration files
</li>
<li>
After step 8, necessary system tools (which you can choose from a nice
list) are installed
</li>
<li>
After step 9, your choice of bootloader has been installed and
configured and you are logged in into your new Gentoo installation
</li>
<li>
After step 10, your Gentoo Linux environment is ready to be explored
</li>
</ul>
<p>
When you are given a certain choice, we try our best to explain what the pros
and cons are. We will continue then with a default
choice, identified by "Default: " in the title. The other
possibilities are marked by "Alternative: ". Do <span class="emphasis">not</span>
think that the default is what we recommend. It is however what we
believe most users will use.
</p>
<p>
Sometimes you can pursue an optional step. Such steps are marked as
"Optional: " and are therefore not needed to install Gentoo.
However, some optional steps are dependent on a previous decision you
made. We will inform you when this happens, both when you make the
decision, and right before the optional step is described.
</p>
<p class="secthead"><a name="book_part1_chap1__chap1_sect3">What are my Options?</a></p>
<p>
You can install Gentoo in many different ways. You can download and install from
one of our Installation CDs, from a distribution already installed, from a
non-Gentoo bootable CD (such as Knoppix), from a netbooted environment, from
a rescue floppy, etc.
</p>
<p>
This document covers the installation using a <span class="emphasis">Gentoo Installation CD</span> or,
in certain cases, netbooting. This installation assumes that you want to install
the latest available version of each package.
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
For help on the other installation approaches, including using non-Gentoo CDs,
please read our <a href="https://wiki.gentoo.org/wiki/Installation_alternatives">Alternative Installation
Guide</a>.
</p></td></tr></table>
<p>
We also provide a <a href="https://wiki.gentoo.org/wiki/Gentoo_installation_tips_and_tricks">Gentoo
Installation Tips &amp; Tricks</a> document that might be useful to read as
well.
</p>
<p class="secthead"><a name="book_part1_chap1__chap1_sect4">Troubles?</a></p>
<p>
If you find a problem in the installation (or in the installation
documentation), please visit our <a href="https://bugs.gentoo.org">bugtracking
system</a> and check if the bug is known. If not, please create a bugreport
for it so we can take care of it. Do not be afraid of the developers who are
assigned to (your) bugs -- they generally don't eat people.
</p>
<p>
Note though that, although the document you are now reading is
architecture-specific, it might contain references to other architectures as
well. This is due to the fact that large parts of the Gentoo Handbook use source
code that is common for all architectures (to avoid duplication of efforts and
starvation of development resources). We will try to keep this to a minimum
to avoid confusion.
</p>
<p>
If you are uncertain if the problem is a user-problem (some error you
made despite having read the documentation carefully) or a
software-problem (some error we made despite having tested the
installation/documentation carefully) you are welcome to join #gentoo on
irc.freenode.net. Of course, you are welcome otherwise too as our chat channel
covers the broad Gentoo spectrum :)
</p>
<p>
Speaking of which, if you have a question regarding Gentoo, check out our <a href="https://wiki.gentoo.org/wiki/FAQ">Frequently Asked Questions</a>, available from the <a href="https://wiki.gentoo.org">Gentoo Wiki</a>. You can also view the <a href="https://forums.gentoo.org/viewforum.php?f=40">FAQs</a> on our
<a href="https://forums.gentoo.org">forums</a>.
</p>
<a name="book_part1_chap2"></a><h3>2. Choosing the Right Installation Medium</h3>
<p class="chaphead"><a name="book_part1_chap2__chap1"></a><span class="chapnum">2.a. </span>Hardware Requirements</p>
<p class="secthead"><a name="book_part1_chap2__chap1_sect1">Introduction</a></p>
<p>
Before we start, we first list what hardware requirements you need to
successfully install Gentoo on your box.
</p>
<p class="secthead"><a name="book_part1_chap2__chap1_sect2">Hardware Requirements</a></p>
<table class="ntable">
<tr>
<td class="tableinfo"></td>
<td class="infohead"><b>Minimal CD</b></td>
<td class="infohead"><b>LiveDVD</b></td>
</tr>
<tr>
<td class="infohead"><b>CPU</b></td>
<td class="tableinfo">i486 or later</td>
<td class="tableinfo">
<b>i686</b> or later</td>
</tr>
<tr>
<td class="infohead"><b>Memory</b></td>
<td class="tableinfo">256 MB</td>
<td class="tableinfo">512 MB</td>
</tr>
<tr>
<td class="infohead"><b>Diskspace</b></td>
<td class="tableinfo" colspan="2">2.5 GB (excluding swap space)</td>
</tr>
<tr>
<td class="infohead"><b>Swap space</b></td>
<td class="tableinfo" colspan="2">At least 256 MB</td>
</tr>
</table>
<p class="chaphead"><a name="book_part1_chap2__chap2"></a><span class="chapnum">2.b. </span>The Gentoo Installation CD</p>
<p class="secthead"><a name="book_part1_chap2__chap2_sect1">Gentoo Minimal Installation CD</a></p>
<p>
The <span class="emphasis">Minimal Installation CD</span> is a bootable CD which contains a
self-sustained Gentoo environment. It allows you to boot Linux from the CD.
During the boot process your hardware is detected and the appropriate drivers
are loaded. The CD is maintained by Gentoo developers and allows you to install
Gentoo with an active Internet connection.
</p>
<p>
The Minimal Installation CD is called <span class="code" dir="ltr">install-x86-minimal-&lt;release&gt;.iso</span> and
takes up around 140 MB of diskspace.
</p>
<p class="secthead"><a name="book_part1_chap2__chap2_sect2">Gentoo Linux LiveDVDs</a></p>
<p>
Occasionally, a special DVD is crafted by the Gentoo Ten
project which can be used to install Gentoo with too. The instructions further
down this chapter target the Minimal Installation CD so might be a bit
different. However, the LiveDVD (or any other bootable
Linux environment) supports getting a root prompt by just invoking <span class="code" dir="ltr">sudo
su -</span> or <span class="code" dir="ltr">sudo -i</span> on a terminal.
</p>
<p class="secthead"><a name="book_part1_chap2__chap2_sect3">The Stage3 Tarball</a></p>
<p>
A stage3 tarball is an archive containing a minimal Gentoo environment,
suitable to continue the Gentoo installation using the instructions in this
manual. Previously, the Gentoo Handbook described the installation using one of
three stage tarballs. While Gentoo still offers stage1 and stage2 tarballs, the
official installation method uses the stage3 tarball. If you are interested in
performing a Gentoo installation using a stage1 or stage2 tarball, please read
the Gentoo FAQ on <a href="https://wiki.gentoo.org/wiki/FAQ#How_do_I_Install_Gentoo_Using_a_Stage1_or_Stage2_Tarball.3F">How
do I Install Gentoo Using a Stage1 or Stage2 Tarball?</a>
</p>
<p>
Stage3 tarballs can be downloaded from <span class="path" dir="ltr">releases/x86/autobuilds/current-stage3/</span> on any of the <a href="/main/en/mirrors.xml?style=printable">Official Gentoo Mirrors</a> and are not provided
on the LiveDVD.
</p>
<p class="chaphead"><a name="book_part1_chap2__chap3"></a><span class="chapnum">2.c. </span>Download, Burn and Boot a Gentoo Installation CD</p>
<p class="secthead"><a name="book_part1_chap2__chap3_sect1">Downloading and Burning the Installation CD</a></p>
<p>
You have chosen to use a Gentoo Installation CD. We'll first start by
downloading and burning the chosen Installation CD. We previously discussed
the Installation CD, but where can you find it?
</p>
<p>
You can download any of the Installation CD from one of our <a href="/main/en/mirrors.xml?style=printable">mirrors</a>. The Installation CD is located in
the <span class="path" dir="ltr">releases/x86/autobuilds/current-iso/</span> directory.
</p>
<p>
Inside that directory you'll find the ISO file. This is a full CD image which you
can write on a CD-R.
</p>
<p>
In case you wonder if your downloaded file is corrupted or not, you can check
its SHA-2 checksum and compare it with the SHA-2 checksum we provide (such as
<span class="path" dir="ltr">install-x86-minimal-&lt;release&gt;.iso.DIGESTS</span>). You can check the SHA-2
checksum with the <span class="code" dir="ltr">sha512sum</span> tool under Linux/Unix or <a href="http://www.sinf.gr/en/hashcalc.html">Checksums calculator</a> for Windows.
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
The tool will attempt to verify the checksums in the list, even if the checksum
is made with a different algorithm. Therefore, the output of the command might
give both success (for SHA checksums) and failures (for other checksums). At
least one OK needs to be provided for each file.
</p></td></tr></table>
<a name="book_part1_chap2__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: Verifying the SHA-2 checksum</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
$ <span class="code-input">sha512sum -c &lt;downloaded iso.DIGESTS&gt;</span>
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
If you get the message that no properly formatted SHA checksum was found, take a
look at the DIGESTS file yourself to see what the supported checksums are.
</p></td></tr></table>
<p>
Another way to check the validity of the downloaded file is to use GnuPG to
verify the cryptographic signature that we provide (the file ending with
<span class="path" dir="ltr">.asc</span>). Download the signature file and obtain the public keys whose
key ids can be found on the <a href="/proj/en/releng/index.xml?style=printable">release
engineering project site</a>.
</p>
<a name="book_part1_chap2__chap3_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.2: Obtaining the public key</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment">(... Substitute the key ids with those mentioned on the release engineering site ...)</span>
$ <span class="code-input">gpg --keyserver subkeys.pgp.net --recv-keys 96D8BF6D 2D182910 17072058</span>
</pre></td></tr>
</table>
<p>
Now verify the signature:
</p>
<a name="book_part1_chap2__chap3_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.3: Verify the files</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
$ <span class="code-input">gpg --verify &lt;downloaded iso.DIGESTS.asc&gt;</span>
$ <span class="code-input">sha512sum -c &lt;downloaded iso.DIGESTS.asc&gt;</span>
</pre></td></tr>
</table>
<p>
To burn the downloaded ISO(s), you have to select raw-burning. How you
do this is highly program-dependent. We will discuss <span class="code" dir="ltr">cdrecord</span> and
<span class="code" dir="ltr">K3B</span> here; more information can be found in our <a href="https://wiki.gentoo.org/wiki/FAQ#How_do_I_burn_an_ISO_file.3F">Gentoo FAQ</a>.
</p>
<ul>
<li>
With cdrecord, you simply type <span class="code" dir="ltr">cdrecord dev=/dev/sr0 &lt;downloaded iso
file&gt;</span> (replace <span class="path" dir="ltr">/dev/sr0</span> with your CD-RW drive's
device path).
</li>
<li>
With K3B, select <span class="code" dir="ltr">Tools</span> &gt; <span class="code" dir="ltr">Burn CD Image</span>. Then you can locate
your ISO file within the 'Image to Burn' area. Finally click <span class="code" dir="ltr">Start</span>.
</li>
</ul>
<p class="secthead"><a name="book_part1_chap2__chap3_sect2">Booting the Installation CD</a></p>
<p>
Once you have burnt your installation CD, it is time to boot it.
Remove all CDs from your CD drives, reboot your system and enter the BIOS.
This is usually done by hitting DEL, F1 or ESC, depending on your BIOS. Inside
the BIOS, change the boot order so that the CD-ROM is tried before the hard
disk. This is often found under "CMOS Setup". If you don't do this, your system
will just reboot from the hard disk, ignoring the CD-ROM.
</p>
<p>
Now place the installation CD in the CD-ROM drive and reboot. You should see a
boot prompt. At this screen, you can hit Enter to begin the boot process with
the default boot options, or boot the Installation CD with custom boot options
by specifying a kernel followed by boot options and then hitting Enter.
</p>
<p>
When the boot prompt is shown, you get the option of displaying the available
kernels (<span class="code" dir="ltr">F1</span>) and boot options (<span class="code" dir="ltr">F2</span>). If you make no selection
within 15 seconds (either displaying information or using a kernel) then the
LiveDVD will fall back to booting from disk. This allows installations to reboot
and try out their installed environment without the need to remove the CD from
the tray (something well appreciated for remote installations).
</p>
<p>
Now we mentioned specifying a kernel. On our Installation CD, we provide
several kernels. The default one is <span class="code" dir="ltr">gentoo</span>. Other kernels are for
specific hardware needs and the <span class="code" dir="ltr">-nofb</span> variants which disable
framebuffer.
</p>
<p>
Below you'll find a short overview on the available kernels:
</p>
<table class="ntable">
<tr>
<td class="infohead"><b>Kernel</b></td>
<td class="infohead"><b>Description</b></td>
</tr>
<tr>
<td class="tableinfo">gentoo</td>
<td class="tableinfo">Default 2.6 kernel with support for multiple CPUs</td>
</tr>
<tr>
<td class="tableinfo">gentoo-nofb</td>
<td class="tableinfo">Same as <span class="code" dir="ltr">gentoo</span> but without framebuffer support</td>
</tr>
<tr>
<td class="tableinfo">memtest86</td>
<td class="tableinfo">Test your local RAM for errors</td>
</tr>
</table>
<p>
You can also provide kernel options. They represent optional settings you can
(de)activate at will.
</p>
<p>
<font color="#ff0000"><b>Hardware options:</b></font>
</p>
<dl>
<dt>acpi=on</dt>
<dd>
This loads support for ACPI and also causes the acpid daemon to be started by
the CD on boot. This is only needed if your system requires ACPI to function
properly. This is not required for Hyperthreading support.
</dd>
<dt>acpi=off</dt>
<dd>
Completely disables ACPI. This is useful on some older systems and is also a
requirement for using APM. This will disable any Hyperthreading support of
your processor.
</dd>
<dt>console=X</dt>
<dd>
This sets up serial console access for the CD. The first option is the
device, usually ttyS0 on x86, followed by any connection options, which are
comma separated. The default options are 9600,8,n,1.
</dd>
<dt>dmraid=X</dt>
<dd>
This allows for passing options to the device-mapper RAID subsystem. Options
should be encapsulated in quotes.
</dd>
<dt>doapm</dt>
<dd>
This loads APM driver support. This requires you to also use acpi=off.
</dd>
<dt>dopcmcia</dt>
<dd>
This loads support for PCMCIA and Cardbus hardware and also causes the pcmcia
cardmgr to be started by the CD on boot. This is only required when booting
from PCMCIA/Cardbus devices.
</dd>
<dt>doscsi</dt>
<dd>
This loads support for most SCSI controllers. This is also a requirement for
booting most USB devices, as they use the SCSI subsystem of the kernel.
</dd>
<dt>sda=stroke</dt>
<dd>
This allows you to partition the whole hard disk even when your BIOS is unable
to handle large disks. This option is only used on machines with an older BIOS.
Replace sda with the device that requires this option.
</dd>
<dt>ide=nodma</dt>
<dd>
This forces the disabling of DMA in the kernel and is required by some IDE
chipsets and also by some CDROM drives. If your system is having trouble
reading from your IDE CDROM, try this option. This also disables the default
hdparm settings from being executed.
</dd>
<dt>noapic</dt>
<dd>
This disables the Advanced Programmable Interrupt Controller that is present
on newer motherboards. It has been known to cause some problems on older
hardware.
</dd>
<dt>nodetect</dt>
<dd>
This disables all of the autodetection done by the CD, including device
autodetection and DHCP probing. This is useful for doing debugging of a
failing CD or driver.
</dd>
<dt>nodhcp</dt>
<dd>
This disables DHCP probing on detected network cards. This is useful on
networks with only static addresses.
</dd>
<dt>nodmraid</dt>
<dd>
Disables support for device-mapper RAID, such as that used for on-board
IDE/SATA RAID controllers.
</dd>
<dt>nofirewire</dt>
<dd>
This disables the loading of Firewire modules. This should only be necessary
if your Firewire hardware is causing a problem with booting the CD.
</dd>
<dt>nogpm</dt>
<dd>
This disables gpm console mouse support.
</dd>
<dt>nohotplug</dt>
<dd>
This disables the loading of the hotplug and coldplug init scripts at boot.
This is useful for doing debugging of a failing CD or driver.
</dd>
<dt>nokeymap</dt>
<dd>
This disables the keymap selection used to select non-US keyboard layouts.
</dd>
<dt>nolapic</dt>
<dd>
This disables the local APIC on Uniprocessor kernels.
</dd>
<dt>nosata</dt>
<dd>
This disables the loading of Serial ATA modules. This is used if your system
is having problems with the SATA subsystem.
</dd>
<dt>nosmp</dt>
<dd>
This disables SMP, or Symmetric Multiprocessing, on SMP-enabled kernels. This
is useful for debugging SMP-related issues with certain drivers and
motherboards.
</dd>
<dt>nosound</dt>
<dd>
This disables sound support and volume setting. This is useful for systems
where sound support causes problems.
</dd>
<dt>nousb</dt>
<dd>
This disables the autoloading of USB modules. This is useful for debugging
USB issues.
</dd>
<dt>slowusb</dt>
<dd>
This adds some extra pauses into the boot process for slow USB CDROMs, like
in the IBM BladeCenter.
</dd>
</dl>
<p>
<font color="#ff0000"><b>Volume/Device Management:</b></font>
</p>
<dl>
<dt>dolvm</dt>
<dd>
This enables support for Linux's Logical Volume Management.
</dd>
</dl>
<p>
<font color="#ff0000"><b>Other options:</b></font>
</p>
<dl>
<dt>debug</dt>
<dd>
Enables debugging code. This might get messy, as it displays a lot of data to
the screen.
</dd>
<dt>docache</dt>
<dd>
This caches the entire runtime portion of the CD into RAM, which allows you
to umount /mnt/cdrom and mount another CDROM. This option requires that you
have
at least twice as much available RAM as the size of the CD.
</dd>
<dt>doload=X</dt>
<dd>
This causes the initial ramdisk to load any module listed, as well as
dependencies. Replace X with the module name.
<br>
Multiple modules can be specified by a comma-separated list.
</dd>
<dt>dosshd</dt>
<dd>
Starts sshd on boot, which is useful for unattended installs.
</dd>
<dt>passwd=foo</dt>
<dd>
Sets whatever follows the equals as the root password, which is required for
dosshd since we scramble the root password.
</dd>
<dt>noload=X</dt>
<dd>
This causes the initial ramdisk to skip the loading of a specific module that
may be causing a problem. Syntax matches that of doload.
</dd>
<dt>nonfs</dt>
<dd>
Disables the starting of portmap/nfsmount on boot.
</dd>
<dt>nox</dt>
<dd>
This causes an X-enabled LiveCD to not automatically start X, but rather, to
drop to the command line instead.
</dd>
<dt>scandelay</dt>
<dd>
This causes the CD to pause for 10 seconds during certain portions the boot
process to allow for devices that are slow to initialize to be ready for use.
</dd>
<dt>scandelay=X</dt>
<dd>
This allows you to specify a given delay, in seconds, to be added to certain
portions of the boot process to allow for devices that are slow to initialize
to be ready for use. Replace X with the number of seconds to pause.
</dd>
</dl>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
The CD will check for "no*" options before "do*" options, so that you can
override any option in the exact order you specify.
</p></td></tr></table>
<p>
Now boot your CD, select a kernel (if you are not happy with the default
<span class="code" dir="ltr">gentoo</span> kernel) and boot options. As an example, we show you how
to boot the <span class="code" dir="ltr">gentoo</span> kernel, with <span class="code" dir="ltr">dopcmcia</span> as kernel
parameters:
</p>
<a name="book_part1_chap2__chap3_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.4: Booting an Installation CD</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
boot: <span class="code-input">gentoo dopcmcia</span>
</pre></td></tr>
</table>
<p>
You will then be greeted with a boot screen and progress bar. If you are
installing Gentoo on a system with a non-US keyboard, make sure you immediately
press Alt-F1 to switch to verbose mode and follow the prompt. If no selection
is made in 10 seconds the default (US keyboard) will be accepted and the boot
process will continue. Once the boot process completes, you will be
automatically logged in to the "Live" Gentoo Linux as "root", the super user.
You should have a root ("#") prompt on the current console and can also switch
to other consoles by pressing Alt-F2, Alt-F3 and Alt-F4. Get back to the one
you started on by pressing Alt-F1.
</p>
<p>
Now continue with <a href="#hardware">Extra Hardware Configuration</a>.
</p>
<p class="secthead"><a name="hardware"></a><a name="book_part1_chap2__chap3_sect3">Extra Hardware Configuration</a></p>
<p>
When the Installation CD boots, it tries to detect all your hardware devices and
loads the appropriate kernel modules to support your hardware. In the
vast majority of cases, it does a very good job. However, in some cases it may
not auto-load the kernel
modules you need. If the PCI auto-detection missed some of your system's
hardware, you will have to load the appropriate kernel modules manually.
</p>
<p>
In the next example we try to load the <span class="code" dir="ltr">8139too</span> module (support for
certain kinds of network interfaces):
</p>
<a name="book_part1_chap2__chap3_pre5"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.5: Loading kernel modules</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">modprobe 8139too</span>
</pre></td></tr>
</table>
<p class="secthead"><a name="useraccounts"></a><a name="book_part1_chap2__chap3_sect4">Optional: User Accounts</a></p>
<p>
If you plan on giving other people access to your installation
environment or you want to chat using <span class="code" dir="ltr">irssi</span> without root privileges (for
security reasons), you need to create the necessary user accounts and change
the root password.
</p>
<p>
To change the root password, use the <span class="code" dir="ltr">passwd</span> utility:
</p>
<a name="book_part1_chap2__chap3_pre6"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.6: Changing the root password</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">passwd</span>
New password: <span class="code-comment">(Enter your new password)</span>
Re-enter password: <span class="code-comment">(Re-enter your password)</span>
</pre></td></tr>
</table>
<p>
To create a user account, we first enter their credentials, followed by
its password. We use <span class="code" dir="ltr">useradd</span> and <span class="code" dir="ltr">passwd</span> for these tasks.
In the next example, we create a user called "john".
</p>
<a name="book_part1_chap2__chap3_pre7"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.7: Creating a user account</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">useradd -m -G users john</span>
# <span class="code-input">passwd john</span>
New password: <span class="code-comment">(Enter john's password)</span>
Re-enter password: <span class="code-comment">(Re-enter john's password)</span>
</pre></td></tr>
</table>
<p>
You can change your user id from root to the newly created user by using
<span class="code" dir="ltr">su</span>:
</p>
<a name="book_part1_chap2__chap3_pre8"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.8: Changing user id</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">su - john</span>
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part1_chap2__chap3_sect5">Optional: Viewing Documentation while Installing</a></p>
<p>
If you want to view the Gentoo Handbook during the installation, make sure you
have created a user account (see <a href="#useraccounts">Optional: User
Accounts</a>). Then press <span class="code" dir="ltr">Alt-F2</span> to go to a new terminal.
</p>
<p>
You can view the handbook using <span class="code" dir="ltr">links</span>, once you have completed the
<span class="emphasis">Configuring your Network</span> chapter (otherwise you won't be able to go on
the Internet to view the document):
</p>
<a name="book_part1_chap2__chap3_pre9"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.9: Viewing the Online Documentation</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">links http://www.gentoo.org/doc/en/handbook/handbook-x86.xml</span>
</pre></td></tr>
</table>
<p>
You can go back to your original terminal by pressing <span class="code" dir="ltr">Alt-F1</span>.
</p>
<p class="secthead"><a name="book_part1_chap2__chap3_sect6">Optional: Starting the SSH Daemon</a></p>
<p>
If you want to allow other users to access your computer during the
Gentoo installation (perhaps because those users are going to help you
install Gentoo, or even do it for you), you need to create a user
account for them and perhaps even provide them with your root password
(<span class="emphasis">only</span> do that <span class="emphasis">if</span> you <b>fully trust</b> that user).
</p>
<p>
To fire up the SSH daemon, execute the following command:
</p>
<a name="book_part1_chap2__chap3_pre10"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.10: Starting the SSH daemon</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">/etc/init.d/sshd start</span>
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
If you (or other users) log on to the system, they will get a message that the
host key for this system needs to be confirmed (through what is called a
fingerprint). This is to be expected as it is the first time people log on
to the system.
However, later when your system is set up and you log on to the newly created
system, your SSH client will warn you that the host key has been changed. This
is because you now log on to - for SSH - a different server (namely your freshly
installed Gentoo system rather than the live environment you are on right now).
When you hit that warning, follow the instructions given on the screen then
to replace the host key on the client system.
</p></td></tr></table>
<p>
To be able to use sshd, you first need to set up your networking. Continue with
the chapter on <a href="#book_part1_chap3">Configuring your Network</a>.
</p>
<a name="book_part1_chap3"></a><h3>3. Configuring your Network</h3>
<p class="chaphead"><a name="book_part1_chap3__chap1"></a><span class="chapnum">3.a. </span>Automatic Network Detection</p>
<p class="secthead"><a name="book_part1_chap3__chap1_sect1">Maybe it just works?</a></p>
<p>
If your system is plugged into an Ethernet network with a DHCP server, it is
very likely that your networking configuration has already been set up
automatically for you. If so, you should be able to take advantage of the many
included network-aware commands on the Installation CD such as <span class="code" dir="ltr">ssh</span>,
<span class="code" dir="ltr">scp</span>, <span class="code" dir="ltr">ping</span>, <span class="code" dir="ltr">irssi</span>, <span class="code" dir="ltr">wget</span> and <span class="code" dir="ltr">links</span>, among
others.
</p>
<p>
If networking has been configured for you, the <span class="code" dir="ltr">ifconfig</span> command
should list some network interfaces besides lo, such as eth0:
</p>
<a name="book_part1_chap3__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: ifconfig for a working network configuration</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">ifconfig</span>
<span class="code-comment">(...)</span>
eth0 Link encap:Ethernet HWaddr 00:50:BA:8F:61:7A
inet addr:192.168.0.2 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::50:ba8f:617a/10 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1498792 errors:0 dropped:0 overruns:0 frame:0
TX packets:1284980 errors:0 dropped:0 overruns:0 carrier:0
collisions:1984 txqueuelen:100
RX bytes:485691215 (463.1 Mb) TX bytes:123951388 (118.2 Mb)
Interrupt:11 Base address:0xe800
</pre></td></tr>
</table>
<p>
The interface name on your system can be quite different from eth0. Recent
installation media might show regular network interfaces names like eno0, ens1
or enp5s0. Just seek the interface in the <span class="code" dir="ltr">ifconfig</span> output that has an IP
address related to your local network.
</p>
<p>
In the remainder of this document, we will assume that the interface is called
eth0.
</p>
<p class="secthead"><a name="book_part1_chap3__chap1_sect2">Optional: Configure any Proxies</a></p>
<p>
If you access the Internet through a proxy, you might need to set up proxy
information during the installation. It is very easy to define a proxy: you just
need to define a variable which contains the proxy server information.
</p>
<p>
In most cases, you can just define the variables using the server hostname. As
an example, we assume the proxy is called <span class="code" dir="ltr">proxy.gentoo.org</span> and the port
is <span class="code" dir="ltr">8080</span>.
</p>
<a name="book_part1_chap3__chap1_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.2: Defining proxy servers</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment">(If the proxy filters HTTP traffic)</span>
# <span class="code-input">export http_proxy="http://proxy.gentoo.org:8080"</span>
<span class="code-comment">(If the proxy filters FTP traffic)</span>
# <span class="code-input">export ftp_proxy="ftp://proxy.gentoo.org:8080"</span>
<span class="code-comment">(If the proxy filters RSYNC traffic)</span>
# <span class="code-input">export RSYNC_PROXY="proxy.gentoo.org:8080"</span>
</pre></td></tr>
</table>
<p>
If your proxy requires a username and password, you should use the following
syntax for the variable:
</p>
<a name="book_part1_chap3__chap1_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.3: Adding username/password to the proxy variable</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
http://<span class="code-input">username</span>:<span class="code-input">password</span>@proxy.gentoo.org:8080
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part1_chap3__chap1_sect3">Testing the Network</a></p>
<p>
You may want to try pinging your ISP's DNS server (found in
<span class="path" dir="ltr">/etc/resolv.conf</span>) and a Web site of your choice, just to make sure
that your packets are reaching the net, DNS name resolution is working
correctly, etc.
</p>
<a name="book_part1_chap3__chap1_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.4: Further network testing</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">ping -c 3 www.gentoo.org</span>
</pre></td></tr>
</table>
<p>
If you are now able to use your network, you can skip the rest of this
section and continue with <a href="#book_part1_chap4">Preparing the
Disks</a>. If not, read on.
</p>
<p class="chaphead"><a name="book_part1_chap3__chap2"></a><span class="chapnum">3.b. </span>Automatic Network Configuration</p>
<p>
If the network doesn't work immediately, some installation media allow you to
use <span class="code" dir="ltr">net-setup</span> (for regular or wireless networks), <span class="code" dir="ltr">pppoe-setup</span>
(for ADSL-users) or <span class="code" dir="ltr">pptp</span> (for PPTP-users - available on x86, amd64,
alpha, ppc and ppc64).
</p>
<p>
If your installation medium does not contain any of these tools or your network
doesn't function yet, continue with <a href="#book_part1_chap3__chap3">Manual Network
Configuration</a>.
</p>
<ul>
<li>
Regular Ethernet users should continue with <a href="#net-setup">Default: Using net-setup</a>
</li>
<li>
ADSL users should continue with <a href="#ppp">Alternative:
Using PPP</a>
</li>
<li>
PPTP users should continue with <a href="#pptp">Alternative:
Using PPTP</a>
</li>
</ul>
<p class="secthead"><a name="net-setup"></a><a name="book_part1_chap3__chap2_sect2">Default: Using net-setup</a></p>
<p>
The simplest way to set up networking if it didn't get configured
automatically is to run the <span class="code" dir="ltr">net-setup</span> script:
</p>
<a name="book_part1_chap3__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: Running the net-setup script</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">net-setup eth0</span>
</pre></td></tr>
</table>
<p>
<span class="code" dir="ltr">net-setup</span> will ask you some questions about your network
environment. When all is done, you should have a working network
connection. Test your network connection as stated before. If the tests
are positive, congratulations! You are now ready to install Gentoo. Skip
the rest of this section and continue with <a href="#book_part1_chap4">Preparing the Disks</a>.
</p>
<p>
If your network still doesn't work, continue with <a href="#book_part1_chap3__chap3">Manual
Network Configuration</a>.
</p>
<p class="secthead"><a name="ppp"></a><a name="book_part1_chap3__chap2_sect3">Alternative: Using PPP</a></p>
<p>
Assuming you need PPPoE to connect to the internet, the Installation CD (any
version) has made things easy for you by including <span class="code" dir="ltr">ppp</span>. Use the provided
<span class="code" dir="ltr">pppoe-setup</span> script to configure your connection. You will be prompted for
the ethernet device that is connected to your adsl modem, your username and
password, the IPs of your DNS servers and if you need a basic firewall or not.
</p>
<a name="book_part1_chap3__chap2_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.2: Using ppp</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">pppoe-setup</span>
# <span class="code-input">pppoe-start</span>
</pre></td></tr>
</table>
<p>
If something goes wrong, double-check that you correctly typed your username and
password by looking at <span class="path" dir="ltr">/etc/ppp/pap-secrets</span> or
<span class="path" dir="ltr">/etc/ppp/chap-secrets</span> and make sure you are using the right
ethernet device. If your ethernet device doesn't exist, you will have to load
the appropriate network modules. In that case you should continue with
<a href="#book_part1_chap3__chap3">Manual Network Configuration</a> as we explain how to
load the appropriate network modules there.
</p>
<p>
If everything worked, continue with <a href="#book_part1_chap4">Preparing the
Disks</a>.
</p>
<p class="secthead"><a name="pptp"></a><a name="book_part1_chap3__chap2_sect4">Alternative: Using PPTP</a></p>
<p>
If you need PPTP support, you can use <span class="code" dir="ltr">pptpclient</span> which is provided by our
Installation CDs. But first you need to make sure that your configuration is
correct. Edit <span class="path" dir="ltr">/etc/ppp/pap-secrets</span> or
<span class="path" dir="ltr">/etc/ppp/chap-secrets</span> so it contains the correct username/password
combination:
</p>
<a name="book_part1_chap3__chap2_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.3: Editing /etc/ppp/chap-secrets</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">nano -w /etc/ppp/chap-secrets</span>
</pre></td></tr>
</table>
<p>
Then adjust <span class="path" dir="ltr">/etc/ppp/options.pptp</span> if necessary:
</p>
<a name="book_part1_chap3__chap2_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.4: Editing /etc/ppp/options.pptp</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">nano -w /etc/ppp/options.pptp</span>
</pre></td></tr>
</table>
<p>
When all that is done, just run <span class="code" dir="ltr">pptp</span> (along with the options you couldn't
set in <span class="path" dir="ltr">options.pptp</span>) to connect the server:
</p>
<a name="book_part1_chap3__chap2_pre5"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.5: Connection to a dial-in server</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">pptp &lt;server ip&gt;</span>
</pre></td></tr>
</table>
<p>
Now continue with <a href="#book_part1_chap4">Preparing the Disks</a>.
</p>
<p class="chaphead"><a name="book_part1_chap3__chap3"></a><span class="chapnum">3.c. </span>Manual Network Configuration</p>
<p class="secthead"><a name="book_part1_chap3__chap3_sect1">Loading the Appropriate Network Modules</a></p>
<p>
When the Installation CD boots, it tries to detect all your hardware devices and
loads the appropriate kernel modules (drivers) to support your hardware. In the
vast majority of cases, it does a very good job. However, in some cases,
it may not auto-load the kernel modules you need.
</p>
<p>
If <span class="code" dir="ltr">net-setup</span> or <span class="code" dir="ltr">pppoe-setup</span> failed, then it is possible that
your network card wasn't found immediately. This means you may have to load
the appropriate kernel modules manually.
</p>
<p>
To find out what kernel modules we provide for networking, use
<span class="code" dir="ltr">ls</span>:
</p>
<a name="book_part1_chap3__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: Searching for provided modules</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">ls /lib/modules/`uname -r`/kernel/drivers/net</span>
</pre></td></tr>
</table>
<p>
If you find a driver for your network card, use <span class="code" dir="ltr">modprobe</span> to load
the kernel module:
</p>
<a name="book_part1_chap3__chap3_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.2: Using modprobe to load a kernel module</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment">(As an example, we load the pcnet32 module)</span>
# <span class="code-input">modprobe pcnet32</span>
</pre></td></tr>
</table>
<p>
To check if your network card is now detected, use <span class="code" dir="ltr">ifconfig</span>. A
detected network card would result in something like this (again, eth0 here is
just an example):
</p>
<a name="book_part1_chap3__chap3_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.3: Testing availability of your network card, successful</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">ifconfig eth0</span>
eth0 Link encap:Ethernet HWaddr FE:FD:00:00:00:00
BROADCAST NOARP MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
</pre></td></tr>
</table>
<p>
If however you receive the following error, the network card is not
detected:
</p>
<a name="book_part1_chap3__chap3_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.4: Testing availability of your network card, failed</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">ifconfig eth0</span>
eth0: error fetching interface information: Device not found
</pre></td></tr>
</table>
<p>
The available network interface names on your system can be listed through the
<span class="path" dir="ltr">/sys</span> file system:
</p>
<a name="book_part1_chap3__chap3_pre5"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.5: Viewing the available network interfaces</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">ls /sys/class/net</span>
dummy0 eth0 lo sit0 tap0 wlan0
</pre></td></tr>
</table>
<p>
In the above example, 6 interfaces are found. The eth0 one is most likely the
(wired) Ethernet adapter whereas wlan0 is the wireless one.
</p>
<p>
Assuming that you now have a detected network card, you can
retry <span class="code" dir="ltr">net-setup</span> or <span class="code" dir="ltr">pppoe-setup</span> again (which should work
now), but for the hardcore people amongst you we explain how to configure your
network manually.
</p>
<p>
Select one of the following sections based on your network setup:
</p>
<ul>
<li>
<a href="#install-dhcp">Using DHCP</a> for automatic IP retrieval</li>
<li>
<a href="#wireless">Preparing for Wireless Access</a> if you have a
wireless card
</li>
<li>
<a href="#network_term">Understanding Network Terminology</a> explains
what you need to know about networking
</li>
<li>
<a href="#ifconfig_route">Using ifconfig and route</a> explains how to
set up your networking manually
</li>
</ul>
<p class="secthead"><a name="install-dhcp"></a><a name="book_part1_chap3__chap3_sect2">Using DHCP</a></p>
<p>
DHCP (Dynamic Host Configuration Protocol) makes it possible to
automatically receive networking information (IP address, netmask,
broadcast address, gateway, nameservers etc.). This only works if you
have a DHCP server in your network (or if your provider provides a DHCP
service). To have a network interface receive this information automatically,
use <span class="code" dir="ltr">dhcpcd</span>:
</p>
<a name="book_part1_chap3__chap3_pre6"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.6: Using dhcpcd</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">dhcpcd eth0</span>
<span class="code-comment">Some network admins require that you use the</span>
<span class="code-comment">hostname and domainname provided by the DHCP server.</span>
<span class="code-comment">In that case, use</span>
# <span class="code-input">dhcpcd -HD eth0</span>
</pre></td></tr>
</table>
<p>
If this works (try pinging some internet server, like <a href="http://www.google.com">Google</a>), then you are all set and
ready to continue. Skip the rest of this section and continue with <a href="#book_part1_chap4">Preparing the Disks</a>.
</p>
<p class="secthead"><a name="wireless"></a><a name="book_part1_chap3__chap3_sect3">Preparing for Wireless Access</a></p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
Support for the <span class="code" dir="ltr">iwconfig</span> command is only available on x86, amd64 and ppc
Installation CDs. You can still get the extensions working otherwise
by following the instructions of the
<a href="ftp://ftp.linux-wlan.org/pub/linux-wlan-ng/README">linux-wlan-ng
project</a>.
</p></td></tr></table>
<p>
If you are using a wireless (802.11) card, you may need to configure your
wireless settings before going any further. To see the current wireless settings
on your card, you can use <span class="code" dir="ltr">iwconfig</span>. Running <span class="code" dir="ltr">iwconfig</span> might show
something like:
</p>
<a name="book_part1_chap3__chap3_pre7"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.7: Showing the current wireless settings</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">iwconfig eth0</span>
eth0 IEEE 802.11-DS ESSID:"GentooNode"
Mode:Managed Frequency:2.442GHz Access Point: 00:09:5B:11:CC:F2
Bit Rate:11Mb/s Tx-Power=20 dBm Sensitivity=0/65535
Retry limit:16 RTS thr:off Fragment thr:off
Power Management:off
Link Quality:25/10 Signal level:-51 dBm Noise level:-102 dBm
Rx invalid nwid:5901 Rx invalid crypt:0 Rx invalid frag:0 Tx
excessive retries:237 Invalid misc:350282 Missed beacon:84
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
Some wireless cards may have a device name of <span class="code" dir="ltr">wlan0</span> or <span class="code" dir="ltr">ra0</span> instead
of <span class="code" dir="ltr">eth0</span>. Run <span class="code" dir="ltr">iwconfig</span> without any command-line parameters to
determine the correct device name.
</p></td></tr></table>
<p>
For most users, there are only two settings that might be important to change,
the ESSID (aka wireless network name) or the WEP key. If the ESSID and Access
Point address listed are already that of your access point and you are not using
WEP, then your wireless is working. If you need to change your ESSID, or add a
WEP key, you can issue the following commands:
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
If your wireless network is set up with WPA or WPA2, you will need to use
<span class="code" dir="ltr">wpa_supplicant</span>. For more information on configuring wireless networking
in Gentoo Linux, please read the <a href="#book_part4_chap4">Wireless
Networking</a> chapter in the Gentoo Handbook.
</p></td></tr></table>
<a name="book_part1_chap3__chap3_pre8"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.8: Changing ESSID and/or adding WEP key</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment">(This sets the network name to "GentooNode")</span>
# <span class="code-input">iwconfig eth0 essid GentooNode</span>
<span class="code-comment">(This sets a hex WEP key)</span>
# <span class="code-input">iwconfig eth0 key 1234123412341234abcd</span>
<span class="code-comment">(This sets an ASCII key - prefix it with "s:")</span>
# <span class="code-input">iwconfig eth0 key s:some-password</span>
</pre></td></tr>
</table>
<p>
You can then confirm your wireless settings again by using <span class="code" dir="ltr">iwconfig</span>.
Once you have wireless working, you can continue configuring the IP level
networking options as described in the next section (<a href="#network_term">Understanding Network Terminology</a>) or use the
<span class="code" dir="ltr">net-setup</span> tool as described previously.
</p>
<p class="secthead"><a name="network_term"></a><a name="book_part1_chap3__chap3_sect4">Understanding Network Terminology</a></p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
If you know your IP address, broadcast address, netmask and nameservers,
then you can skip this subsection and continue with <a href="#ifconfig_route">Using ifconfig and route</a>.
</p></td></tr></table>
<p>
If all of the above fails, you will have to configure your network manually.
This is not difficult at all. However, you need to be familiar with some
network terminology, as you will need it to be able to
configure your network to your satisfaction. After reading this, you
will know what a <span class="emphasis">gateway</span> is, what a <span class="emphasis">netmask</span> serves for,
how a <span class="emphasis">broadcast</span> address is formed and why you need
<span class="emphasis">nameservers</span>.
</p>
<p>
In a network, hosts are identified by their <span class="emphasis">IP address</span> (Internet
Protocol address). Such an address is a combination of four numbers
between 0 and 255. Well, at least that is how we perceive it. In
reality, such an IP address consists of 32 bits (ones and zeros). Let's
view an example:
</p>
<a name="book_part1_chap3__chap3_pre9"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.9: Example of an IP address</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
IP Address (numbers): 192.168.0.2
IP Address (bits): 11000000 10101000 00000000 00000010
-------- -------- -------- --------
192 168 0 2
</pre></td></tr>
</table>
<p>
Such an IP address is unique to a host as far as all accessible networks are
concerned (i.e. every host that you are able to reach must have a unique IP
address). In order to distinguish between hosts inside and outside a
network, the IP address is divided in two parts: the
<span class="emphasis">network</span> part and the <span class="emphasis">host</span> part.
</p>
<p>
The separation is written down with the <span class="emphasis">netmask</span>, a collection of
ones followed by a collection of zeros. The part of the IP that can be
mapped on the ones is the network-part, the other one is the host-part.
As usual, the netmask can be written down as an IP-address.
</p>
<a name="book_part1_chap3__chap3_pre10"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.10: Example of network/host separation</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
IP-address: 192 168 0 2
11000000 10101000 00000000 00000010
Netmask: 11111111 11111111 11111111 00000000
255 255 255 0
+--------------------------+--------+
Network Host
</pre></td></tr>
</table>
<p>
In other words, 192.168.0.14 is still part of our example network, but
192.168.1.2 is not.
</p>
<p>
The <span class="emphasis">broadcast</span> address is an IP-address with the same network-part
as your network, but with only ones as host-part. Every host on your
network listens to this IP address. It is truly meant for broadcasting
packets.
</p>
<a name="book_part1_chap3__chap3_pre11"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.11: Broadcast address</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
IP-address: 192 168 0 2
11000000 10101000 00000000 00000010
Broadcast: 11000000 10101000 00000000 11111111
192 168 0 255
+--------------------------+--------+
Network Host
</pre></td></tr>
</table>
<p>
To be able to surf on the internet, you must know which host shares the
Internet connection. This host is called the <span class="emphasis">gateway</span>. Since it is
a regular host, it has a regular IP address (for instance 192.168.0.1).
</p>
<p>
We previously stated that every host has its own IP address. To be able
to reach this host by a name (instead of an IP address) you need a
service that translates a name (such as <span class="emphasis">dev.gentoo.org</span>) to an IP
address (such as <span class="emphasis">64.5.62.82</span>). Such a service is called a name
service. To use such a service, you must define the necessary <span class="emphasis">name
servers</span> in <span class="path" dir="ltr">/etc/resolv.conf</span>.
</p>
<p>
In some cases, your gateway also serves as nameserver. Otherwise you
will have to enter the nameservers provided by your ISP.
</p>
<p>
To summarise, you will need the following information before continuing:
</p>
<table class="ntable">
<tr>
<td class="infohead"><b>Network Item</b></td>
<td class="infohead"><b>Example</b></td>
</tr>
<tr>
<td class="tableinfo">Your IP address</td>
<td class="tableinfo">192.168.0.2</td>
</tr>
<tr>
<td class="tableinfo">Netmask</td>
<td class="tableinfo">255.255.255.0</td>
</tr>
<tr>
<td class="tableinfo">Broadcast</td>
<td class="tableinfo">192.168.0.255</td>
</tr>
<tr>
<td class="tableinfo">Gateway</td>
<td class="tableinfo">192.168.0.1</td>
</tr>
<tr>
<td class="tableinfo">Nameserver(s)</td>
<td class="tableinfo">195.130.130.5, 195.130.130.133</td>
</tr>
</table>
<p class="secthead"><a name="ifconfig_route"></a><a name="book_part1_chap3__chap3_sect5">Using ifconfig and route</a></p>
<p>
Setting up your network consists of three steps. First we assign
ourselves an IP address using <span class="code" dir="ltr">ifconfig</span>. Then we set up routing to
the gateway using <span class="code" dir="ltr">route</span>. Then we finish up by placing the
nameserver IPs in <span class="path" dir="ltr">/etc/resolv.conf</span>.
</p>
<p>
To assign an IP address, you will need your IP address, broadcast
address and netmask. Then execute the following command, substituting
<span class="code" dir="ltr">${IP_ADDR}</span> with your IP address, <span class="code" dir="ltr">${BROADCAST}</span> with your
broadcast address and <span class="code" dir="ltr">${NETMASK}</span> with your netmask:
</p>
<a name="book_part1_chap3__chap3_pre12"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.12: Using ifconfig</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">ifconfig eth0 ${IP_ADDR} broadcast ${BROADCAST} netmask ${NETMASK} up</span>
</pre></td></tr>
</table>
<p>
Now set up routing using <span class="code" dir="ltr">route</span>. Substitute <span class="code" dir="ltr">${GATEWAY}</span> with
your gateway IP address:
</p>
<a name="book_part1_chap3__chap3_pre13"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.13: Using route</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">route add default gw ${GATEWAY}</span>
</pre></td></tr>
</table>
<p>
Now open <span class="path" dir="ltr">/etc/resolv.conf</span> with your favorite editor (in our
example, we use <span class="code" dir="ltr">nano</span>):
</p>
<a name="book_part1_chap3__chap3_pre14"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.14: Creating /etc/resolv.conf</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">nano -w /etc/resolv.conf</span>
</pre></td></tr>
</table>
<p>
Now fill in your nameserver(s) using the following as a template. Make
sure you substitute <span class="code" dir="ltr">${NAMESERVER1}</span> and <span class="code" dir="ltr">${NAMESERVER2}</span> with
the appropriate nameserver addresses:
</p>
<a name="book_part1_chap3__chap3_pre15"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.15: /etc/resolv.conf template</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
nameserver ${NAMESERVER1}
nameserver ${NAMESERVER2}
</pre></td></tr>
</table>
<p>
That's it. Now test your network by pinging some Internet server (like
<a href="http://www.google.com">Google</a>). If this works,
congratulations then. You are now ready to install Gentoo. Continue with <a href="#book_part1_chap4">Preparing the Disks</a>.
</p>
<a name="book_part1_chap4"></a><h3>4. Preparing the Disks</h3>
<p class="chaphead"><a name="book_part1_chap4__chap1"></a><span class="chapnum">4.a. </span>Introduction to Block Devices</p>
<p class="secthead"><a name="blockdevicesdesc"></a><a name="book_part1_chap4__chap1_sect1">Block Devices</a></p>
<p>
We'll take a good look at disk-oriented aspects of Gentoo Linux
and Linux in general, including Linux filesystems, partitions and block devices.
Then, once you're familiar with the ins and outs of disks and filesystems,
you'll be guided through the process of setting up partitions and filesystems
for your Gentoo Linux installation.
</p>
<p>
To begin, we'll introduce <span class="emphasis">block devices</span>. The most famous block device is
probably the one that represents the first drive in a Linux system, namely
<span class="path" dir="ltr">/dev/sda</span>. SCSI and Serial ATA drives are both labeled
<span class="path" dir="ltr">/dev/sd*</span>; even IDE drives are labeled <span class="path" dir="ltr">/dev/sd*</span> with
the new libata framework in the kernel. If you're using the old device
framework, then your first IDE drive is <span class="path" dir="ltr">/dev/hda</span>.
</p>
<p>
The block devices above represent an abstract interface to the disk. User
programs can use these block devices to interact with your disk without worrying
about whether your drives are IDE, SCSI or something else. The program can
simply address the storage on the disk as a bunch of contiguous,
randomly-accessible 512-byte blocks.
</p>
<p class="secthead"><a name="book_part1_chap4__chap1_sect2">Partitions</a></p>
<p>
Although it is theoretically possible to use a full disk to house your Linux
system, this is almost never done in practice. Instead, full disk block devices
are split up in smaller, more manageable block devices. On x86
systems, these are called <span class="emphasis">partitions</span>. There are currently two standard
partitioning technologies in use: MBR and GPT.
</p>
<p>
The <span class="emphasis">MBR (Master Boot Record)</span> setup uses 32-bit identifiers for
the start sector and length of the partitions, and supports three partition
types: <span class="emphasis">primary</span>,
<span class="emphasis">extended</span> and <span class="emphasis">logical</span>. Primary partitions have their information
stored in the master boot record itself - a very small (usually 512 bytes)
location at the very beginning of a disk. Due to this small space, only four
primary partitions are supported (for instance, <span class="path" dir="ltr">/dev/sda1</span> to
<span class="path" dir="ltr">/dev/sda4</span>).
</p>
<p>
To support more partitions, one of the primary partitions can be marked as an
extended partition. This partition can then contain logical partitions
(partitions within a partition).
</p>
<p>
Each partition is limited to 2 TB in size (due to the 32-bit identifiers).
Also, the MBR setup does not provide any backup-MBR, so if an application
or user overwrites the MBR, all partition information is lost.
</p>
<p>
The <span class="emphasis">GPT (GUID Partition table)</span> setup uses 64-bit identifiers for
the partitions. The location in which it stores the partition information
is also much bigger than the 512 bytes of an MBR, and there is no limit on
the amount of partitions. Also the size of a partition is bounded by a much
greater limit (almost 8 ZB - yes, zettabytes).
</p>
<p>
When a system's software interface between the operating system and firmware
is UEFI (instead of BIOS), GPT is almost mandatory as compatibility issues will
arise with MBR here.
</p>
<p>
GPT also has the advantage that it has a backup GPT at the end of the disk,
which can be used to recover damage of the primary GPT at the beginning. GPT
also carries CRC32 checksums to detect errors in the header and partition
tables.
</p>
<p class="secthead"><a name="gpt_or_mbr"></a><a name="book_part1_chap4__chap1_sect3">So, GPT or MBR?</a></p>
<p>
From the description above, one might think that using GPT should always be the
recommended approach. But there are a few caveats with this.
</p>
<p>
Using GPT on a BIOS-based computer works, but you cannot dual-boot then with a
Microsoft Windows operating system. The reason is that Microsoft Windows will
boot in EFI mode if it detects a GPT partition label.
</p>
<p>
Some buggy BIOSes or EFIs configured to boot in BIOS/CSM/legacy mode might also
have problems with booting from GPT labeled disks. If that is the case, you
might be able to work around the problem by adding the boot/active flag on the
protective MBR partition which has to be done through <span class="code" dir="ltr">fdisk</span>
(<span class="code" dir="ltr">parted</span> understands the GPT tables and would not show the protective
MBR partition):
</p>
<a name="book_part1_chap4__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: Enabling boot flag on protective MBR</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">fdisk /dev/sda</span>
WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util fdisk
doesn't support GPT. Use GNU Parted.
Command (m for help): <span class="code-input">a</span>
Partition number (1-4): <span class="code-input">1</span>
Command (m for help): <span class="code-input">w</span>
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part1_chap4__chap1_sect4">Advanced Storage</a></p>
<p>
The x86 Installation CDs provide support for LVM2.
LVM2 increases the flexibility offered by your partitioning setup.
During the installation instructions, we will focus on "regular" partitions,
but it is still good to know LVM2 is supported as well.
</p>
<p class="chaphead"><a name="book_part1_chap4__chap2"></a><span class="chapnum">4.b. </span>Designing a Partitioning Scheme</p>
<p class="secthead"><a name="book_part1_chap4__chap2_sect1">Default Partitioning Scheme</a></p>
<p>
If you are not interested in drawing up a partitioning scheme for your system,
you can use the partitioning scheme we use throughout this book.
</p>
<table class="ntable">
<tr>
<td class="infohead"><b>Partition</b></td>
<td class="infohead"><b>Filesystem</b></td>
<td class="infohead"><b>Size</b></td>
<td class="infohead"><b>Description</b></td>
</tr>
<tr>
<td class="tableinfo"><span class="path" dir="ltr">/dev/sda1</span></td>
<td class="tableinfo">(bootloader)</td>
<td class="tableinfo">2M</td>
<td class="tableinfo">BIOS boot partition</td>
</tr>
<tr>
<td class="tableinfo"><span class="path" dir="ltr">/dev/sda2</span></td>
<td class="tableinfo">ext2</td>
<td class="tableinfo">128M</td>
<td class="tableinfo">Boot partition</td>
</tr>
<tr>
<td class="tableinfo"><span class="path" dir="ltr">/dev/sda3</span></td>
<td class="tableinfo">(swap)</td>
<td class="tableinfo">512M or higher</td>
<td class="tableinfo">Swap partition</td>
</tr>
<tr>
<td class="tableinfo"><span class="path" dir="ltr">/dev/sda4</span></td>
<td class="tableinfo">ext4</td>
<td class="tableinfo">Rest of the disk</td>
<td class="tableinfo">Root partition</td>
</tr>
</table>
<p>
If you are interested in knowing how big a partition should be, or even how
many partitions you need, read on. Otherwise continue now with partitioning
your disk by reading <a href="#parted">Default: Using parted to Partition
your Disk</a> (or <a href="#fdisk">Alternative: Using fdisk to Partition
your Disk</a>). Both are partitioning tools, <span class="code" dir="ltr">fdisk</span> is well known and stable,
<span class="code" dir="ltr">parted</span> is a bit more recent but supports partitions larger than
2TB).
</p>
<p class="secthead"><a name="book_part1_chap4__chap2_sect2">How Many and How Big?</a></p>
<p>
The number of partitions is highly dependent on your environment. For instance,
if you have lots of users, you will most likely want to have your
<span class="path" dir="ltr">/home</span> separate as it increases security and makes backups easier.
If you are installing Gentoo to perform as a mailserver, your
<span class="path" dir="ltr">/var</span> should be separate as all mails are stored inside
<span class="path" dir="ltr">/var</span>. A good choice of filesystem will then maximise your
performance. Gameservers will have a separate <span class="path" dir="ltr">/opt</span> as most gaming
servers are installed there. The reason is similar for <span class="path" dir="ltr">/home</span>:
security and backups. You will definitely want to keep <span class="path" dir="ltr">/usr</span> big:
not only will it contain the majority of applications, the Portage tree alone
takes around 500 Mbyte excluding the various sources that are stored in it.
</p>
<p>
As you can see, it very much depends on what you want to achieve. Separate
partitions or volumes have the following advantages:
</p>
<ul>
<li>
You can choose the best performing filesystem for each partition or volume
</li>
<li>
Your entire system cannot run out of free space if one defunct tool is
continuously writing files to a partition or volume
</li>
<li>
If necessary, file system checks are reduced in time, as multiple checks can
be done in parallel (although this advantage is more with multiple disks than
it is with multiple partitions)
</li>
<li>
Security can be enhanced by mounting some partitions or volumes read-only,
nosuid (setuid bits are ignored), noexec (executable bits are ignored) etc.
</li>
</ul>
<p>
However, multiple partitions have disadvantages as well. If not configured
properly, you will have a system with lots of free space on one partition and
none on another. Another nuisance is that separate partitions - especially
for important mountpoints like <span class="path" dir="ltr">/usr</span> or <span class="path" dir="ltr">/var</span> - often
require the administrator to boot with an initramfs to mount the partition
before other boot scripts start. This isn't always the case though, so your
results may vary.
</p>
<p>
There is also a 15-partition limit for SCSI and SATA unless you use GPT
labels.
</p>
<p class="secthead"><a name="book_part1_chap4__chap2_sect3">What about swap space?</a></p>
<p>
There is no perfect value for the swap partition. The purpose of swap space is
to provide disk storage to the kernel when internal memory (RAM) is under
pressure. A swap space allows for the kernel to move memory pages that are
not likely to be accessed soon to disk (swap or page-out), freeing memory. Of
course, if that memory is suddenly needed, these pages need to be put back in
memory (page-in) which will take a while (as disks are very slow compared to
internal memory).
</p>
<p>
If you are not going to run memory intensive applications or you have lots of
memory available, then you probably do not need much swap space. However, swap
space is also used to store the entire memory in case of hibernation. If you
plan on using hibernation, you will need a bigger swap space, often at least
the amount of memory you have in your system.
</p>
<p class="secthead"><a name="book_part1_chap4__chap2_sect4">What is the BIOS boot partition?</a></p>
<p>
A BIOS boot partition is a very small (1 to 2 MB) partition in which
bootloaders like GRUB2 can put additional data that doesn't fit in the
allocated storage (a few hundred bytes in case of MBR) and cannot place
elsewhere.
</p>
<p>
Such partitions are not always necessary, but considering the low space
consumption and the difficulties we would have with documenting the plethora
of partitioning differences otherwise, it is recommended to create it in
either case.
</p>
<p>
For completeness, we can say that the BIOS boot partition is needed when
GPT partition layout is used with GRUB2, or when the MBR partition layout
is used with GRUB2 when the first partition starts earlier than the 1 MB
location on the disk.
</p>
<p class="chaphead"><a name="parted"></a><a name="book_part1_chap4__chap3"></a><span class="chapnum">4.c. </span>Default: Using parted to Partition your Disk</p>
<p>
In this chapter, we guide you through the creation of the example partition
layout mentioned earlier in the instructions, but repeat here again for
your convenience:
</p>
<table class="ntable">
<tr>
<td class="infohead"><b>Partition</b></td>
<td class="infohead"><b>Description</b></td>
</tr>
<tr>
<td class="tableinfo"><span class="path" dir="ltr">/dev/sda1</span></td>
<td class="tableinfo">BIOS boot partition</td>
</tr>
<tr>
<td class="tableinfo"><span class="path" dir="ltr">/dev/sda2</span></td>
<td class="tableinfo">Boot partition</td>
</tr>
<tr>
<td class="tableinfo"><span class="path" dir="ltr">/dev/sda3</span></td>
<td class="tableinfo">Swap partition</td>
</tr>
<tr>
<td class="tableinfo"><span class="path" dir="ltr">/dev/sda4</span></td>
<td class="tableinfo">Root partition</td>
</tr>
</table>
<p>
Change your partition layout according to your own preference.
</p>
<p class="secthead"><a name="book_part1_chap4__chap3_sect2">Viewing the Current Partition Layout</a></p>
<p>
The <span class="code" dir="ltr">parted</span> application offers a simple interface for partitioning your
disks and supports very large partitions (more than 2 TB). Fire up
<span class="code" dir="ltr">parted</span> on your disk (in our example, we use <span class="path" dir="ltr">/dev/sda</span>).
We will ask <span class="code" dir="ltr">parted</span> to use optimum alignment:
</p>
<a name="book_part1_chap4__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: Starting parted</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">parted -a optimal /dev/sda</span>
GNU Parted 2.3
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
</pre></td></tr>
</table>
<p>
Alignment means that partitions are started on well-known boundaries within
the disk, ensuring that operations on the disk from the operating system level
(retrieve pages from the disk) use the least amount of internal disk
operations. Misaligned partitions might require the disk to fetch two pages
instead of one even if the operating system asked for a single page.
</p>
<p>
To find out about all options supported by <span class="code" dir="ltr">parted</span>, type <span class="code" dir="ltr">help</span> and
press return.
</p>
<p class="secthead"><a name="book_part1_chap4__chap3_sect3">Setting the GPT Label</a></p>
<p>
Most disks on x86/amd64 are prepared using an <span class="emphasis">msdos</span> label. Using
<span class="code" dir="ltr">parted</span>, we can put a GPT label on the disk using <span class="code" dir="ltr">mklabel gpt</span>:
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffbbbb"><p class="note"><b>Warning: </b>
Changing the partition type will remove all partitions from your disk. All data
on the disk will be lost.
</p></td></tr></table>
<a name="book_part1_chap4__chap3_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.2: Setting the GPT label</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
(parted) <span class="code-input">mklabel gpt</span>
</pre></td></tr>
</table>
<p>
If you want the disk to have MBR layout, use <span class="code" dir="ltr">mklabel msdos</span>.
</p>
<p class="secthead"><a name="book_part1_chap4__chap3_sect4">Removing all Partitions</a></p>
<p>
If this isn't done yet (for instance through the <span class="code" dir="ltr">mklabel</span> operation
earlier, or because the disk is a freshly formatted one), we will first
remove all existing partitions from the disk. Type <span class="code" dir="ltr">print</span> to view the
current partitions, and <span class="code" dir="ltr">rm &lt;number&gt;</span> where &lt;number&gt; is the
partition you want to remove.
</p>
<a name="book_part1_chap4__chap3_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.3: Removing a partition from the disk</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
(parted) <span class="code-input">rm 2</span>
</pre></td></tr>
</table>
<p>
Do the same for all other partitions that you don't need. However, make sure you
do not make any mistakes here - <span class="code" dir="ltr">parted</span> executes the changes immediately
(unlike <span class="code" dir="ltr">fdisk</span> which stages them, allowing a user to "undo" his changes
before saving or exiting <span class="code" dir="ltr">fdisk</span>).
</p>
<p class="secthead"><a name="book_part1_chap4__chap3_sect5">Creating the Partitions</a></p>
<p>
Now let's create the partitions we mentioned earlier. Creating partitions with
<span class="code" dir="ltr">parted</span> isn't very difficult - all we need to do is inform <span class="code" dir="ltr">parted</span>
about the following settings:
</p>
<ul>
<li>
The <span class="emphasis">partition type</span> to use. This usually is <span class="emphasis">primary</span>.
If you use the <span class="emphasis">msdos</span> partition label, keep in mind that you can have
no more than 4 primary partitions. If you need more than 4 partitions, make
a partition <span class="emphasis">extended</span> and create <span class="emphasis">logical</span> partitions inside it.
</li>
<li>
The start location of a partition (which can be expressed in MB, GB, ...)
</li>
<li>
The end location of the partition (which can be expressed in MB, GB, ...)
</li>
</ul>
<p>
First, we tell <span class="code" dir="ltr">parted</span> that the size unit we work with is megabytes
(actually mebibytes, abbreviated as MiB which is the "standard" notation, but
we will use MB in the text throughout as it is much more common):
</p>
<a name="book_part1_chap4__chap3_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.4: Using MiB units</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
(parted) <span class="code-input">unit mib</span>
</pre></td></tr>
</table>
<p>
Now create a 2 MB partition that will be used by the GRUB2 bootloader later.
We use the <span class="code" dir="ltr">mkpart</span> command for this, and inform <span class="code" dir="ltr">parted</span> to start
from 1 MB and end at 3 MB (creating a partition of 2 MB in size).
</p>
<a name="book_part1_chap4__chap3_pre5"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.5: Creating a 2 MB partition</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
(parted) <span class="code-input">mkpart primary 1 3</span>
(parted) <span class="code-input">name 1 grub</span>
(parted) <span class="code-input">set 1 bios_grub on</span>
(parted) <span class="code-input">print</span>
Model: Virtio Block Device (virtblk)
Disk /dev/sda: 20480MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 1.00MiB 3.00MiB 2.00MiB grub bios_grub
</pre></td></tr>
</table>
<p>
Do the same for the boot partition (128 MB), swap partition (in the example,
512 MB) and the root partition that spans the remaining disk (for which the
end location is marked as <span class="code" dir="ltr">-1</span>, meaning the end of the disk minus one MB,
which is the farthest a partition can go).
</p>
<a name="book_part1_chap4__chap3_pre6"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.6: Creating other partitions</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
(parted) <span class="code-input">mkpart primary 3 131</span>
(parted) <span class="code-input">name 2 boot</span>
(parted) <span class="code-input">mkpart primary 131 643</span>
(parted) <span class="code-input">name 3 swap</span>
(parted) <span class="code-input">mkpart primary 643 -1</span>
(parted) <span class="code-input">name 4 rootfs</span>
</pre></td></tr>
</table>
<p>
The end result looks like so:
</p>
<a name="book_part1_chap4__chap3_pre7"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.7: Viewing the current partition layout</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
(parted) <span class="code-input">print</span>
Model: Virtio Block Device (virtblk)
Disk /dev/sda: 20480MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 1.00MiB 3.00MiB 2.00MiB grub bios_grub
2 3.00MiB 131MiB 128MiB boot
3 131MiB 643MiB 512MiB swap
4 643MiB 20479MiB 19836MiB rootfs
</pre></td></tr>
</table>
<p>
When you are satisfied, use the <span class="code" dir="ltr">quit</span> command to exit <span class="code" dir="ltr">parted</span>.
</p>
<p class="chaphead"><a name="fdisk"></a><a name="book_part1_chap4__chap4"></a><span class="chapnum">4.d. </span>Alternative: Using fdisk to Partition your Disk</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffffbb"><p class="note"><b>Important: </b>
If your environment will deal with partitions larger than 2 TB, please
use the <a href="#parted">Default: Using parted to Partition your Disk</a>
instructions instead. <span class="code" dir="ltr">fdisk</span> is not able to deal with larger
partitions. Fdisk will also use the MBR partition layout. Alternative fdisk
applications, like gdisk (which Gentoo provides through the gptfdisk package)
exist that do support GPT, but might not be included on the Gentoo installation
media.
</p></td></tr></table>
<p>
The following parts explain how to create the example partition layout
using <span class="code" dir="ltr">fdisk</span>. The example partition layout was mentioned earlier:
</p>
<table class="ntable">
<tr>
<td class="infohead"><b>Partition</b></td>
<td class="infohead"><b>Description</b></td>
</tr>
<tr>
<td class="tableinfo"><span class="path" dir="ltr">/dev/sda1</span></td>
<td class="tableinfo">BIOS boot partition</td>
</tr>
<tr>
<td class="tableinfo"><span class="path" dir="ltr">/dev/sda2</span></td>
<td class="tableinfo">Boot partition</td>
</tr>
<tr>
<td class="tableinfo"><span class="path" dir="ltr">/dev/sda3</span></td>
<td class="tableinfo">Swap partition</td>
</tr>
<tr>
<td class="tableinfo"><span class="path" dir="ltr">/dev/sda4</span></td>
<td class="tableinfo">Root partition</td>
</tr>
</table>
<p>
Change your partition layout according to your own preference.
</p>
<p class="secthead"><a name="book_part1_chap4__chap4_sect2">Viewing the Current Partition Layout</a></p>
<p>
<span class="code" dir="ltr">fdisk</span> is a popular and powerful tool to split your disk into partitions.
Fire up <span class="code" dir="ltr">fdisk</span> on your disk (in our example, we use
<span class="path" dir="ltr">/dev/sda</span>):
</p>
<a name="book_part1_chap4__chap4_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.1: Starting fdisk</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">fdisk /dev/sda</span>
</pre></td></tr>
</table>
<p>
Once in <span class="code" dir="ltr">fdisk</span>, you'll be greeted with a prompt that looks like this:
</p>
<a name="book_part1_chap4__chap4_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.2: fdisk prompt</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
Command (m for help):
</pre></td></tr>
</table>
<p>
Type <span class="code" dir="ltr">p</span> to display your disk's current partition configuration:
</p>
<a name="book_part1_chap4__chap4_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.3: An example partition configuration</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
Command (m for help): <span class="code-input">p</span>
Disk /dev/sda: 240 heads, 63 sectors, 2184 cylinders
Units = cylinders of 15120 * 512 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 14 105808+ 83 Linux
/dev/sda2 15 49 264600 82 Linux swap
/dev/sda3 50 70 158760 83 Linux
/dev/sda4 71 2184 15981840 5 Extended
/dev/sda5 71 209 1050808+ 83 Linux
/dev/sda6 210 348 1050808+ 83 Linux
/dev/sda7 349 626 2101648+ 83 Linux
/dev/sda8 627 904 2101648+ 83 Linux
/dev/sda9 905 2184 9676768+ 83 Linux
Command (m for help):
</pre></td></tr>
</table>
<p>
This particular disk is configured to house seven Linux filesystems (each with
a corresponding partition listed as "Linux") as well as a swap partition
(listed as "Linux swap").
</p>
<p class="secthead"><a name="book_part1_chap4__chap4_sect3">Removing all Partitions</a></p>
<p>
We will first remove all existing partitions from the disk. Type <span class="code" dir="ltr">d</span> to
delete a partition. For instance, to delete an existing <span class="path" dir="ltr">/dev/sda1</span>:
</p>
<a name="book_part1_chap4__chap4_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.4: Deleting a partition</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
Command (m for help): <span class="code-input">d</span>
Partition number (1-4): <span class="code-input">1</span>
</pre></td></tr>
</table>
<p>
The partition has been scheduled for deletion. It will no longer show up if you
type <span class="code" dir="ltr">p</span>, but it will not be erased until your changes have been saved. If
you made a mistake and want to abort without saving your changes, type <span class="code" dir="ltr">q</span>
immediately and hit enter and your partition will not be deleted.
</p>
<p>
Now, assuming that you do indeed want to wipe out all the partitions on your
system, repeatedly type <span class="code" dir="ltr">p</span> to print out a partition listing and then type
<span class="code" dir="ltr">d</span> and the number of the partition to delete it. Eventually, you'll end
up with a partition table with nothing in it:
</p>
<a name="book_part1_chap4__chap4_pre5"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.5: An empty partition table</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
Disk /dev/sda: 30.0 GB, 30005821440 bytes
240 heads, 63 sectors/track, 3876 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes
Device Boot Start End Blocks Id System
Command (m for help):
</pre></td></tr>
</table>
<p>
Now that the in-memory partition table is empty, we're ready to create the
partitions. We will use a default partitioning scheme as discussed previously.
Of course, don't follow these instructions to the letter if you don't want the
same partitioning scheme!
</p>
<p class="secthead"><a name="book_part1_chap4__chap4_sect4">Creating the BIOS Boot Partition</a></p>
<p>
We first create a very small BIOS boot partition. Type <span class="code" dir="ltr">n</span> to create a new
partition, then <span class="code" dir="ltr">p</span> to select a primary partition, followed by <span class="code" dir="ltr">1</span> to
select the first primary partition. When prompted for the first sector, make sure
it starts from <span class="code" dir="ltr">2048</span> (which is needed for the boot loader) and hit enter. When
prompted for the last sector, type <span class="code" dir="ltr">+2M</span> to create a partition 2 Mbyte
in size:
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
The start from sector 2048 is a fail-safe in case the boot loader does not
detect this partition as being available for its use.
</p></td></tr></table>
<a name="book_part1_chap4__chap4_pre6"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.6: Creating the BIOS boot partition</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
Command (m for help): <span class="code-input">n</span>
Command action
e extended
p primary partition (1-4)
<span class="code-input">p</span>
Partition number (1-4): <span class="code-input">1</span>
First sector (64-10486533532, default 64): <span class="code-input">2048</span>
Last sector, +sectors +size{M,K,G} (4096-10486533532, default 10486533532): <span class="code-input">+2M</span>
</pre></td></tr>
</table>
<p>
Mark the partition for EFI purposes:
</p>
<a name="book_part1_chap4__chap4_pre7"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.7: Marking the partition for EFI purposes</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
Command (m for help): <span class="code-input">t</span>
Selected partition 1
Hex code (type L to list codes): <span class="code-input">ef</span>
Changed system type of partition 1 to ef (EFI (FAT-12/16/32))
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part1_chap4__chap4_sect5">Creating the Boot Partition</a></p>
<p>
We now create a small boot partition. Type <span class="code" dir="ltr">n</span> to create a new partition,
then <span class="code" dir="ltr">p</span> to select a primary partition, followed by <span class="code" dir="ltr">2</span> to select the
second primary partition. When prompted for the first sector, accept the default
by hitting enter. When prompted for the last sector, type <span class="code" dir="ltr">+128M</span> to create a
partition 128 Mbyte in size:
</p>
<a name="book_part1_chap4__chap4_pre8"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.8: Creating the boot partition</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
Command (m for help): <span class="code-input">n</span>
Command action
e extended
p primary partition (1-4)
<span class="code-input">p</span>
Partition number (1-4): <span class="code-input">2</span>
First sector (5198-10486533532, default 5198): <span class="code-comment">(Hit enter)</span>
Last sector, +sectors +size{M,K,G} (4096-10486533532, default 10486533532): <span class="code-input">+128M</span>
</pre></td></tr>
</table>
<p>
Now, when you type <span class="code" dir="ltr">p</span>, you should see the following partition printout:
</p>
<a name="book_part1_chap4__chap4_pre9"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.9: Created boot partition</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
Command (m for help): <span class="code-input">p</span>
Disk /dev/sda: 30.0 GB, 30005821440 bytes
240 heads, 63 sectors/track, 3876 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 3 5198+ ef EFI (FAT-12/16/32)
/dev/sda2 3 14 105808+ 83 Linux
</pre></td></tr>
</table>
<p>
We need to make this partition bootable. Type <span class="code" dir="ltr">a</span> to toggle the bootable
flag on a partition and select <span class="code" dir="ltr">2</span>. If you press <span class="code" dir="ltr">p</span> again, you will
notice that an <span class="emphasis">*</span> is placed in the "Boot" column.
</p>
<p class="secthead"><a name="book_part1_chap4__chap4_sect6">Creating the Swap Partition</a></p>
<p>
Let's now create the swap partition. To do this, type <span class="code" dir="ltr">n</span> to create a new
partition, then <span class="code" dir="ltr">p</span> to tell fdisk that you want a primary partition. Then
type <span class="code" dir="ltr">3</span> to create the third primary partition, <span class="path" dir="ltr">/dev/sda3</span> in
our case. When prompted for the first sector, hit enter. When prompted for
the last sector, type <span class="code" dir="ltr">+512M</span> (or any other size you need for the swap
space) to create a partition 512MB in size.
</p>
<p>
After you've done this, type <span class="code" dir="ltr">t</span> to set the partition type, <span class="code" dir="ltr">3</span> to select
the partition you just created and then type in <span class="code" dir="ltr">82</span> to set the partition
type to "Linux Swap".
</p>
<p class="secthead"><a name="book_part1_chap4__chap4_sect7">Creating the Root Partition</a></p>
<p>
Finally, let's create the root partition. To do this, type <span class="code" dir="ltr">n</span> to create a
new partition, then <span class="code" dir="ltr">p</span> to tell fdisk that you want a primary partition.
Then type <span class="code" dir="ltr">4</span> to create the fourth primary partition, <span class="path" dir="ltr">/dev/sda4</span>
in our case. When prompted for the first sector, hit enter. When prompted for
the last sector, hit enter to create a partition that takes up the rest of the
remaining space on your disk. After completing these steps, typing <span class="code" dir="ltr">p</span>
should display a partition table that looks similar to this:
</p>
<a name="book_part1_chap4__chap4_pre10"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.10: Partition listing after creating the root partition</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
Command (m for help): <span class="code-input">p</span>
Disk /dev/sda: 30.0 GB, 30005821440 bytes
240 heads, 63 sectors/track, 3876 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 3 5198+ ef EFI (FAT-12/16/32)
/dev/sda2 * 3 14 105808+ 83 Linux
/dev/sda3 15 81 506520 82 Linux swap
/dev/sda4 82 3876 28690200 83 Linux
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part1_chap4__chap4_sect8">Saving the Partition Layout</a></p>
<p>
To save the partition layout and exit <span class="code" dir="ltr">fdisk</span>, type <span class="code" dir="ltr">w</span>.
</p>
<a name="book_part1_chap4__chap4_pre11"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.11: Save and exit fdisk</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
Command (m for help): <span class="code-input">w</span>
</pre></td></tr>
</table>
<p>
Now that your partitions are created, you can continue with <a href="#filesystems">Creating Filesystems</a>.
</p>
<p class="chaphead"><a name="filesystems"></a><a name="book_part1_chap4__chap5"></a><span class="chapnum">4.e. </span>Creating Filesystems</p>
<p class="secthead"><a name="book_part1_chap4__chap5_sect1">Introduction</a></p>
<p>
Now that your partitions are created, it is time to place a filesystem on them.
If you don't care about what filesystem to choose and are happy with what we use
as default in this handbook, continue with <a href="#filesystems-apply">Applying a Filesystem to a Partition</a>.
Otherwise read on to learn about the available filesystems...
</p>
<p class="secthead"><a name="filesystemsdesc"></a><a name="book_part1_chap4__chap5_sect2">Filesystems</a></p>
<p>
The Linux kernel supports various filesystems. We'll explain ext2, ext3, ext4,
ReiserFS, XFS and JFS as these are the most commonly used filesystems on Linux
systems.
</p>
<p>
<b>ext2</b> is the tried and true Linux filesystem but doesn't have metadata
journaling, which means that routine ext2 filesystem checks at startup time can
be quite time-consuming. There is now quite a selection of newer-generation
journaled filesystems that can be checked for consistency very quickly and are
thus generally preferred over their non-journaled counterparts. Journaled
filesystems prevent long delays when you boot your system and your filesystem
happens to be in an inconsistent state.
</p>
<p>
<b>ext3</b> is the journaled version of the ext2 filesystem, providing metadata
journaling for fast recovery in addition to other enhanced journaling modes like
full data and ordered data journaling. It uses an HTree index that enables high
performance in almost all situations. In short, ext3 is a very good and
reliable filesystem.
</p>
<p>
<b>ext4</b> is a filesystem created as a fork of ext3 bringing new features,
performance improvements and removal of size limits with moderate changes
to the on-disk format. It can span volumes up to 1 EB and with maximum file
size of 16 TB. Instead of the classic ext2/3 bitmap block allocation ext4 uses
<a href="http://en.wikipedia.org/wiki/Extent_%28file_systems%29">extents</a>,
which improve large file performance and reduce fragmentation. Ext4 also provides
more sophisticated block allocation algorithms (delayed allocation and multiblock
allocation) giving the filesystem driver more ways to optimise the layout of data
on the disk. The ext4 filesystem is a compromise between production-grade code
stability and the desire to introduce extensions to an almost decade old
filesystem. Ext4 is the recommended all-purpose all-platform filesystem.
</p>
<p>
If you intend to install Gentoo on a small partition (less than 8GB), then you'll
need to tell ext2, ext3 or ext4 (if available) to reserve enough inodes when you
create the filesystem. The <span class="code" dir="ltr">mke2fs</span> application uses the "bytes-per-inode"
setting to calculate how many inodes a file system should have. By running
<span class="code" dir="ltr">mke2fs -T small /dev/&lt;device&gt;</span> (ext2) or <span class="code" dir="ltr">mke2fs -j -T small
/dev/&lt;device&gt;</span> (ext3/ext4) the number of inodes will generally
quadruple for a given file system as its "bytes-per-inode" reduces from
one every 16kB to one every 4kB. You can tune this even further by using
<span class="code" dir="ltr">mke2fs -i &lt;ratio&gt; /dev/&lt;device&gt;</span> (ext2) or <span class="code" dir="ltr">mke2fs -j
-i &lt;ratio&gt; /dev/&lt;device&gt;</span> (ext3/ext4).
</p>
<p>
<b>JFS</b> is IBM's high-performance journaling filesystem. JFS is a light,
fast and reliable B+tree-based filesystem with good performance in various
conditions.
</p>
<p>
<b>ReiserFS</b> is a B+tree-based journaled filesystem that has good overall
performance, especially when dealing with many tiny files at the cost of more
CPU cycles. ReiserFS appears to be less maintained than other filesystems.
</p>
<p>
<b>XFS</b> is a filesystem with metadata journaling which comes with a robust
feature-set and is optimized for scalability. XFS seems to be less forgiving to
various hardware problems.
</p>
<p class="secthead"><a name="filesystems-apply"></a><a name="book_part1_chap4__chap5_sect3">Applying a Filesystem to a Partition</a></p>
<p>
To create a filesystem on a partition or volume, there are tools available for
each possible filesystem:
</p>
<table class="ntable">
<tr>
<td class="infohead"><b>Filesystem</b></td>
<td class="infohead"><b>Creation Command</b></td>
</tr>
<tr>
<td class="tableinfo">ext2</td>
<td class="tableinfo"><span class="code" dir="ltr">mkfs.ext2</span></td>
</tr>
<tr>
<td class="tableinfo">ext3</td>
<td class="tableinfo"><span class="code" dir="ltr">mkfs.ext3</span></td>
</tr>
<tr>
<td class="tableinfo">ext4</td>
<td class="tableinfo"><span class="code" dir="ltr">mkfs.ext4</span></td>
</tr>
<tr>
<td class="tableinfo">reiserfs</td>
<td class="tableinfo"><span class="code" dir="ltr">mkreiserfs</span></td>
</tr>
<tr>
<td class="tableinfo">xfs</td>
<td class="tableinfo"><span class="code" dir="ltr">mkfs.xfs</span></td>
</tr>
<tr>
<td class="tableinfo">jfs</td>
<td class="tableinfo"><span class="code" dir="ltr">mkfs.jfs</span></td>
</tr>
</table>
<p>
For instance, to have the boot partition (<span class="path" dir="ltr">/dev/sda2</span> in our
example) in ext2 and the root partition (<span class="path" dir="ltr">/dev/sda4</span> in our example)
in ext4 (as in our example), you would use:
</p>
<a name="book_part1_chap4__chap5_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.1: Applying a filesystem on a partition</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">mkfs.ext2 /dev/sda2</span>
# <span class="code-input">mkfs.ext4 /dev/sda4</span>
</pre></td></tr>
</table>
<p>
Now create the filesystems on your newly created partitions (or logical
volumes).
</p>
<p class="secthead"><a name="book_part1_chap4__chap5_sect4">Activating the Swap Partition</a></p>
<p>
<span class="code" dir="ltr">mkswap</span> is the command that is used to initialize swap partitions:
</p>
<a name="book_part1_chap4__chap5_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.2: Creating a Swap signature</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">mkswap /dev/sda3</span>
</pre></td></tr>
</table>
<p>
To activate the swap partition, use <span class="code" dir="ltr">swapon</span>:
</p>
<a name="book_part1_chap4__chap5_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.3: Activating the swap partition</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">swapon /dev/sda3</span>
</pre></td></tr>
</table>
<p>
Create and activate the swap with the commands mentioned above.
</p>
<p class="chaphead"><a name="book_part1_chap4__chap6"></a><span class="chapnum">4.f. </span>Mounting</p>
<p>
Now that your partitions are initialized and are housing a filesystem, it is
time to mount those partitions. Use the <span class="code" dir="ltr">mount</span> command. Don't forget to
create the necessary mount directories for every partition you created. As an
example we mount the root and boot partition:
</p>
<a name="book_part1_chap4__chap6_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 6.1: Mounting partitions</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">mount /dev/sda4 /mnt/gentoo</span>
# <span class="code-input">mkdir /mnt/gentoo/boot</span>
# <span class="code-input">mount /dev/sda2 /mnt/gentoo/boot</span>
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
If you want your <span class="path" dir="ltr">/tmp</span> to reside on a separate partition, be sure to
change its permissions after mounting: <span class="code" dir="ltr">chmod 1777 /mnt/gentoo/tmp</span>. This
also holds for <span class="path" dir="ltr">/var/tmp</span>.
</p></td></tr></table>
<p>
We will also have to mount the proc filesystem (a virtual interface with the
kernel) on <span class="path" dir="ltr">/proc</span>. But first we will need to place our files on the partitions.
</p>
<p>
Continue with <a href="#book_part1_chap5">Installing the Gentoo
Installation Files</a>.
</p>
<a name="book_part1_chap5"></a><h3>5. Installing the Gentoo Installation Files</h3>
<p class="chaphead"><a name="book_part1_chap5__chap1"></a><span class="chapnum">5.a. </span>Installing a Stage Tarball</p>
<p class="secthead"><a name="book_part1_chap5__chap1_sect1">Setting the Date/Time Right</a></p>
<p>
Before you continue you need to check your date/time and update it. A
misconfigured clock may lead to strange results in the future!
</p>
<p>
To verify the current date/time, run <span class="code" dir="ltr">date</span>:
</p>
<a name="book_part1_chap5__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: Verifying the date/time</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">date</span>
Fri Mar 29 16:21:18 UTC 2005
</pre></td></tr>
</table>
<p>
If the date/time displayed is wrong, update it using the <span class="code" dir="ltr">date
MMDDhhmmYYYY</span> syntax (<b>M</b>onth, <b>D</b>ay, <b>h</b>our, <b>m</b>inute
and <b>Y</b>ear). At this stage, you should use UTC time. You will be able to
define your timezone later on. For instance, to set the date to March 29th,
16:21 in the year 2005:
</p>
<a name="book_part1_chap5__chap1_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.2: Setting the UTC date/time</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">date 032916212005</span>
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part1_chap5__chap1_sect2">Making your Choice</a></p>
<p>
The next step you need to perform is to install the <span class="emphasis">stage3</span> tarball onto
your system. The command <span class="code" dir="ltr">uname -m</span> can be used to help you decide which
stage file to download as it provides information on the architecture of your
system.
</p>
<p class="chaphead"><a name="book_part1_chap5__chap2"></a><span class="chapnum">5.b. </span>Using a Stage from the Internet</p>
<p class="secthead"><a name="book_part1_chap5__chap2_sect1">Downloading the Stage Tarball</a></p>
<p>
Go to the Gentoo mountpoint at which you mounted your filesystems
(most likely <span class="path" dir="ltr">/mnt/gentoo</span>):
</p>
<a name="book_part1_chap5__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: Going to the Gentoo mountpoint</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">cd /mnt/gentoo</span>
</pre></td></tr>
</table>
<p>
Depending on your installation medium, you have a couple of tools available to
download a stage. If you have <span class="code" dir="ltr">links</span> available, then you can immediately
surf to <a href="/main/en/mirrors.xml?style=printable">the Gentoo mirrorlist</a> and
choose a mirror close to you: type <span class="code" dir="ltr">links http://www.gentoo.org/main/en/mirrors.xml</span>
and press enter.
</p>
<p>
If you don't have <span class="code" dir="ltr">links</span> available you should have <span class="code" dir="ltr">lynx</span> at your
disposal. If you need to go through a proxy, export the <span class="code" dir="ltr">http_proxy</span> and
<span class="code" dir="ltr">ftp_proxy</span> variables:
</p>
<a name="book_part1_chap5__chap2_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.2: Setting proxy information for lynx</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">export http_proxy="http://proxy.server.com:port"</span>
# <span class="code-input">export ftp_proxy="http://proxy.server.com:port"</span>
</pre></td></tr>
</table>
<p>
We will now assume that you have <span class="code" dir="ltr">links</span> at your disposal.
</p>
<p>
Select a mirror closeby. Usually HTTP mirrors suffice, but other protocols are
available as well. Move to the <span class="path" dir="ltr">releases/x86/autobuilds/</span>
directory. There you should see all available stage files for your architecture
(they might be stored within subdirectories named after the individual
subarchitectures). Select one and press <span class="code" dir="ltr">D</span> to download. When you're
finished, press <span class="code" dir="ltr">Q</span> to quit the browser.
</p>
<p>
Most PC users should use the <b>stage3-i686-&lt;release&gt;.tar.bz2</b> stage3 archive. All
modern PCs are considered i686. If you use an old machine, you can check the
<a href="http://en.wikipedia.org/wiki/I686">list of i686-compatible
processors</a> on Wikipedia. Old processors such as the Pentium, K5, K6, or
Via C3 and similar require the more generic <b>x86</b> stage3. Processors older
than <b>i486</b> are not supported.
</p>
<a name="book_part1_chap5__chap2_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.3: Surfing to the mirror listing with links</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">links http://www.gentoo.org/main/en/mirrors.xml</span>
<span class="code-comment">(If you need proxy support with links:)</span>
# <span class="code-input">links -http-proxy proxy.server.com:8080 http://www.gentoo.org/main/en/mirrors.xml</span>
</pre></td></tr>
</table>
<p>
Make sure you download a <b>stage3</b> tarball - installations using a stage1
or stage2 tarball are not supported anymore (and in most cases, you will not
find stage1 or stage2 tarballs on our regular download mirrors anyway).
</p>
<p>
If you want to check the integrity of the downloaded stage tarball, use
<span class="code" dir="ltr">openssl</span> and compare the output with the checksums provided on the
mirror. The digests files provide several checksums, each taken with a different
algorithm. The recommended ones are SHA512 and Whirlpool.
</p>
<a name="book_part1_chap5__chap2_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.4: Calculating the integrity checksum of a stage tarball</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment">## Calculating the SHA512 checksum</span>
# <span class="code-input">openssl dgst -r -sha512 stage3-i686-&lt;release&gt;.tar.bz2</span>
<span class="code-comment">or</span>
# <span class="code-input">sha512sum stage3-i686-&lt;release&gt;.tar.bz2</span>
<span class="code-comment">## Calculating the Whirlpool checksum</span>
# <span class="code-input">openssl dgst -r -whirlpool stage3-i686-&lt;release&gt;.tar.bz2</span>
</pre></td></tr>
</table>
<p>
Then compare the output of these commands with the value registered in the
<span class="path" dir="ltr">.DIGESTS(.asc)</span> files that can be found on the mirrors as well. The values need to
match, otherwise the downloaded file might be corrupt (or the digests file is).
</p>
<p>
Just like with the ISO file, you can also verify the cryptographic signature of
the <span class="path" dir="ltr">.DIGESTS.asc</span> file using <span class="code" dir="ltr">gpg</span> to make sure the checksums
have not been tampered with:
</p>
<a name="book_part1_chap5__chap2_pre5"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.5: Validating the checksums using gpg</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">gpg --verify stage3-i686-&lt;release&gt;.tar.bz2.DIGESTS.asc</span>
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part1_chap5__chap2_sect2">Unpacking the Stage Tarball</a></p>
<p>
Now unpack your downloaded stage onto your system. We use <span class="code" dir="ltr">tar</span> to proceed
as it is the easiest method:
</p>
<a name="book_part1_chap5__chap2_pre6"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.6: Unpacking the stage</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">tar xvjpf stage3-*.tar.bz2</span>
</pre></td></tr>
</table>
<p>
Make sure that you use the same options (<span class="code" dir="ltr">xvjpf</span>). The <span class="code" dir="ltr">x</span> stands for
<span class="emphasis">Extract</span>, the <span class="code" dir="ltr">v</span> for <span class="emphasis">Verbose</span> to see what happens during the
extraction process (optional), the <span class="code" dir="ltr">j</span> for <span class="emphasis">Decompress with bzip2</span>,
the <span class="code" dir="ltr">p</span> for <span class="emphasis">Preserve permissions</span> and the <span class="code" dir="ltr">f</span> to denote that we
want to extract a file, not standard input.
</p>
<p>
Now that the stage is installed, continue with <a href="#compile_options">Configuring the Compile Options</a>.
</p>
<p class="chaphead"><a name="compile_options"></a><a name="book_part1_chap5__chap3"></a><span class="chapnum">5.c. </span>Configuring the Compile Options</p>
<p class="secthead"><a name="book_part1_chap5__chap3_sect1">Introduction</a></p>
<p>
To optimize Gentoo, you can set a couple of variables which impact Portage
behaviour. All those variables can be set as environment variables (using
<span class="code" dir="ltr">export</span>) but that isn't permanent. To keep your settings, Portage provides
you with <span class="path" dir="ltr">/etc/portage/make.conf</span>, a configuration file for Portage.
It is this file we will edit now.
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
A commented listing of all possible variables can be found in
<span class="path" dir="ltr">/mnt/gentoo/usr/share/portage/config/make.conf.example</span>. For a
successful Gentoo installation you'll only need to set the variables which are
mentioned beneath.
</p></td></tr></table>
<p>
Fire up your favorite editor (in this guide we use <span class="code" dir="ltr">nano</span>) so we can alter
the optimization variables we will discuss hereafter.
</p>
<a name="book_part1_chap5__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: Opening /etc/portage/make.conf</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">nano -w /mnt/gentoo/etc/portage/make.conf</span>
</pre></td></tr>
</table>
<p>
As you probably noticed, the <span class="path" dir="ltr">make.conf.example</span> file is
structured in a generic way: commented lines start with "#", other lines define
variables using the <span class="code" dir="ltr">VARIABLE="content"</span> syntax. The <span class="path" dir="ltr">make.conf</span>
file uses the same syntax. Several of those variables are discussed next.
</p>
<p class="secthead"><a name="book_part1_chap5__chap3_sect2">CFLAGS and CXXFLAGS</a></p>
<p>
The <span class="code" dir="ltr">CFLAGS</span> and <span class="code" dir="ltr">CXXFLAGS</span> variables define the optimization flags
for the <span class="code" dir="ltr">gcc</span> C and C++ compiler respectively. Although we define those
generally here, you will only have maximum performance if you optimize these
flags for each program separately. The reason for this is because every program
is different.
</p>
<p>
In <span class="path" dir="ltr">make.conf</span> you should define the optimization flags you think
will make your system the most responsive <span class="emphasis">generally</span>. Don't place
experimental settings in this variable; too much optimization can make
programs behave bad (crash, or even worse, malfunction).
</p>
<p>
We will not explain all possible optimization options. If you want to know
them all, read the <a href="http://gcc.gnu.org/onlinedocs/">GNU
Online Manual(s)</a> or the <span class="code" dir="ltr">gcc</span> info page (<span class="code" dir="ltr">info gcc</span> -- only
works on a working Linux system). The <span class="path" dir="ltr">make.conf.example</span> file
itself also contains lots of examples and information; don't forget to read it
too.
</p>
<p>
A first setting is the <span class="code" dir="ltr">-march=</span> or <span class="code" dir="ltr">-mtune=</span> flag, which specifies
the name of the target architecture. Possible options are described in the
<span class="path" dir="ltr">make.conf.example</span> file (as comments). A commonly used value is
<span class="emphasis">native</span> as that tells the compiler to select the target architecture of
the current system (the one you are installing on).
</p>
<p>
A second one is the <span class="code" dir="ltr">-O</span> flag (that is a capital O, not a zero),
which specifies the <span class="code" dir="ltr">gcc</span> optimization
class flag. Possible classes are <span class="code" dir="ltr">s</span> (for size-optimized),
<span class="code" dir="ltr">0</span> (zero - for no optimizations), <span class="code" dir="ltr">1</span>, <span class="code" dir="ltr">2</span> or even <span class="code" dir="ltr">3</span> for more
speed-optimization flags (every class has the same flags as the one before, plus
some extras). <span class="code" dir="ltr">-O2</span> is the recommended default. <span class="code" dir="ltr">-O3</span> is known to
cause problems when used system-wide, so we recommend that you stick to
<span class="code" dir="ltr">-O2</span>.
</p>
<p>
Another popular optimization flag is <span class="code" dir="ltr">-pipe</span> (use pipes rather than
temporary files for communication between the various stages of compilation).
It has no impact on the generated code, but uses more memory. On systems with
low memory, gcc might get killed. In that case, do not use this flag.
</p>
<p>
Using <span class="code" dir="ltr">-fomit-frame-pointer</span> (which doesn't keep the frame pointer in a
register for functions that don't need one) might have serious repercussions on
the debugging of applications.
</p>
<p>
When you define the <span class="code" dir="ltr">CFLAGS</span> and <span class="code" dir="ltr">CXXFLAGS</span>, you should combine
several optimization flags. The default values contained in the stage3 archive
you unpacked should be good enough. The following one is just an example:
</p>
<a name="book_part1_chap5__chap3_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.2: Defining the CFLAGS and CXXFLAGS variable</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
CFLAGS="-O2 -march=i686 -pipe"
<span class="code-comment"># Use the same settings for both variables</span>
CXXFLAGS="${CFLAGS}"
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
You may also want to view the <a href="https://wiki.gentoo.org/wiki/GCC_optimization">Compilation Optimization Guide</a> for
more information on how the various compilation options can affect your system.
</p></td></tr></table>
<p class="secthead"><a name="book_part1_chap5__chap3_sect3">MAKEOPTS</a></p>
<p>
With <span class="code" dir="ltr">MAKEOPTS</span> you define how many parallel compilations should occur when
you install a package. A good choice is the number of CPUs (or CPU cores) in
your system plus one, but this guideline isn't always perfect.
</p>
<a name="book_part1_chap5__chap3_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.3: MAKEOPTS for a regular, 1-CPU system</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
MAKEOPTS="-j2"
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part1_chap5__chap3_sect4">Ready, Set, Go!</a></p>
<p>
Update your <span class="path" dir="ltr">/mnt/gentoo/etc/portage/make.conf</span> to your own preference
and save (<span class="code" dir="ltr">nano</span> users would hit <span class="code" dir="ltr">Ctrl-X</span>). You are now ready to continue
with <a href="#book_part1_chap6">Installing the Gentoo Base System</a>.
</p>
<a name="book_part1_chap6"></a><h3>6. Installing the Gentoo Base System</h3>
<p class="chaphead"><a name="book_part1_chap6__chap1"></a><span class="chapnum">6.a. </span>Chrooting</p>
<p class="secthead"><a name="book_part1_chap6__chap1_sect1">Optional: Selecting Mirrors</a></p>
<p>
In order to download source code quickly it is recommended to select a fast
mirror. Portage will look in your <span class="path" dir="ltr">make.conf</span> file for the
GENTOO_MIRRORS variable and use the mirrors listed therein. You can surf to
our <a href="/main/en/mirrors.xml?style=printable">mirror list</a> and search
for a mirror (or mirrors) close to you (as those are most frequently the
fastest ones), but we provide a nice tool called <span class="code" dir="ltr">mirrorselect</span> which
provides you with a nice interface to select the mirrors you want. Just
navigate to the mirrors of choice and press spacebar to select one or more
mirrors.
</p>
<a name="book_part1_chap6__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: Using mirrorselect for the GENTOO_MIRRORS variable</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">mirrorselect -i -o &gt;&gt; /mnt/gentoo/etc/portage/make.conf</span>
</pre></td></tr>
</table>
<p>
A second important setting is the SYNC setting in <span class="path" dir="ltr">make.conf</span>. This
variable contains the rsync server you want to use when updating your Portage
tree (the collection of ebuilds, scripts containing all the information Portage
needs to download and install software). Although you can manually enter a SYNC
server for yourself, <span class="code" dir="ltr">mirrorselect</span> can ease that operation for you:
</p>
<a name="book_part1_chap6__chap1_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.2: Selecting an rsync mirror using mirrorselect</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">mirrorselect -i -r -o &gt;&gt; /mnt/gentoo/etc/portage/make.conf</span>
</pre></td></tr>
</table>
<p>
After running <span class="code" dir="ltr">mirrorselect</span> it is adviseable to double-check the settings
in <span class="path" dir="ltr">/mnt/gentoo/etc/portage/make.conf</span> !
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
If you want to manually set a SYNC server in <span class="path" dir="ltr">make.conf</span>, you should
check out the <a href="/main/en/mirrors-rsync.xml?style=printable">community mirrors
list</a> for the mirrors closest to you. We recommend choosing a
<span class="emphasis">rotation</span>, such as <span class="code" dir="ltr">rsync.us.gentoo.org</span>, rather than choosing a
single mirror. This helps spread out the load and provides a failsafe in case a
specific mirror is offline.
</p></td></tr></table>
<p class="secthead"><a name="book_part1_chap6__chap1_sect2">Copy DNS Info</a></p>
<p>
One thing still remains to be done before we enter the new environment and that
is copying over the DNS information in <span class="path" dir="ltr">/etc/resolv.conf</span>. You need
to do this to ensure that networking still works even after entering the new
environment. <span class="path" dir="ltr">/etc/resolv.conf</span> contains the nameservers for your
network.
</p>
<a name="book_part1_chap6__chap1_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.3: Copy over DNS information</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment">(The "-L" option is needed to make sure we don't copy a symbolic link)</span>
# <span class="code-input">cp -L /etc/resolv.conf /mnt/gentoo/etc/</span>
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part1_chap6__chap1_sect3">Mounting the necessary Filesystems</a></p>
<p>
In a few moments, we will change the Linux root towards the new location. To
make sure that the new environment works properly, we need to make certain file
systems available there as well.
</p>
<p>
Mount the <span class="path" dir="ltr">/proc</span> filesystem on <span class="path" dir="ltr">/mnt/gentoo/proc</span> to
allow the installation to use the kernel-provided information within the
chrooted environment, and then mount-bind the <span class="path" dir="ltr">/dev</span> and
<span class="path" dir="ltr">/sys</span> filesystems.
</p>
<a name="book_part1_chap6__chap1_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.4: Mounting /proc and /dev</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">mount -t proc proc /mnt/gentoo/proc</span>
# <span class="code-input">mount --rbind /sys /mnt/gentoo/sys</span>
# <span class="code-input">mount --rbind /dev /mnt/gentoo/dev</span>
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffbbbb"><p class="note"><b>Warning: </b>
When using non-Gentoo installation media, this might not be sufficient.
Some distributions make <span class="path" dir="ltr">/dev/shm</span> a symbolic link to
<span class="path" dir="ltr">/run/shm</span> which, after the chroot, becomes invalid. Making
<span class="path" dir="ltr">/dev/shm</span> a proper tmpfs-mount up front can fix this.
</p></td></tr></table>
<p class="secthead"><a name="book_part1_chap6__chap1_sect4">Entering the new Environment</a></p>
<p>
Now that all partitions are initialized and the base environment
installed, it is time to enter our new installation environment by
<span class="emphasis">chrooting</span> into it. This means that we change from the current
installation environment (Installation CD or other installation medium) to your
installation system (namely the initialized partitions).
</p>
<p>
This chrooting is done in three steps. First we will change the root
from <span class="path" dir="ltr">/</span> (on the installation medium) to <span class="path" dir="ltr">/mnt/gentoo</span>
(on your partitions) using <span class="code" dir="ltr">chroot</span>. Then we will reload some settings, as
provided by <span class="path" dir="ltr">/etc/profile</span>, in memory using <span class="code" dir="ltr">source</span>.
The last step is to redefine the primary prompt to help us remember that we are
inside a chroot environment.
</p>
<a name="book_part1_chap6__chap1_pre5"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.5: Chrooting into the new environment</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">chroot /mnt/gentoo /bin/bash</span>
# <span class="code-input">source /etc/profile</span>
# <span class="code-input">export PS1="(chroot) $PS1"</span>
</pre></td></tr>
</table>
<p>
Congratulations! You are now inside your own Gentoo Linux environment.
Of course it is far from finished, which is why the installation still
has some sections left :-)
</p>
<p>
If you at any time would need another terminal or console to access the chroot
environment, all you need to do is to execute the above steps again.
</p>
<p class="chaphead"><a name="installing_portage"></a><a name="book_part1_chap6__chap2"></a><span class="chapnum">6.b. </span>Configuring Portage</p>
<p class="secthead"><a name="book_part1_chap6__chap2_sect1">Installing a Portage Snapshot</a></p>
<p>
You now have to install a Portage snapshot, a collection of files that inform
Portage what software titles you can install, which profiles are available, etc.
</p>
<p>
We recommend the use of <span class="code" dir="ltr">emerge-webrsync</span>. This will fetch the latest
portage snapshot (which Gentoo releases on a daily basis) from one of our mirrors
and install it onto your system.
</p>
<a name="book_part1_chap6__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: Running emerge-webrsync to install a Portage snapshot</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge-webrsync</span>
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
During this operation, <span class="code" dir="ltr">emerge-webrsync</span> might complain about a missing
<span class="path" dir="ltr">/usr/portage</span> location. This is to be expected and nothing to
worry about - the tool will create the location for us.
</p></td></tr></table>
<p>
From this point onward, Portage might mention that certain updates are
recommended to be executed. This is because certain system packages
installed through the stage3 file might have newer versions available,
and Portage is now aware of this because a new Portage snapshot is installed.
You can safely ignore this for now and update after the Gentoo installation
has finished.
</p>
<p class="secthead"><a name="book_part1_chap6__chap2_sect2">Optional: Updating the Portage tree</a></p>
<p>
You can now update your Portage tree to the latest version. <span class="code" dir="ltr">emerge
--sync</span> will use the rsync protocol to update the Portage tree (which
you fetched earlier on through <span class="code" dir="ltr">emerge-webrsync</span>) to the latest state.
</p>
<a name="book_part1_chap6__chap2_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.2: Updating the Portage tree</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge --sync</span>
<span class="code-comment">(If you're using a slow terminal like some framebuffers or a serial
console, you can add the --quiet option to speed up this process:)</span>
# <span class="code-input">emerge --sync --quiet</span>
</pre></td></tr>
</table>
<p>
If you are behind a firewall that blocks rsync traffic, you safely ignore this
step as you already have a quite up-to-date Portage tree.
</p>
<p>
If you are warned that a new Portage version is available and that you should
update Portage, you should do it now using <span class="code" dir="ltr">emerge --oneshot portage</span>. You
might also be notified that "news items need reading". More on that next.
</p>
<p class="secthead"><a name="book_part1_chap6__chap2_sect3">Reading News Items</a></p>
<p>
When a Portage tree is synchronized to your system, Portage might warn you with
the following:
</p>
<a name="book_part1_chap6__chap2_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.3: Portage informing that news items are available</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
* IMPORTANT: 2 news items need reading for repository 'gentoo'.
* Use eselect news to read news items.
</pre></td></tr>
</table>
<p>
Portage news items were created to provide a communication medium to push
critical messages to users via the rsync tree. To manage them you will need to
use <span class="code" dir="ltr">eselect news</span>. With the <span class="code" dir="ltr">read</span> subcommand, you can read all news
items. With <span class="code" dir="ltr">list</span> you can get an overview of the available news items, and
with <span class="code" dir="ltr">purge</span> you can remove them once you have read them and have no
further need for the item(s) anymore.
</p>
<a name="book_part1_chap6__chap2_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.4: Handling Portage news</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">eselect news list</span>
# <span class="code-input">eselect news read</span>
</pre></td></tr>
</table>
<p>
More information about the newsreader is available through its manual page:
<span class="code" dir="ltr">man news.eselect</span>.
</p>
<p class="secthead"><a name="book_part1_chap6__chap2_sect4">Choosing the Right Profile</a></p>
<p>
First, a small definition is in place.
</p>
<p>
A profile is a building block for any Gentoo system. Not only does it specify
default values for USE, CFLAGS and other important variables, it also locks
the system to a certain range of package versions. This is all maintained by the
Gentoo developers.
</p>
<p>
Previously, such a profile was untouched by the users. However, there may be
certain situations in which you may decide a profile change is necessary.
</p>
<p>
You can see what profile you are currently using with the following command:
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
The output of the command below is just an example and evolves over time.
</p></td></tr></table>
<a name="book_part1_chap6__chap2_pre5"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.5: Verifying system profile</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">eselect profile list</span>
Available profile symlink targets:
[1] default/linux/x86/13.0 *
[2] default/linux/x86/13.0/desktop
[3] default/linux/x86/13.0/desktop/gnome
[4] default/linux/x86/13.0/desktop/kde
</pre></td></tr>
</table>
<p>
As you can see, there are also <span class="code" dir="ltr">desktop</span> subprofiles available for some
architectures. Running <span class="code" dir="ltr">eselect profile list</span> will show all available
profiles.
</p>
<p>
After viewing the available profiles for your architecture, you can use a
different one if you wish:
</p>
<a name="book_part1_chap6__chap2_pre6"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.6: Changing profiles</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">eselect profile set 2</span>
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
The <span class="code" dir="ltr">developer</span> subprofile is specifically for Gentoo Linux development
tasks. It is <span class="emphasis">not</span> meant to help set up general development environments.
</p></td></tr></table>
<p class="secthead"><a name="configure_USE"></a><a name="book_part1_chap6__chap2_sect5">Configuring the USE variable</a></p>
<p>
<span class="code" dir="ltr">USE</span> is one of the most powerful variables Gentoo provides to its users.
Several programs can be compiled with or without optional support for certain
items. For instance, some programs can be compiled with gtk-support, or with
qt-support. Others can be compiled with or without SSL support. Some programs
can even be compiled with framebuffer support (svgalib) instead of X11 support
(X-server).
</p>
<p>
Most distributions compile their packages with support for as much as possible,
increasing the size of the programs and startup time, not to mention an enormous
amount of dependencies. With Gentoo you can define what options a package
should be compiled with. This is where <span class="code" dir="ltr">USE</span> comes into play.
</p>
<p>
In the <span class="code" dir="ltr">USE</span> variable you define keywords which are mapped onto
compile-options. For instance, <span class="emphasis">ssl</span> will compile ssl-support in the
programs that support it. <span class="emphasis">-X</span> will remove X-server support (note the
minus sign in front). <span class="emphasis">gnome gtk -kde -qt4</span> will compile your
programs with gnome (and gtk) support, and not with kde (and qt) support,
making your system fully tweaked for GNOME.
</p>
<p>
The default <span class="code" dir="ltr">USE</span> settings are placed in the <span class="path" dir="ltr">make.defaults</span>
files of your profile. You will find <span class="path" dir="ltr">make.defaults</span> files in the
directory which <span class="path" dir="ltr">/etc/portage/make.profile</span> points to and all parent
directories as well. The default <span class="code" dir="ltr">USE</span> setting is the sum of all <span class="code" dir="ltr">USE</span>
settings in all <span class="path" dir="ltr">make.defaults</span> files. What you place in
<span class="path" dir="ltr">/etc/portage/make.conf</span> is calculated against these defaults
settings. If you add something to the <span class="code" dir="ltr">USE</span> setting, it is added to the
default list. If you remove something from the <span class="code" dir="ltr">USE</span> setting (by placing
a minus sign in front of it) it is removed from the default list (if it was
in the default list at all). <span class="emphasis">Never</span> alter anything inside the
<span class="path" dir="ltr">/etc/portage/make.profile</span> directory; it gets overwritten when
you update Portage!
</p>
<p>
A full description on <span class="code" dir="ltr">USE</span> can be found in the second part of the Gentoo
Handbook, <a href="#book_part2_chap2">USE flags</a>. A full description on
the available USE flags can be found on your system in
<span class="path" dir="ltr">/usr/portage/profiles/use.desc</span>.
</p>
<a name="book_part1_chap6__chap2_pre7"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.7: Viewing available USE flags</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">less /usr/portage/profiles/use.desc</span>
<span class="code-comment">(You can scroll using your arrow keys, exit by pressing 'q')</span>
</pre></td></tr>
</table>
<p>
As an example we show a <span class="code" dir="ltr">USE</span> setting for a KDE-based system with DVD, ALSA
and CD Recording support:
</p>
<a name="book_part1_chap6__chap2_pre8"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.8: Opening /etc/portage/make.conf</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">nano -w /etc/portage/make.conf</span>
</pre></td></tr>
</table>
<a name="book_part1_chap6__chap2_pre9"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.9: USE setting</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
USE="-gtk -gnome qt4 kde dvd alsa cdr"
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part1_chap6__chap3"></a><span class="chapnum">6.c. </span>Optional: Using systemd</p>
<p>
The remainder of the Gentoo Handbook focuses on OpenRC as the default init
support system. If you want to use systemd instead, or are planning to use Gnome
3.8 and later (which requires systemd), please consult the <a href="https://wiki.gentoo.org/wiki/Systemd">systemd page</a> on
the Gentoo wiki as it elaborates on the different configuration settings and
methods.
</p>
<p>
The Gentoo Handbook can then be followed with that page in mind.
</p>
<p class="chaphead"><a name="book_part1_chap6__chap4"></a><span class="chapnum">6.d. </span>Timezone</p>
<p>
Finally select your timezone so that your system knows where it is physically
located. Look for your timezone in <span class="path" dir="ltr">/usr/share/zoneinfo</span>, then
write it in the <span class="path" dir="ltr">/etc/timezone</span> file.
</p>
<a name="book_part1_chap6__chap4_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.1: Setting the timezone information</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">ls /usr/share/zoneinfo</span>
<span class="code-comment">(Suppose you want to use Europe/Brussels)</span>
# <span class="code-input">echo "Europe/Brussels" &gt; /etc/timezone</span>
</pre></td></tr>
</table>
<p>
Please avoid the <span class="path" dir="ltr">/usr/share/zoneinfo/Etc/GMT*</span> timezones as their
names do not indicate the expected zones. For instance, <span class="path" dir="ltr">GMT-8</span> is
in fact GMT+8.
</p>
<p>
Next, reconfigure the timezone-data package, which will update the
<span class="path" dir="ltr">/etc/localtime</span> file for us, based on the <span class="path" dir="ltr">/etc/timezone</span>
entry. The <span class="path" dir="ltr">/etc/localtime</span> file is used by the system C library
to know the timezone the system is in.
</p>
<a name="book_part1_chap6__chap4_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.2: Reconfiguring timezone-data</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge --config sys-libs/timezone-data</span>
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part1_chap6__chap5"></a><span class="chapnum">6.e. </span>Configure locales</p>
<p>
You will probably only use one or maybe two locales on your system. You have to
specify locales you will need in <span class="path" dir="ltr">/etc/locale.gen</span>.
</p>
<a name="book_part1_chap6__chap5_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.1: Opening /etc/locale.gen</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">nano -w /etc/locale.gen</span>
</pre></td></tr>
</table>
<p>
The following locales are an example to get both English (United States) and
German (Germany) with the accompanying character formats (like UTF-8).
</p>
<a name="book_part1_chap6__chap5_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.2: Specify your locales</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
en_US ISO-8859-1
en_US.UTF-8 UTF-8
de_DE ISO-8859-1
de_DE@euro ISO-8859-15
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
You can select your desired locales in the list given by running <span class="code" dir="ltr">locale -a</span>.
</p></td></tr></table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffbbbb"><p class="note"><b>Warning: </b>
We strongly suggest that you should use at least one UTF-8 locale because some
applications may require it.
</p></td></tr></table>
<p>
The next step is to run <span class="code" dir="ltr">locale-gen</span>. It will generate all the locales you
have specified in the <span class="path" dir="ltr">/etc/locale.gen</span> file.
</p>
<a name="book_part1_chap6__chap5_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.3: Running locale-gen</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">locale-gen</span>
</pre></td></tr>
</table>
<p>
You can verify that your selected locales are available by running <span class="code" dir="ltr">locale -a</span>.
</p>
<p>
Once done, you now have the possibility to set the system-wide locale settings.
With <span class="code" dir="ltr">eselect locale list</span>, the available targets are displayed:
</p>
<a name="book_part1_chap6__chap5_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.4: Displaying the available LANG settings</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">eselect locale list</span>
Available targets for the LANG variable:
[1] C
[2] POSIX
[3] en_US
[4] en_US.iso88591
[5] en_US.utf8
[6] de_DE
[7] de_DE.iso88591
[8] de_DE.iso885915
[9] de_DE.utf8
[ ] (free form)
</pre></td></tr>
</table>
<p>
With <span class="code" dir="ltr">eselect locale set &lt;value&gt;</span> the correct locale can be set:
</p>
<a name="book_part1_chap6__chap5_pre5"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.5: Setting the LANG variable</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">eselect locale set 9</span>
</pre></td></tr>
</table>
<p>
Manually, this can still be accomplished through the
<span class="path" dir="ltr">/etc/env.d/02locale</span> file:
</p>
<a name="book_part1_chap6__chap5_pre6"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.6: Setting the default system locale in /etc/env.d/02locale</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
LANG="de_DE.UTF-8"
LC_COLLATE="C"
</pre></td></tr>
</table>
<p>
Make sure a locale is set, as you could otherwise get warnings and errors
during kernel builds and other software deployments later in the installation.
</p>
<p>
Don't forget to reload your environment:
</p>
<a name="book_part1_chap6__chap5_pre7"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.7: Reload shell environment</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">env-update &amp;&amp; source /etc/profile</span>
</pre></td></tr>
</table>
<p>
We made a full <a href="https://wiki.gentoo.org/wiki/Localization/HOWTO">Localization
Guide</a> to help you through this process. You can also read the detailed
<a href="https://wiki.gentoo.org/wiki/UTF-8">UTF-8 article</a> for very specific
informations to enable UTF-8 on your system.
</p>
<a name="book_part1_chap7"></a><h3>7. Configuring the Kernel</h3>
<p class="chaphead"><a name="book_part1_chap7__chap1"></a><span class="chapnum">7.a. </span>Installing the Sources</p>
<p class="secthead"><a name="book_part1_chap7__chap1_sect1">Choosing a Kernel</a></p>
<p>
The core around which all distributions are built is the Linux kernel. It is the
layer between the user programs and your system hardware. Gentoo provides its
users several possible kernel sources. A full listing with description is
available at the <a href="https://wiki.gentoo.org/wiki/Kernel/Overview">Gentoo Kernel
Guide</a>.
</p>
<p>
For x86-based systems we have <span class="code" dir="ltr">gentoo-sources</span>
(kernel source patched for extra features).
</p>
<p>
Choose your kernel source and install it using <span class="code" dir="ltr">emerge</span>.
</p>
<a name="book_part1_chap7__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: Installing a kernel source</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge gentoo-sources</span>
</pre></td></tr>
</table>
<p>
When you take a look in <span class="path" dir="ltr">/usr/src</span> you should see a symlink called
<span class="path" dir="ltr">linux</span> pointing to your kernel source. In this case, the installed
kernel source points to <span class="code" dir="ltr">gentoo-sources-3.12.20</span>.
Your version may be different, so keep this in mind.
</p>
<a name="book_part1_chap7__chap1_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.2: Viewing the kernel source symlink</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">ls -l /usr/src/linux</span>
lrwxrwxrwx 1 root root 12 Oct 13 11:04 /usr/src/linux -&gt; linux-3.12.20
</pre></td></tr>
</table>
<p>
Now it is time to configure and compile your kernel source. You can use
<span class="code" dir="ltr">genkernel</span> for this, which will build a generic kernel as used by the
Installation CD. We explain the "manual" configuration first though, as it is
the best way to optimize your environment.
</p>
<p>
If you want to manually configure your kernel, continue now with <a href="#manual">Default: Manual Configuration</a>. If you want to use
<span class="code" dir="ltr">genkernel</span> you should read <a href="#genkernel">Alternative: Using
genkernel</a> instead.
</p>
<p class="chaphead"><a name="manual"></a><a name="book_part1_chap7__chap2"></a><span class="chapnum">7.b. </span>Default: Manual Configuration</p>
<p class="secthead"><a name="book_part1_chap7__chap2_sect1">Introduction</a></p>
<p>
Manually configuring a kernel is often seen as the most difficult procedure a
Linux user ever has to perform. Nothing is less true -- after configuring a
couple of kernels you don't even remember that it was difficult ;)
</p>
<p>
However, one thing <span class="emphasis">is</span> true: you must know your system when you start
configuring a kernel manually. Most information can be gathered by emerging
pciutils (<span class="code" dir="ltr">emerge pciutils</span>) which contains <span class="code" dir="ltr">lspci</span>. You will now
be able to use <span class="code" dir="ltr">lspci</span> within the chrooted environment. You may safely
ignore any <span class="emphasis">pcilib</span> warnings (like pcilib: cannot open
/sys/bus/pci/devices) that <span class="code" dir="ltr">lspci</span> throws out. Alternatively, you can run
<span class="code" dir="ltr">lspci</span> from a <span class="emphasis">non-chrooted</span> environment. The results are the same.
You can also run <span class="code" dir="ltr">lsmod</span> to see what kernel modules the Installation CD
uses (it might provide you with a nice hint on what to enable).
</p>
<p>
Now go to your kernel source directory and execute <span class="code" dir="ltr">make menuconfig</span>. This
will fire up an ncurses-based configuration menu.
</p>
<a name="book_part1_chap7__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: Invoking menuconfig</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">cd /usr/src/linux</span>
# <span class="code-input">make menuconfig</span>
</pre></td></tr>
</table>
<p>
You will be greeted with several configuration sections. We'll first list some
options you must activate (otherwise Gentoo will not function, or not function
properly without additional tweaks). We also have a <a href="https://wiki.gentoo.org/wiki/Kernel/Gentoo_Kernel_Configuration_Guide">Gentoo
Kernel Configuration Guide</a> on the Gentoo wiki that might help you further.
</p>
<p class="secthead"><a name="book_part1_chap7__chap2_sect2">Activating Required Options</a></p>
<p>
Make sure that every driver that is vital to the booting of your system (such as
SCSI controller, ...) is compiled <span class="emphasis">in</span> the kernel and not as a module,
otherwise your system will not be able to boot completely.
</p>
<p>
Now select the correct processor family:
</p>
<a name="book_part1_chap7__chap2_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.2: Selecting correct processor family</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
Processor type and features ---&gt;
<span class="code-comment">(Change according to your system)</span>
(<span class="code-input">Athlon/Duron/K7</span>) Processor family
</pre></td></tr>
</table>
<p>
Next select <span class="emphasis">Maintain a devtmpfs file system to mount at /dev</span> so that
critical device files are already available early in the boot process.
</p>
<a name="book_part1_chap7__chap2_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.3: Enabling devtmpfs support</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
Device Drivers ---&gt;
Generic Driver Options ---&gt;
[*] Maintain a devtmpfs filesystem to mount at /dev
[ ] Automount devtmpfs at /dev, after the kernel mounted the rootfs
</pre></td></tr>
</table>
<p>
Now go to <span class="code" dir="ltr">File Systems</span> and select support for the filesystems you use.
<span class="emphasis">Don't</span> compile the file system you use for the root filesystem as module,
otherwise your Gentoo system will not be able to mount your partition. Also
select <span class="code" dir="ltr">Virtual memory</span> and <span class="code" dir="ltr">/proc file system</span>.
</p>
<a name="book_part1_chap7__chap2_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.4: Selecting necessary file systems</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
File systems ---&gt;
<span class="code-comment">(Select one or more of the following options as needed by your system)</span>
&lt;*&gt; Second extended fs support
&lt;*&gt; Ext3 journalling file system support
&lt;*&gt; The Extended 4 (ext4) filesystem
&lt;*&gt; Reiserfs support
&lt;*&gt; JFS filesystem support
&lt;*&gt; XFS filesystem support
...
Pseudo Filesystems ---&gt;
[*] /proc file system support
[*] Virtual memory file system support (former shm fs)
<span class="code-comment">(Enable GPT partition label support if you used that previously)</span>
-*- Enable the block layer ---&gt;
...
Partition Types ---&gt;
[*] Advanced partition selection
...
[*] EFI GUID Partition support
</pre></td></tr>
</table>
<p>
If you are using PPPoE to connect to the Internet or you are using a dial-up
modem, you will need the following options in the kernel:
</p>
<a name="book_part1_chap7__chap2_pre5"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.5: Selecting PPPoE necessary drivers</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
Device Drivers ---&gt;
Network device support ---&gt;
&lt;*&gt; PPP (point-to-point protocol) support
&lt;*&gt; PPP support for async serial ports
&lt;*&gt; PPP support for sync tty ports
</pre></td></tr>
</table>
<p>
The two compression options won't harm but are not definitely needed, neither
does the <span class="code" dir="ltr">PPP over Ethernet</span> option, that might only be used by <span class="code" dir="ltr">ppp</span>
when configured to do kernel mode PPPoE.
</p>
<p>
If you require it, don't forget to include support in the kernel for your
ethernet card.
</p>
<p>
If you have an Intel CPU that supports HyperThreading (tm), or you have a
multi-CPU system, you should activate "Symmetric multi-processing support":
</p>
<a name="book_part1_chap7__chap2_pre6"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.6: Activating SMP support</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
Processor type and features ---&gt;
[*] Symmetric multi-processing support
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
In multi-core systems, each core counts as one processor.
</p></td></tr></table>
<p>
If you have more than 4GB of RAM, you need to enable "High Memory Support
(64G)".
</p>
<p>
If you use USB Input Devices (like Keyboard or Mouse) don't forget to enable
those as well:
</p>
<a name="book_part1_chap7__chap2_pre7"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.7: Activating USB Support for Input Devices</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
Device Drivers ---&gt;
[*] HID Devices ---&gt;
&lt;*&gt; USB Human Interface Device (full HID) support
</pre></td></tr>
</table>
<p>
If you want PCMCIA support for your laptop, don't forget to enable
support for the PCMCIA card bridge present in your system:
</p>
<a name="book_part1_chap7__chap2_pre8"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.8: Enabling PCMCIA support</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
Bus options (PCI etc.) ---&gt;
PCCARD (PCMCIA/CardBus) support ---&gt;
&lt;*&gt; PCCard (PCMCIA/CardBus) support
<span class="code-comment">(select 16 bit if you need support for older PCMCIA cards. Most people want this.)</span>
&lt;*&gt; 16-bit PCMCIA support
[*] 32-bit CardBus support
<span class="code-comment">(select the relevant bridges below)</span>
*** PC-card bridges ***
&lt;*&gt; CardBus yenta-compatible bridge support (NEW)
&lt;*&gt; Cirrus PD6729 compatible bridge support (NEW)
&lt;*&gt; i82092 compatible bridge support (NEW)
</pre></td></tr>
</table>
<p>
When you've finished configuring the kernel, continue with <a href="#compiling">Compiling and Installing</a>.
</p>
<p class="secthead"><a name="compiling"></a><a name="book_part1_chap7__chap2_sect3">Compiling and Installing</a></p>
<p>
Now that your kernel is configured, it is time to compile and install it. Exit
the configuration and start the compilation process:
</p>
<a name="book_part1_chap7__chap2_pre9"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.9: Compiling the kernel</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">make &amp;&amp; make modules_install</span>
</pre></td></tr>
</table>
<p>
When the kernel has finished compiling, copy the kernel image to
<span class="path" dir="ltr">/boot</span>. This is handled by the <span class="code" dir="ltr">make install</span> command:
</p>
<a name="book_part1_chap7__chap2_pre10"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.10: Installing the kernel</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">make install</span>
</pre></td></tr>
</table>
<p>
This will copy the kernel image into <span class="path" dir="ltr">/boot</span> together with the
<span class="path" dir="ltr">System.map</span> file and the kernel configuration file.
</p>
<p class="secthead"><a name="initramfs"></a><a name="book_part1_chap7__chap2_sect4">(Optional) Building an Initramfs</a></p>
<p>
If you use a specific partition layout where important file system locations
(like <span class="path" dir="ltr">/usr</span> or <span class="path" dir="ltr">/var</span>) are on separate partitions, then
you will need to setup an initramfs so that this partition can be mounted before
it is needed.
</p>
<p>
Without an initramfs, you risk that the system will not boot up properly as the
tools that are responsible for mounting the file systems need information that
resides on those file systems. An initramfs will pull in the necessary files
into an archive which is used right after the kernel boots, but before the
control is handed over to the <span class="code" dir="ltr">init</span> tool. Scripts on the initramfs will
then make sure that the partitions are properly mounted before the system
continues booting.
</p>
<p>
To install an initramfs, install <span class="code" dir="ltr">genkernel</span> first, then have it
generate an initramfs for you.
</p>
<a name="book_part1_chap7__chap2_pre11"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.11: Building an initramfs</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge genkernel</span>
# <span class="code-input">genkernel --install initramfs</span>
</pre></td></tr>
</table>
<p>
If you need specific support in the initramfs, such as lvm or raid, add in the
appropriate options to genkernel. See <span class="code" dir="ltr">genkernel --help</span> for more
information, or the next example which enables support for LVM and software raid
(mdadm):
</p>
<a name="book_part1_chap7__chap2_pre12"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.12: Building an initramfs with support for LVM and software raid</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">genkernel --lvm --mdadm --install initramfs</span>
</pre></td></tr>
</table>
<p>
The initramfs will be stored in <span class="path" dir="ltr">/boot</span>. You can find the file by
simply listing the files starting with <span class="path" dir="ltr">initramfs</span>:
</p>
<a name="book_part1_chap7__chap2_pre13"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.13: Checking the initramfs file name</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">ls /boot/initramfs*</span>
</pre></td></tr>
</table>
<p>
Now continue with <a href="#kernel_modules">Kernel Modules</a>.
</p>
<p class="chaphead"><a name="genkernel"></a><a name="book_part1_chap7__chap3"></a><span class="chapnum">7.c. </span>Alternative: Using genkernel</p>
<p>
If you are reading this section, you have chosen to use our <span class="code" dir="ltr">genkernel</span>
script to configure your kernel for you.
</p>
<p>
Now that your kernel source tree is installed, it's now time to compile your
kernel by using our <span class="code" dir="ltr">genkernel</span> script to automatically build a kernel for
you. <span class="code" dir="ltr">genkernel</span> works by configuring a kernel nearly identically to the
way our Installation CD kernel is configured. This means that when you use
<span class="code" dir="ltr">genkernel</span> to build your kernel, your system will generally detect all
your hardware at boot-time, just like our Installation CD does. Because
genkernel doesn't require any manual kernel configuration, it is an ideal
solution for those users who may not be comfortable compiling their own kernels.
</p>
<p>
Now, let's see how to use genkernel. First, emerge the genkernel ebuild:
</p>
<a name="book_part1_chap7__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: Emerging genkernel</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge genkernel</span>
</pre></td></tr>
</table>
<p>
Next, edit the <span class="path" dir="ltr">/etc/fstab</span> file so that the line containing
<span class="path" dir="ltr">/boot</span> as second field has the first field pointing to the right
device. If the partitioning example from the handbook is followed, then this
device is most likely <span class="path" dir="ltr">/dev/sda2</span> with the ext2 file
system. This would make the entry in the file look like so:
</p>
<a name="book_part1_chap7__chap3_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.2: Editing /etc/fstab for the /boot entry</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">nano -w /etc/fstab</span>
...
/dev/sda2 /boot ext2 defaults 0 2
</pre></td></tr>
</table>
<p>
The remainder of the <span class="path" dir="ltr">/etc/fstab</span> will be updated in the next section,
but as <span class="code" dir="ltr">genkernel</span> reads this information we need to update the
<span class="path" dir="ltr">/boot</span> line up front.
</p>
<p>
Now, compile your kernel sources by running <span class="code" dir="ltr">genkernel all</span>. Be aware
though, as <span class="code" dir="ltr">genkernel</span> compiles a kernel that supports almost all
hardware, this compilation will take quite a while to finish!
</p>
<p>
Note that, if your boot partition doesn't use ext2 or ext3 as filesystem you
might need to manually configure your kernel using <span class="code" dir="ltr">genkernel --menuconfig
all</span> and add support for your filesystem <span class="emphasis">in</span> the kernel (i.e.
<span class="emphasis">not</span> as a module). Users of LVM2 will probably want to add <span class="code" dir="ltr">--lvm</span>
as an argument as well.
</p>
<a name="book_part1_chap7__chap3_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.3: Running genkernel</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">genkernel all</span>
</pre></td></tr>
</table>
<p>
Once <span class="code" dir="ltr">genkernel</span> completes, a kernel, full set of modules and
<span class="emphasis">initial ram disk</span> (initramfs) will be created. We will use the kernel
and initrd when configuring a boot loader later in this document. Write
down the names of the kernel and initrd as you will need it when writing
the bootloader configuration file. The initrd will be started immediately after
booting to perform hardware autodetection (just like on the Installation CD)
before your "real" system starts up.
</p>
<a name="book_part1_chap7__chap3_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.4: Checking the created kernel image name and initrd</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">ls /boot/kernel* /boot/initramfs*</span>
</pre></td></tr>
</table>
<p class="chaphead"><a name="kernel_modules"></a><a name="book_part1_chap7__chap4"></a><span class="chapnum">7.d. </span>Kernel Modules</p>
<p class="secthead"><a name="kernelmodules"></a><a name="book_part1_chap7__chap4_sect1">Configuring the Modules</a></p>
<p>
You should list the modules you want automatically loaded in
<span class="path" dir="ltr">/etc/conf.d/modules</span>. You can add extra options to
the modules too if you want.
</p>
<p>
To view all available modules, run the following <span class="code" dir="ltr">find</span> command. Don't
forget to substitute "&lt;kernel version&gt;" with the version of the kernel you
just compiled:
</p>
<a name="book_part1_chap7__chap4_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.1: Viewing all available modules</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">find /lib/modules/&lt;kernel version&gt;/ -type f -iname '*.o' -or -iname '*.ko' | less</span>
</pre></td></tr>
</table>
<p>
For instance, to automatically load the <span class="code" dir="ltr">3c59x.ko</span> module (which is the
driver for a specific 3Com network card family), edit the
<span class="path" dir="ltr">/etc/conf.d/modules</span> file and enter the module name in it.
</p>
<a name="book_part1_chap7__chap4_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.2: Editing /etc/conf.d/modules</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">nano -w /etc/conf.d/modules</span>
modules_2_6="<span class="code-input">3c59x</span>"
</pre></td></tr>
</table>
<p>
Continue the installation with <a href="#book_part1_chap8">Configuring your
System</a>.
</p>
<a name="book_part1_chap8"></a><h3>8. Configuring your System</h3>
<p class="chaphead"><a name="book_part1_chap8__chap1"></a><span class="chapnum">8.a. </span>Filesystem Information</p>
<p class="secthead"><a name="book_part1_chap8__chap1_sect1">What is fstab?</a></p>
<p>
Under Linux, all partitions used by the system must be listed in
<span class="path" dir="ltr">/etc/fstab</span>. This file contains the mount points of those partitions
(where they are seen in the file system structure), how they should be mounted
and with what special options (automatically or not, whether users can mount
them or not, etc.)
</p>
<p class="secthead"><a name="book_part1_chap8__chap1_sect2">Creating /etc/fstab</a></p>
<p>
<span class="path" dir="ltr">/etc/fstab</span> uses a special syntax. Every line consists of six
fields, separated by whitespace (space(s), tabs or a mixture). Each field has
its own meaning:
</p>
<ul>
<li>
The first field shows the <b>partition</b> described (the path to the device
file)
</li>
<li>
The second field shows the <b>mount point</b> at which the partition should be
mounted
</li>
<li>
The third field shows the <b>filesystem</b> used by the partition
</li>
<li>
The fourth field shows the <b>mount options</b> used by <span class="code" dir="ltr">mount</span> when it
wants to mount the partition. As every filesystem has its own mount options,
you are encouraged to read the mount man page (<span class="code" dir="ltr">man mount</span>) for a full
listing. Multiple mount options are comma-separated.
</li>
<li>
The fifth field is used by <span class="code" dir="ltr">dump</span> to determine if the partition needs to
be <b>dump</b>ed or not. You can generally leave this as <span class="code" dir="ltr">0</span> (zero).
</li>
<li>
The sixth field is used by <span class="code" dir="ltr">fsck</span> to determine the order in which
filesystems should be <b>check</b>ed if the system wasn't shut down properly.
The root filesystem should have <span class="code" dir="ltr">1</span> while the rest should have <span class="code" dir="ltr">2</span>
(or <span class="code" dir="ltr">0</span> if a filesystem check isn't necessary).
</li>
</ul>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffffbb"><p class="note"><b>Important: </b>
The default <span class="path" dir="ltr">/etc/fstab</span> file provided by Gentoo <span class="emphasis">is not a valid
fstab file</span>. You <b>have to create</b> your own <span class="path" dir="ltr">/etc/fstab</span>.
</p></td></tr></table>
<a name="book_part1_chap8__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: Opening /etc/fstab</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">nano -w /etc/fstab</span>
</pre></td></tr>
</table>
<p>
In the remainder of the text, we use the default <span class="path" dir="ltr">/dev/sd*</span> block
device files as partition. You can also opt to use the symbolic links in the
<span class="path" dir="ltr">/dev/disk/by-id</span> or <span class="path" dir="ltr">/dev/disk/by-uuid</span>. These names are
not likely to change, whereas the default block device files naming depends on
a number of factors (such as how and in what order the disks are attached to
your system). However, if you do not intend to fiddle with the disk ordering,
you can continue with the default block device files safely.
</p>
<p>
Let us take a look at how we write down the options for the <span class="path" dir="ltr">/boot</span>
partition. This is just an example, if you didn't or couldn't create a
<span class="path" dir="ltr">/boot</span>, don't copy it.
</p>
<p>
In our default x86 partitioning example, <span class="path" dir="ltr">/boot</span> is
usually the <span class="path" dir="ltr">/dev/sda2</span> partition, with <span class="code" dir="ltr">ext2</span> as
filesystem. It needs to be checked during boot, so we would write down:
</p>
<a name="book_part1_chap8__chap1_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.2: An example /boot line for /etc/fstab</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
/dev/sda2 /boot ext2 defaults 0 2
</pre></td></tr>
</table>
<p>
Some users don't want their <span class="path" dir="ltr">/boot</span> partition to be mounted
automatically to improve their system's security. Those people should
substitute <span class="code" dir="ltr">defaults</span> with <span class="code" dir="ltr">noauto</span>. This does mean that you need to
manually mount this partition every time you want to use it.
</p>
<p>
Add the rules that match your partitioning scheme and append rules for
your CD-ROM drive(s), and of course, if you have other partitions or drives,
for those too.
</p>
<p>
Now use the <span class="emphasis">example</span> below to create your <span class="path" dir="ltr">/etc/fstab</span>:
</p>
<a name="book_part1_chap8__chap1_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.3: A full /etc/fstab example</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
/dev/sda2 /boot ext2 defaults,noatime 0 2
/dev/sda3 none swap sw 0 0
/dev/sda4 / ext4 noatime 0 1
/dev/cdrom /mnt/cdrom auto noauto,user 0 0
</pre></td></tr>
</table>
<p>
<span class="code" dir="ltr">auto</span> makes <span class="code" dir="ltr">mount</span> guess for the filesystem (recommended for
removable media as they can be created with one of many filesystems) and
<span class="code" dir="ltr">user</span> makes it possible for non-root users to mount the CD.
</p>
<p>
To improve performance, most users would want to add the <span class="code" dir="ltr">noatime</span>
mount option, which results in a faster system since access times
aren't registered (you don't need those generally anyway). This is also
recommended for solid state drive (SSD) users, who should also enable
the <span class="code" dir="ltr">discard</span> mount option (ext4 and btrfs only for now) which
makes the TRIM command work.
</p>
<p>
Double-check your <span class="path" dir="ltr">/etc/fstab</span>, save and quit to continue.
</p>
<p class="chaphead"><a name="book_part1_chap8__chap2"></a><span class="chapnum">8.b. </span>Networking Information</p>
<p class="secthead"><a name="book_part1_chap8__chap2_sect1">Host name, Domainname, etc</a></p>
<p>
One of the choices the user has to make is name his/her PC. This seems to be
quite easy, but <span class="emphasis">lots</span> of users are having difficulties finding the
appropriate name for their Linux-pc. To speed things up, know that any name you
choose can be changed afterwards. For all we care, you can just call your system
<span class="code" dir="ltr">tux</span> and domain <span class="code" dir="ltr">homenetwork</span>.
</p>
<a name="book_part1_chap8__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: Setting the host name</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">nano -w /etc/conf.d/hostname</span>
<span class="code-comment">(Set the hostname variable to your host name)</span>
hostname="<span class="code-input">tux</span>"
</pre></td></tr>
</table>
<p>
Second, <span class="emphasis">if</span> you need a domainname, set it in <span class="path" dir="ltr">/etc/conf.d/net</span>.
You only need a domain if your ISP or network administrator says so, or if you
have a DNS server but not a DHCP server. You don't need to worry about DNS or
domainnames if your networking is setup for DHCP.
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
The <span class="path" dir="ltr">/etc/conf.d/net</span> file does not exist by default, so you might
need to create it.
</p></td></tr></table>
<a name="book_part1_chap8__chap2_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.2: Setting the domainname</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">nano -w /etc/conf.d/net</span>
<span class="code-comment">(Set the dns_domain variable to your domain name)</span>
dns_domain_lo="<span class="code-input">homenetwork</span>"
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
If you choose not to set a domainname, you can get rid of the "This is
hostname.(none)" messages at your login screen by editing
<span class="path" dir="ltr">/etc/issue</span>. Just delete the string <span class="code" dir="ltr">.\O</span> from that file.
</p></td></tr></table>
<p>
If you have a NIS domain (if you don't know what that is, then you don't have
one), you need to define that one too:
</p>
<a name="book_part1_chap8__chap2_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.3: Setting the NIS domainname</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">nano -w /etc/conf.d/net</span>
<span class="code-comment">(Set the nis_domain variable to your NIS domain name)</span>
nis_domain_lo="<span class="code-input">my-nisdomain</span>"
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
For more information on configuring DNS and NIS, please read the examples
provided in <span class="path" dir="ltr">/usr/share/doc/netifrc-*/net.example.bz2</span> which
can be read using <span class="code" dir="ltr">bzless</span>. Also, you may want to emerge <span class="code" dir="ltr">openresolv</span>
to help manage your DNS/NIS setup.
</p></td></tr></table>
<p class="secthead"><a name="book_part1_chap8__chap2_sect2">Configuring your Network</a></p>
<p>
Before you get that "Hey, we've had that already"-feeling, you should remember
that the networking you set up in the beginning of the Gentoo installation was
just for the installation. Right now you are going to configure networking for
your Gentoo system permanently.
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
More detailed information about networking, including advanced topics like
bonding, bridging, 802.1Q VLANs or wireless networking is covered in the <a href="#book_part4">Gentoo Network Configuration</a> section.
</p></td></tr></table>
<p>
All networking information is gathered in <span class="path" dir="ltr">/etc/conf.d/net</span>. It uses
a straightforward yet not intuitive syntax if you don't know how to set up
networking manually. But don't fear, we'll explain everything. A fully
commented example that covers many different configurations is available in
<span class="path" dir="ltr">/usr/share/doc/netifrc-*/net.example.bz2</span>.
</p>
<p>
Let's first install <span class="code" dir="ltr">netifrc</span>:
</p>
<a name="book_part1_chap8__chap2_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.4: Installing netifrc</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge --noreplace netifrc</span>
</pre></td></tr>
</table>
<p>
DHCP is used by default. For DHCP to work, you will need to install a DHCP
client. This is described later in <a href="#networking-tools">Installing Necessary System
Tools</a>. Do not forget to install a DHCP client.
</p>
<p>
If you need to configure your network connection either because you need
specific DHCP options or because you do not use DHCP at all, open
<span class="path" dir="ltr">/etc/conf.d/net</span> with your favorite editor (<span class="code" dir="ltr">nano</span> is used in
this example):
</p>
<a name="book_part1_chap8__chap2_pre5"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.5: Opening /etc/conf.d/net for editing</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">nano -w /etc/conf.d/net</span>
</pre></td></tr>
</table>
<p>
To enter your own IP address, netmask and gateway, you need
to set both <span class="code" dir="ltr">config_eth0</span> and <span class="code" dir="ltr">routes_eth0</span>:
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
This assumes that your network interface will be called eth0. This is, however,
very system dependent. It is recommended to assume that the interface is named
the same as the interface name when booted from the installation media <span class="emphasis">if</span>
the installation media is sufficiently recent. More information can be found in
<a href="#book_part4_chap2__chap4">Network Interface Naming</a>.
</p></td></tr></table>
<a name="book_part1_chap8__chap2_pre6"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.6: Manually setting IP information for eth0</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
config_eth0="192.168.0.2 netmask 255.255.255.0 brd 192.168.0.255"
routes_eth0="default via 192.168.0.1"
</pre></td></tr>
</table>
<p>
To use DHCP, define <span class="code" dir="ltr">config_eth0</span>:
</p>
<a name="book_part1_chap8__chap2_pre7"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.7: Automatically obtaining an IP address for eth0</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
config_eth0="dhcp"
</pre></td></tr>
</table>
<p>
Please read <span class="path" dir="ltr">/usr/share/doc/netifrc-*/net.example.bz2</span> for a
list of all available options. Be sure to also read your DHCP client manpage if
you need to set specific DHCP options.
</p>
<p>
If you have several network interfaces repeat the above steps for
<span class="code" dir="ltr">config_eth1</span>, <span class="code" dir="ltr">config_eth2</span>, etc.
</p>
<p>
Now save the configuration and exit to continue.
</p>
<p class="secthead"><a name="book_part1_chap8__chap2_sect3">Automatically Start Networking at Boot</a></p>
<p>
To have your network interfaces activated at boot, you need to add them to the
default runlevel.
</p>
<a name="book_part1_chap8__chap2_pre8"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.8: Adding net.eth0 to the default runlevel</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">cd /etc/init.d</span>
# <span class="code-input">ln -s net.lo net.eth0</span>
# <span class="code-input">rc-update add net.eth0 default</span>
</pre></td></tr>
</table>
<p>
If you have several network interfaces, you need to create the appropriate
<span class="path" dir="ltr">net.*</span> files just like you did with <span class="path" dir="ltr">net.eth0</span>.
</p>
<p>
If you later find out the assumption about the network interface name (which we
currently document as eth0) was wrong, then
</p>
<ol>
<li>
update the <span class="path" dir="ltr">/etc/conf.d/net</span> file with the correct interface name (like enp3s0
instead of eth0),
</li>
<li>
create new symbolic link (like <span class="path" dir="ltr">/etc/init.d/net.enp3s0</span>),
</li>
<li>
remove the old symbolic link (<span class="code" dir="ltr">rm /etc/init.d/net.eth0</span>),
</li>
<li>
add the new one to the default runlevel, and
</li>
<li>
remove the old one using <span class="code" dir="ltr">rc-update del net.eth0 default</span>.
</li>
</ol>
<p class="secthead"><a name="book_part1_chap8__chap2_sect4">Writing Down Network Information</a></p>
<p>
You now need to inform Linux about your network. This is defined in
<span class="path" dir="ltr">/etc/hosts</span> and helps in resolving host names to IP addresses for
hosts that aren't resolved by your nameserver. You need to define your system.
You may also want to define other systems on your network if you don't want to
set up your own internal DNS system.
</p>
<a name="book_part1_chap8__chap2_pre9"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.9: Opening /etc/hosts</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">nano -w /etc/hosts</span>
</pre></td></tr>
</table>
<a name="book_part1_chap8__chap2_pre10"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.10: Filling in the networking information</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment">(This defines the current system)</span>
127.0.0.1 tux.homenetwork tux localhost
<span class="code-comment">(Define extra systems on your network,
they need to have a static IP to be defined this way.)</span>
192.168.0.5 jenny.homenetwork jenny
192.168.0.6 benny.homenetwork benny
</pre></td></tr>
</table>
<p>
Save and exit the editor to continue.
</p>
<p>
If you don't have PCMCIA, you can now continue with <a href="#sysinfo">System Information</a>. PCMCIA-users should read the
following topic on PCMCIA.
</p>
<p class="secthead"><a name="book_part1_chap8__chap2_sect5">Optional: Get PCMCIA Working</a></p>
<p>
PCMCIA users should first install the <span class="code" dir="ltr">pcmciautils</span> package.
</p>
<a name="book_part1_chap8__chap2_pre11"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.11: Installing pcmciautils</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge pcmciautils</span>
</pre></td></tr>
</table>
<p class="chaphead"><a name="sysinfo"></a><a name="book_part1_chap8__chap3"></a><span class="chapnum">8.c. </span>System Information</p>
<p class="secthead"><a name="book_part1_chap8__chap3_sect1">Root Password</a></p>
<p>
First we set the root password by typing:
</p>
<a name="book_part1_chap8__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: Setting the root password</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">passwd</span>
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part1_chap8__chap3_sect2">System Information</a></p>
<p>
Gentoo uses <span class="path" dir="ltr">/etc/rc.conf</span> to configure the services, startup,
and shutdown of your system. Open up <span class="path" dir="ltr">/etc/rc.conf</span> and enjoy all
the comments in the file.
</p>
<a name="book_part1_chap8__chap3_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.2: Configuring services</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">nano -w /etc/rc.conf</span>
</pre></td></tr>
</table>
<p>
When you're finished configuring these two files, save them and exit.
</p>
<p>
Gentoo uses <span class="path" dir="ltr">/etc/conf.d/keymaps</span> to handle keyboard configuration.
Edit it to configure your keyboard.
</p>
<a name="book_part1_chap8__chap3_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.3: Opening /etc/conf.d/keymaps</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">nano -w /etc/conf.d/keymaps</span>
</pre></td></tr>
</table>
<p>
Take special care with the <span class="code" dir="ltr">keymap</span> variable. If you select the wrong
<span class="code" dir="ltr">keymap</span>, you will get weird results when typing on your keyboard.
</p>
<p>
When you're finished configuring <span class="path" dir="ltr">/etc/conf.d/keymaps</span>, save and
exit.
</p>
<p>
Gentoo uses <span class="path" dir="ltr">/etc/conf.d/hwclock</span> to set clock options. Edit it
according to your needs.
</p>
<a name="book_part1_chap8__chap3_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.4: Opening /etc/conf.d/hwclock</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">nano -w /etc/conf.d/hwclock</span>
</pre></td></tr>
</table>
<p>
If your hardware clock is not using UTC, you need to add <span class="code" dir="ltr">clock="local"</span>
to the file. Otherwise you will notice some clock skew.
</p>
<p>
When you're finished configuring <span class="path" dir="ltr">/etc/conf.d/hwclock</span>, save and
exit.
</p>
<a name="book_part1_chap9"></a><h3>9. Installing Necessary System Tools</h3>
<p class="chaphead"><a name="book_part1_chap9__chap1"></a><span class="chapnum">9.a. </span>System Logger</p>
<p>
Some tools are missing from the <span class="emphasis">stage3</span> archive because several packages
provide the same functionality. It is now up to you to choose which ones you
want to install.
</p>
<p>
The first tool you need to decide on has to provide logging facilities for your
system. Unix and Linux have an excellent history of logging capabilities -- if
you want you can log everything that happens on your system in logfiles. This
happens through the <span class="emphasis">system logger</span>.
</p>
<p>
Gentoo offers several system loggers to choose from. There are <span class="code" dir="ltr">sysklogd</span>,
which is the traditional set of system logging daemons, <span class="code" dir="ltr">syslog-ng</span>, an
advanced system logger, and <span class="code" dir="ltr">metalog</span> which is a highly-configurable
system logger. Others might be available through Portage as well - our number of
available packages increases on a daily basis.
</p>
<p>
If you plan on using <span class="code" dir="ltr">sysklogd</span> or <span class="code" dir="ltr">syslog-ng</span> you might want to
install <span class="code" dir="ltr">logrotate</span> afterwards as those system loggers don't provide any
rotation mechanism for the log files.
</p>
<p>
To install the system logger of your choice, <span class="code" dir="ltr">emerge</span> it and have it added
to the default runlevel using <span class="code" dir="ltr">rc-update</span>. The following example installs
<span class="code" dir="ltr">syslog-ng</span>. Of course substitute with your system logger:
</p>
<a name="book_part1_chap9__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: Installing a system logger</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge syslog-ng</span>
# <span class="code-input">rc-update add syslog-ng default</span>
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part1_chap9__chap2"></a><span class="chapnum">9.b. </span>Optional: Cron Daemon</p>
<p>
Next is the cron daemon. Although it is optional and not required for your
system, it is wise to install one. But what is a cron daemon? A cron daemon
executes scheduled commands. It is very handy if you need to execute some
command regularly (for instance daily, weekly or monthly).
</p>
<p>
Gentoo offers several possible cron daemons, including <span class="code" dir="ltr">bcron</span>,
<span class="code" dir="ltr">dcron</span>, <span class="code" dir="ltr">fcron</span> and <span class="code" dir="ltr">cronie</span>. Installing one of them
is similar to installing a system logger. However, <span class="code" dir="ltr">dcron</span> and
<span class="code" dir="ltr">fcron</span> require an extra configuration command, namely <span class="code" dir="ltr">crontab
/etc/crontab</span>. If you don't know what to choose, use <span class="code" dir="ltr">cronie</span>.
</p>
<a name="book_part1_chap9__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: Installing a cron daemon</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge cronie</span>
# <span class="code-input">rc-update add cronie default</span>
<span class="code-comment">(Only if you have chosen dcron or fcron)</span> # <span class="code-input">crontab /etc/crontab</span>
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part1_chap9__chap3"></a><span class="chapnum">9.c. </span>Optional: File Indexing</p>
<p>
If you want to index your system's files so you are able to quickly
locate them using the <span class="code" dir="ltr">locate</span> tool, you need to install
<span class="code" dir="ltr">sys-apps/mlocate</span>.
</p>
<a name="book_part1_chap9__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: Installing mlocate</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge mlocate</span>
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part1_chap9__chap4"></a><span class="chapnum">9.d. </span>Optional: Remote Access</p>
<p>
If you need to access your system remotely after installation, don't forget to
add <span class="code" dir="ltr">sshd</span> to the default runlevel:
</p>
<a name="book_part1_chap9__chap4_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.1: Adding sshd to the default runlevel</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">rc-update add sshd default</span>
</pre></td></tr>
</table>
<p>
If you need serial console access (which is possible in case of remote servers),
you might need to uncomment the serial console section in
<span class="path" dir="ltr">/etc/inittab</span> if it has not been done already automatically.
</p>
<a name="book_part1_chap9__chap4_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.2: Editing /etc/inittab</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">nano -w /etc/inittab</span>
</pre></td></tr>
</table>
<p>
The following excerpt shows the uncommented section:
</p>
<a name="book_part1_chap9__chap4_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.3: Uncommenting serial consoles in inittab</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment"># SERIAL CONSOLES</span>
s0:12345:respawn:/sbin/agetty 9600 ttyS0 vt100
s1:12345:respawn:/sbin/agetty 9600 ttyS1 vt100
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part1_chap9__chap5"></a><span class="chapnum">9.e. </span>File System Tools</p>
<p>
Depending on what file systems you are using, you need to install the necessary
file system utilities (for checking the filesystem integrity, creating
additional file systems etc.). Please note that tools for managing ext2, ext3 or
ext4 filesystems (<span class="code" dir="ltr">e2fsprogs</span>) are already installed as a part of the system.
</p>
<p>
The following table lists the tools you need to install if you use a certain
file system:
</p>
<table class="ntable">
<tr>
<td class="infohead"><b>File System</b></td>
<td class="infohead"><b>Tool</b></td>
<td class="infohead"><b>Install Command</b></td>
</tr>
<tr>
<td class="tableinfo">XFS</td>
<td class="tableinfo">xfsprogs</td>
<td class="tableinfo"><span class="code" dir="ltr">emerge xfsprogs</span></td>
</tr>
<tr>
<td class="tableinfo">ReiserFS</td>
<td class="tableinfo">reiserfsprogs</td>
<td class="tableinfo"><span class="code" dir="ltr">emerge reiserfsprogs</span></td>
</tr>
<tr>
<td class="tableinfo">JFS</td>
<td class="tableinfo">jfsutils</td>
<td class="tableinfo"><span class="code" dir="ltr">emerge jfsutils</span></td>
</tr>
</table>
<p class="chaphead"><a name="networking-tools"></a><a name="book_part1_chap9__chap6"></a><span class="chapnum">9.f. </span>Networking Tools</p>
<p>
If you don't require any additional networking-related tools (such as ppp or a
dhcp client) continue with <a href="#book_part1_chap10">Configuring the
Bootloader</a>.
</p>
<p class="secthead"><a name="book_part1_chap9__chap6_sect2">Optional: Installing a DHCP Client</a></p>
<p>
If you require Gentoo to automatically obtain an IP address for your network
interface(s), you need to install <span class="code" dir="ltr">dhcpcd</span> (or any other DHCP client --
see <a href="#book_part4_chap3">Modular Networking</a> for a list of
available DHCP clients). If you don't do this now, you might not be able to
connect to the internet after the installation.
</p>
<a name="book_part1_chap9__chap6_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 6.1: Installing dhcpcd</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge dhcpcd</span>
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part1_chap9__chap6_sect3">Optional: Installing a PPPoE Client</a></p>
<p>
If you need <span class="code" dir="ltr">ppp</span> to connect to the net, you need to install it.
</p>
<a name="book_part1_chap9__chap6_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 6.2: Installing ppp</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge ppp</span>
</pre></td></tr>
</table>
<p>
Now continue with <a href="#book_part1_chap10">Configuring the
Bootloader</a>.
</p>
<a name="book_part1_chap10"></a><h3>10. Configuring the Bootloader</h3>
<p class="chaphead"><a name="book_part1_chap10__chap1"></a><span class="chapnum">10.a. </span>Making your Choice</p>
<p class="secthead"><a name="book_part1_chap10__chap1_sect1">Introduction</a></p>
<p>
Now that your kernel is configured and compiled and the necessary system
configuration files are filled in correctly, it is time to install a
program that will fire up your kernel when you start the system. Such a
program is called a <span class="emphasis">bootloader</span>.
</p>
<p>
For x86, Gentoo Linux provides <a href="#grub2">GRUB2</a>, <a href="#lilo">LILO</a> and
<a href="#grub">GRUB Legacy</a>.
</p>
<p class="chaphead"><a name="grub2"></a><a name="book_part1_chap10__chap2"></a><span class="chapnum">10.b. </span>Default: Using GRUB2</p>
<p class="secthead"><a name="book_part1_chap10__chap2_sect1">Installing GRUB2</a></p>
<p>
GRUB2 is provided through the <span class="code" dir="ltr">sys-boot/grub</span> package.
</p>
<a name="book_part1_chap10__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: Installing GRUB2</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge sys-boot/grub</span>
</pre></td></tr>
</table>
<p>
The GRUB2 software is now installed on the system, but not activated yet.
</p>
<p class="secthead"><a name="book_part1_chap10__chap2_sect2">Configuring GRUB2</a></p>
<p>
First, let us install the necessary GRUB2 files in <span class="path" dir="ltr">/boot/grub</span>.
Assuming the first disk (the one where the system boots from) is
<span class="path" dir="ltr">/dev/sda</span>, the following command will do this for us:
</p>
<a name="book_part1_chap10__chap2_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.2: Installing the GRUB2 files in /boot/grub</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">grub2-install /dev/sda</span>
</pre></td></tr>
</table>
<p>
Next, we can generate the GRUB2 configuration based on the user configuration
specified in the <span class="path" dir="ltr">/etc/default/grub</span> file and
<span class="path" dir="ltr">/etc/grub.d</span> scripts. In most cases, no configuration is needed
by users as GRUB2 will automatically detect which kernel to boot (the highest
one available in <span class="path" dir="ltr">/boot</span>) and what the root file system is.
</p>
<p>
To generate the final GRUB2 configuration, run the <span class="code" dir="ltr">grub2-mkconfig</span>
command:
</p>
<a name="book_part1_chap10__chap2_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.3: Generating GRUB2 configuration</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">grub2-mkconfig -o /boot/grub/grub.cfg</span>
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.12.20-gentoo
Found initrd image: /boot/initramfs-genkernel-x86-3.12.20-gentoo
done
</pre></td></tr>
</table>
<p>
The output of the command <span class="emphasis">must</span> mention that at least one Linux image is
found, as those are needed to boot the system. If you use initramfs or used
<span class="code" dir="ltr">genkernel</span> to build the kernel, the correct initrd image should be
detected as well. If this is not the case, go to <span class="path" dir="ltr">/boot</span> and check
the contents using the <span class="code" dir="ltr">ls</span> command. If the files are indeed missing, go
back to the kernel configuration and installation instructions.
</p>
<p class="chaphead"><a name="lilo"></a><a name="book_part1_chap10__chap3"></a><span class="chapnum">10.c. </span>Alternative: Using LILO</p>
<p class="secthead"><a name="book_part1_chap10__chap3_sect1">Installing LILO</a></p>
<p>
LILO, the LInuxLOader, is the tried and true workhorse of Linux
bootloaders. However, it lacks some features that GRUB has (which is
also the reason why GRUB is currently gaining popularity). The reason
why LILO is still used is that, on some systems, GRUB doesn't work and
LILO does. Of course, it is also used because some people know LILO and
want to stick with it. Either way, Gentoo supports both, and apparently
you have chosen to use LILO.
</p>
<p>
Installing LILO is a breeze; just use <span class="code" dir="ltr">emerge</span>.
</p>
<a name="book_part1_chap10__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: Installing LILO</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge lilo</span>
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part1_chap10__chap3_sect2">Configuring LILO</a></p>
<p>
To configure LILO, you must create <span class="path" dir="ltr">/etc/lilo.conf</span>. Fire up
your favorite editor (in this handbook we use <span class="code" dir="ltr">nano</span> for
consistency) and create the file.
</p>
<a name="book_part1_chap10__chap3_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.2: Creating /etc/lilo.conf</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">nano -w /etc/lilo.conf</span>
</pre></td></tr>
</table>
<p>
Some sections ago we have asked you to remember the kernel-image name
you have created. In the next example <span class="path" dir="ltr">lilo.conf</span> we use the
example partitioning scheme.
</p>
<p>
Make sure you use <span class="emphasis">your</span> kernel image filename and, if appropriate,
<span class="emphasis">your</span> initrd image filename.
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
If your root filesystem is JFS, you <span class="emphasis">must</span> add a <span class="code" dir="ltr">append="ro"</span>
line after each boot item since JFS needs to replay its log before it allows
read-write mounting.
</p></td></tr></table>
<a name="book_part1_chap10__chap3_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.3: Example /etc/lilo.conf</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
boot=/dev/sda <span class="code-comment"># Install LILO in the MBR</span>
prompt <span class="code-comment"># Give the user the chance to select another section</span>
timeout=50 <span class="code-comment"># Wait 5 (five) seconds before booting the default section</span>
default=gentoo <span class="code-comment"># When the timeout has passed, boot the "gentoo" section</span>
image=/boot/vmlinuz-3.12.20-gentoo
label=gentoo <span class="code-comment"># Name we give to this section</span>
read-only <span class="code-comment"># Start with a read-only root. Do not alter!</span>
root=/dev/sda4 <span class="code-comment"># Location of the root filesystem</span>
image=/boot/vmlinuz-3.12.20-gentoo
label=gentoo.rescue <span class="code-comment"># Name we give to this section</span>
read-only <span class="code-comment"># Start with a read-only root. Do not alter!</span>
root=/dev/sda4 <span class="code-comment"># Location of the root filesystem</span>
append="init=/bin/bb" <span class="code-comment"># Launch the Gentoo static rescue shell</span>
<span class="code-comment"># The next two lines are only if you dualboot with a Windows system.</span>
<span class="code-comment"># In this example, Windows is hosted on /dev/sda6.</span>
other=/dev/sda6
label=windows
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
If you use a different partitioning scheme and/or kernel image, adjust
accordingly.
</p></td></tr></table>
<p>
If, while building the Linux kernel, you opted to include an initramfs to boot
from, then you will need to change the configuration by referring to this
initramfs file and telling the initramfs where your real root device is at:
</p>
<a name="book_part1_chap10__chap3_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.4: LILO snippet for initramfs-enabled kernel builds</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
image=/boot/vmlinuz-3.12.20-gentoo
label=gentoo
read-only
<span class="code-input">append="real_root=/dev/sda4"</span>
<span class="code-input">initrd=/boot/initramfs-genkernel-x86-3.12.20-gentoo</span>
</pre></td></tr>
</table>
<p>
If you need to pass any additional options to the kernel, add an
<span class="code" dir="ltr">append</span> statement to the section. As an example, we add the
<span class="code" dir="ltr">video</span> statement to enable framebuffer:
</p>
<a name="book_part1_chap10__chap3_pre5"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.5: Using append to add kernel options</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
image=/boot/vmlinuz-3.12.20-gentoo
label=gentoo
read-only
root=/dev/sda4
<span class="code-input">append="video=uvesafb:mtrr,ywrap,1024x768-32@85"</span>
</pre></td></tr>
</table>
<p>
If you're using a 2.6.7 or higher kernel and you jumpered your harddrive
because the BIOS can't handle large harddrives you'll need to append
<span class="code" dir="ltr">sda=stroke</span>. Replace sda with the device that requires this option.
</p>
<p>
<span class="code" dir="ltr">genkernel</span> users should know that their kernels use the same boot options
as is used for the Installation CD. For instance, if you have SCSI devices, you
should add <span class="code" dir="ltr">doscsi</span> as kernel option.
</p>
<p>
Now save the file and exit. To finish up, you have to run <span class="code" dir="ltr">/sbin/lilo</span> so
LILO can apply the <span class="path" dir="ltr">/etc/lilo.conf</span> to your system (i.e. install
itself on the disk). Keep in mind that you'll also have to run
<span class="code" dir="ltr">/sbin/lilo</span> every time you install a new kernel or make any changes to
the menu.
</p>
<a name="book_part1_chap10__chap3_pre6"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.6: Finishing the LILO installation</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">/sbin/lilo</span>
</pre></td></tr>
</table>
<p>
If you have more questions regarding LILO, please consult its <a href="http://en.wikipedia.org/wiki/LILO_(boot_loader)">wikipedia page</a>.
</p>
<p>
You can now continue with <a href="#reboot">Rebooting the System</a>.
</p>
<p class="chaphead"><a name="grub"></a><a name="book_part1_chap10__chap4"></a><span class="chapnum">10.d. </span>Alternative: Using GRUB Legacy</p>
<p class="secthead"><a name="book_part1_chap10__chap4_sect1">What is Legacy?</a></p>
<p>
GRUB has been reworked and a new release dubbed GRUB2 is made available. The new
GRUB2 codebase is quite different from the current GRUB, which is why this GRUB
version is now dubbed as "GRUB Legacy".
</p>
<p class="secthead"><a name="book_part1_chap10__chap4_sect2">Understanding GRUB's terminology</a></p>
<p>
The most critical part of understanding GRUB is getting comfortable with how
GRUB refers to hard drives and partitions. Your Linux partition
<span class="path" dir="ltr">/dev/sda2</span> will most likely be called <span class="path" dir="ltr">(hd0,1)</span> under
GRUB. Notice the parentheses around the <span class="path" dir="ltr">hd0,1</span> - they are
required.
</p>
<p>
Hard drives count from zero rather than "a" and partitions start at zero
rather than one. Be aware too that with the hd devices, only hard drives are
counted, not atapi-ide devices such as cdrom players and burners. Also, the
same construct is used with SCSI drives. (Normally they get higher numbers
than IDE drives except when the BIOS is configured to boot from SCSI devices.)
When you ask the BIOS to boot from a different hard disk (for instance your
primary slave), <span class="emphasis">that</span> harddisk is seen as <span class="path" dir="ltr">hd0</span>.
</p>
<p>
Assuming you have a hard drive on <span class="path" dir="ltr">/dev/sda</span> and two more on
<span class="path" dir="ltr">/dev/sdb</span> and <span class="path" dir="ltr">/dev/sdc</span>, <span class="path" dir="ltr">/dev/sdb7</span> gets
translated to <span class="path" dir="ltr">(hd1,6)</span>. It might sound tricky and tricky it is
indeed, but as we will see, GRUB offers a tab completion mechanism that comes
handy for those of you having a lot of hard drives and partitions and who are a
little lost in the GRUB numbering scheme.
</p>
<p>
Having gotten the feel for that, it is time to install GRUB.
</p>
<p class="secthead"><a name="book_part1_chap10__chap4_sect3">Installing GRUB</a></p>
<p>
To install GRUB Legacy, let's first emerge it:
</p>
<a name="book_part1_chap10__chap4_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.1: Installing GRUB</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge sys-boot/grub:0</span>
</pre></td></tr>
</table>
<p>
Although GRUB is now installed, we still need to write up a
configuration file for it and place GRUB in our MBR so that GRUB automatically
boots your newly created kernel. Create <span class="path" dir="ltr">/boot/grub/grub.conf</span> with
<span class="code" dir="ltr">nano</span> (or, if applicable, another editor):
</p>
<a name="book_part1_chap10__chap4_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.2: Creating /boot/grub/grub.conf</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">nano -w /boot/grub/grub.conf</span>
</pre></td></tr>
</table>
<p>
Now we are going to write up a <span class="path" dir="ltr">grub.conf</span>. Make
sure you use <span class="emphasis">your</span> kernel image filename and, if appropriate, <span class="emphasis">your</span>
initrd image filename.
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
Grub assigns device designations from the BIOS. If you change your BIOS
settings, your device letters and numbers may change, too. For example, if you
change your device boot order, you may need to change your grub configuration.
</p></td></tr></table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
If your root filesystem is JFS, you <span class="emphasis">must</span> add " ro" to the <span class="code" dir="ltr">kernel</span>
line since JFS needs to replay its log before it allows read-write mounting.
</p></td></tr></table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
If dualboot with Windows is used, the partitioning example used in this
book will not be sufficient (our example uses all four primary partitions
for Linux, whereas at least one would need to be extended if Windows is
installed on a logical partition). Please proceed with caution and consider
the listing to be an example that needs to be modified to suit your own needs.
</p></td></tr></table>
<a name="book_part1_chap10__chap4_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.3: Example grub.conf</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment"># Which listing to boot as default. 0 is the first, 1 the second etc.</span>
default 0
<span class="code-comment"># How many seconds to wait before the default listing is booted.</span>
timeout 30
<span class="code-comment"># Nice, fat splash-image to spice things up :)
# Comment out if you don't have a graphics card installed</span>
splashimage=(hd0,1)/boot/grub/splash.xpm.gz
title Gentoo Linux 3.12.20
<span class="code-comment"># Partition where the kernel image (or operating system) is located</span>
root (hd0,1)
kernel /boot/vmlinuz-3.12.20-gentoo root=/dev/sda4
title Gentoo Linux 3.12.20 (rescue)
<span class="code-comment"># Partition where the kernel image (or operating system) is located</span>
root (hd0,1)
kernel /boot/vmlinuz-3.12.20-gentoo root=/dev/sda4 init=/bin/bb
<span class="code-comment"># The next four lines are only if you dualboot with a Windows system.</span>
<span class="code-comment"># In this case, Windows is hosted on /dev/sda6.</span>
title Windows XP
rootnoverify (hd0,5)
makeactive
chainloader +1
</pre></td></tr>
</table>
<p>
If, while building the Linux kernel, you opted to include an initramfs to boot
from, then you will need to change the configuration by referring to this
initramfs file and telling the initramfs where your real root device is at:
</p>
<a name="book_part1_chap10__chap4_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.4: GRUB snippet for initramfs-enabled kernel builds</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
title Gentoo Linux 3.12.20
root (hd0,1)
kernel /boot/3.12.20 <span class="code-input">real_</span>root=/dev/sda4
<span class="code-input">initrd /boot/initramfs-genkernel-x86-3.12.20-gentoo</span>
</pre></td></tr>
</table>
<p>
If you used a different partitioning scheme and/or kernel image, adjust
accordingly. However, make sure that anything that follows a GRUB-device (such
as <span class="path" dir="ltr">(hd0,1)</span>) is relative to the mountpoint, not the root. In other
words, <span class="path" dir="ltr">(hd0,1)/grub/splash.xpm.gz</span> is in reality
<span class="path" dir="ltr">/boot/grub/splash.xpm.gz</span> since <span class="path" dir="ltr">(hd0,1)</span> is
<span class="path" dir="ltr">/boot</span>.
</p>
<p>
Besides, if you chose to use a different partitioning scheme and did not put
<span class="path" dir="ltr">/boot</span> in a separate partition, the <span class="path" dir="ltr">/boot</span> prefix used
in the above code samples is really <span class="emphasis">required</span>. If you followed our
suggested partitioning plan, the <span class="path" dir="ltr">/boot</span> prefix it not required, but
a <span class="path" dir="ltr">boot</span> symlink makes it work. In short, the above examples should
work whether you defined a separate <span class="path" dir="ltr">/boot</span> partition or not.
</p>
<p>
If you need to pass any additional options to the kernel, simply add them to the
end of the kernel command. We're already passing one option
(<span class="code" dir="ltr">root=/dev/sda4</span> or <span class="code" dir="ltr">real_root=/dev/sda4</span>), but you can pass others
as well, such as the <span class="code" dir="ltr">video</span> statement for framebuffer as we discussed
previously.
</p>
<p>
If your bootloader configuration file contains the real_root parameter, use the
real_rootflags parameter to set root filesystem mount options.
</p>
<p>
If you're using a 2.6.7 or higher kernel and you jumpered your harddrive
because the BIOS can't handle large harddrives you'll need to append
<span class="code" dir="ltr">sda=stroke</span>. Replace sda with the device that requires this option.
</p>
<p>
<span class="code" dir="ltr">genkernel</span> users should know that their kernels use the same boot options
as is used for the Installation CD. For instance, if you have SCSI devices, you
should add <span class="code" dir="ltr">doscsi</span> as kernel option.
</p>
<p>
Now save the <span class="path" dir="ltr">grub.conf</span> file and exit. You still need to install
GRUB in the MBR (Master Boot Record) so that GRUB is automatically executed when
you boot your system.
</p>
<p>
The GRUB developers recommend the use of <span class="code" dir="ltr">grub-install</span>. However, if for
some reason <span class="code" dir="ltr">grub-install</span> fails to work correctly you still have the
option to manually install GRUB.
</p>
<p>
Continue with <a href="#grub-install-auto">Default: Setting up GRUB using
grub-install</a> or <a href="#grub-install-manual">Alternative: Setting up
GRUB using manual instructions</a>.
</p>
<p class="secthead"><a name="grub-install-auto"></a><a name="book_part1_chap10__chap4_sect4">Default: Setting up GRUB using grub-install</a></p>
<p>
To install GRUB you will need to issue the <span class="code" dir="ltr">grub-install</span> command.
However, <span class="code" dir="ltr">grub-install</span> won't work off-the-shelf since we are inside a
chrooted environment. We need to create <span class="path" dir="ltr">/etc/mtab</span> which lists all
mounted filesystems. Fortunately, there is an easy way to accomplish this -
just copy over <span class="path" dir="ltr">/proc/mounts</span> to <span class="path" dir="ltr">/etc/mtab</span>, excluding
the <span class="code" dir="ltr">rootfs</span> line if you haven't created a separate boot partition. The
following command will work in both cases:
</p>
<a name="book_part1_chap10__chap4_pre5"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.5: Creating /etc/mtab</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">grep -v rootfs /proc/mounts &gt; /etc/mtab</span>
</pre></td></tr>
</table>
<p>
When using Linux virtio disks, we need to tell grub where to find the disks as
the <span class="code" dir="ltr">grub-install</span> command will otherwise fail. This is done by adding the
device definition to the <span class="path" dir="ltr">device.map</span> file:
</p>
<a name="book_part1_chap10__chap4_pre6"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.6: Adding the virtio disk to the device map table</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">echo "(hd0) /dev/vda" &gt;&gt; /boot/grub/device.map</span>
</pre></td></tr>
</table>
<p>
Now we can install GRUB using <span class="code" dir="ltr">grub-install</span>:
</p>
<a name="book_part1_chap10__chap4_pre7"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.7: Running grub-install</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">grub-install --no-floppy /dev/sda</span>
</pre></td></tr>
</table>
<p>
If you have more questions regarding GRUB, please consult the <a href="http://www.gnu.org/software/grub/grub-faq.html">GRUB FAQ</a>, the <a href="http://grub.enbug.org/GrubLegacy">GRUB Wiki</a>, or read <span class="code" dir="ltr">info
grub</span> in your terminal.
</p>
<p>
Continue with <a href="#reboot">Rebooting the System</a>.
</p>
<p class="secthead"><a name="grub-install-manual"></a><a name="book_part1_chap10__chap4_sect5">Alternative: Setting up GRUB using manual instructions</a></p>
<p>
To start configuring GRUB, you type in <span class="code" dir="ltr">grub</span>. You'll be presented
with the <span class="path" dir="ltr">grub&gt;</span> grub command-line prompt. Now, you need to type
in the right commands to install the GRUB boot record onto your hard drive.
</p>
<a name="book_part1_chap10__chap4_pre8"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.8: Starting the GRUB shell</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">grub --no-floppy</span>
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
If your system does not have any floppy drives, add the <span class="code" dir="ltr">--no-floppy</span>
option to the above command to prevent grub from probing the (non-existing)
floppy drives.
</p></td></tr></table>
<p>
In the example configuration we want to install GRUB so that it reads its
information from the boot partition <span class="path" dir="ltr">/dev/sda2</span>, and
installs the GRUB boot record on the hard drive's MBR (master boot record) so
that the first thing we see when we turn on the computer is the GRUB prompt. Of
course, if you haven't followed the example configuration during the
installation, change the commands accordingly.
</p>
<p>
The tab completion mechanism of GRUB can be used from within GRUB.
For instance, if you type in "<span class="code" dir="ltr">root (</span>" followed by a TAB, you will
be presented with a list of devices (such as <span class="path" dir="ltr">hd0</span>). If you
type in "<span class="code" dir="ltr">root (hd0,</span>" followed by a TAB, you will receive a list
of available partitions to choose from (such as <span class="path" dir="ltr">hd0,1</span>).
</p>
<p>
By using the tab completion, setting up GRUB should be not that hard.
Now go on, configure GRUB, shall we? :-)
</p>
<a name="book_part1_chap10__chap4_pre9"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.9: Installing GRUB in the MBR</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
grub&gt; <span class="code-input">root (hd0,1)</span> <span class="code-comment">(Specify where your /boot partition resides)</span>
grub&gt; <span class="code-input">setup (hd0)</span> <span class="code-comment">(Install GRUB in the MBR)</span>
grub&gt; <span class="code-input">quit</span> <span class="code-comment">(Exit the GRUB shell)</span>
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
If you want to install GRUB in a certain partition instead of the MBR,
you have to alter the <span class="code" dir="ltr">setup</span> command so it points to the right
partition. For instance, if you want GRUB installed in
<span class="path" dir="ltr">/dev/sda4</span>, then the command becomes <span class="code" dir="ltr">setup (hd0,3)</span>.
Few users however want to do this.
</p></td></tr></table>
<p>
If you have more questions regarding GRUB, please consult the <a href="http://www.gnu.org/software/grub/grub-faq.html">GRUB FAQ</a>, the <a href="http://grub.enbug.org/GrubLegacy">GRUB Wiki</a>, or read <span class="code" dir="ltr">info
grub</span> in your terminal.
</p>
<p>
Continue with <a href="#reboot">Rebooting the System</a>.
</p>
<p class="chaphead"><a name="reboot"></a><a name="book_part1_chap10__chap5"></a><span class="chapnum">10.e. </span>Rebooting the System</p>
<p>
Exit the chrooted environment and unmount all mounted partitions. Then type in
that one magical command you have been waiting for: <span class="code" dir="ltr">reboot</span>.
</p>
<a name="book_part1_chap10__chap5_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.1: Unmounting all partitions and rebooting</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">exit</span>
cdimage ~# <span class="code-input">cd</span>
cdimage ~# <span class="code-input">umount -l /mnt/gentoo/dev{/shm,/pts,}</span>
cdimage ~# <span class="code-input">umount /mnt/gentoo{/boot,/sys,/proc,}</span>
cdimage ~# <span class="code-input">reboot</span>
</pre></td></tr>
</table>
<p>
Of course, don't forget to remove the bootable CD, otherwise the CD will be
booted again instead of your new Gentoo system.
</p>
<p>
Once rebooted in your Gentoo installation, finish up with <a href="#book_part1_chap11">Finalizing your Gentoo Installation</a>.
</p>
<a name="book_part1_chap11"></a><h3>11. Finalizing your Gentoo Installation</h3>
<p class="chaphead"><a name="book_part1_chap11__chap1"></a><span class="chapnum">11.a. </span>User Administration</p>
<p class="secthead"><a name="book_part1_chap11__chap1_sect1">Adding a User for Daily Use</a></p>
<p>
Working as root on a Unix/Linux system is <span class="emphasis">dangerous</span> and should be avoided
as much as possible. Therefore it is <span class="emphasis">strongly</span> recommended to add a user
for day-to-day use.
</p>
<p>
The groups the user is member of define what activities the user can perform.
The following table lists a number of important groups you might wish to use:
</p>
<table class="ntable">
<tr>
<td class="infohead"><b>Group</b></td>
<td class="infohead"><b>Description</b></td>
</tr>
<tr>
<td class="tableinfo">audio</td>
<td class="tableinfo">be able to access the audio devices</td>
</tr>
<tr>
<td class="tableinfo">cdrom</td>
<td class="tableinfo">be able to directly access optical devices</td>
</tr>
<tr>
<td class="tableinfo">floppy</td>
<td class="tableinfo">be able to directly access floppy devices</td>
</tr>
<tr>
<td class="tableinfo">games</td>
<td class="tableinfo">be able to play games</td>
</tr>
<tr>
<td class="tableinfo">portage</td>
<td class="tableinfo">be able to use <span class="code" dir="ltr">emerge --pretend</span> as a normal user</td>
</tr>
<tr>
<td class="tableinfo">usb</td>
<td class="tableinfo">be able to access USB devices</td>
</tr>
<tr>
<td class="tableinfo">video</td>
<td class="tableinfo">
be able to access video capturing hardware and doing hardware
acceleration
</td>
</tr>
<tr>
<td class="tableinfo">wheel</td>
<td class="tableinfo">be able to use <span class="code" dir="ltr">su</span>
</td>
</tr>
</table>
<p>
For instance, to create a user called <span class="code" dir="ltr">john</span> who is member of the
<span class="code" dir="ltr">wheel</span>, <span class="code" dir="ltr">users</span> and <span class="code" dir="ltr">audio</span> groups, log in as root first
(only root can create users) and run <span class="code" dir="ltr">useradd</span>:
</p>
<a name="book_part1_chap11__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: Adding a user for day-to-day use</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
Login: <span class="code-input">root</span>
Password: <span class="code-comment">(Your root password)</span>
# <span class="code-input">useradd -m -G users,wheel,audio -s /bin/bash john</span>
# <span class="code-input">passwd john</span>
Password: <span class="code-comment">(Enter the password for john)</span>
Re-enter password: <span class="code-comment">(Re-enter the password to verify)</span>
</pre></td></tr>
</table>
<p>
If a user ever needs to perform some task as root, they can use <span class="code" dir="ltr">su -</span>
to temporarily receive root privileges. Another way is to use the <span class="code" dir="ltr">sudo</span>
package which is, if correctly configured, very secure.
</p>
<p class="chaphead"><a name="book_part1_chap11__chap2"></a><span class="chapnum">11.b. </span>Disk Cleanup</p>
<p class="secthead"><a name="book_part1_chap11__chap2_sect1">Removing tarballs</a></p>
<p>
Now that you've finished installing Gentoo and rebooted, if everything has gone
well, you can remove the downloaded stage3 tarball from
your hard disk. Remember that they were downloaded to your <span class="path" dir="ltr">/</span>
directory.
</p>
<a name="book_part1_chap11__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: Removing the stage3 tarball</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">rm /stage3-*.tar.bz2*</span>
</pre></td></tr>
</table>
<a name="book_part1_chap12"></a><h3>12. Where to go from here?</h3>
<p class="chaphead"><a name="book_part1_chap12__chap1"></a><span class="chapnum">12.a. </span>Documentation</p>
<p>
Congratulations! You now have a working Gentoo system. But where to go from
here? What are your options now? What to explore first? Gentoo provides its
users with lots of possibilities, and therefore lots of documented (and less
documented) features.
</p>
<p>
You should definitely take a look at the next part of the Gentoo Handbook
entitled <a href="#book_part2">Working with Gentoo</a> which explains
how to keep your software up to date, how to install more software, what USE
flags are, how the Gentoo init system works, etc.
</p>
<p>
We also have an official <a href="https://wiki.gentoo.org">Gentoo
Wiki</a> where additional, community-provided documentation can be found.
The documentation team also offers a
<a href="https://wiki.gentoo.org/wiki/Project:Documentation/Overview">Documentation
Overview</a>.
</p>
<p>
You might want to use our <a href="https://wiki.gentoo.org/wiki/Localization/HOWTO">localization guide</a> to make your
system feel more at home.
</p>
<p>
We also have a <a href="/doc/en/security/?style=printable">Gentoo Security Handbook</a>
which is worth reading.
</p>
<p class="chaphead"><a name="book_part1_chap12__chap2"></a><span class="chapnum">12.b. </span>Gentoo Online</p>
<p>
You are of course always welcome on our <a href="https://forums.gentoo.org">Gentoo Forums</a> or on one of our many
<a href="/main/en/irc.xml?style=printable">Gentoo IRC channels</a>.
</p>
<p>
We also have several <a href="/main/en/lists.xml?style=printable">mailing lists</a> open to all
our users. Information on how to join is contained in that page.
</p>
<p>
We'll shut up now and let you enjoy your installation. :)
</p>
<a name="book_part2"></a><h2>B. Working with Gentoo</h2>
<a name="book_part2_chap1"></a><h3>1. A Portage Introduction</h3>
<p class="chaphead"><a name="book_part2_chap1__chap1"></a><span class="chapnum">1.a. </span>Welcome to Portage</p>
<p>
Portage is probably Gentoo's most notable innovation in software management.
With its high flexibility and enormous amount of features it is frequently seen
as the best software management tool available for Linux.
</p>
<p>
Portage is completely written in <a href="http://www.python.org">Python</a>
and <a href="http://www.gnu.org/software/bash">Bash</a> and therefore fully
visible to the users as both are scripting languages.
</p>
<p>
Most users will work with Portage through the <span class="code" dir="ltr">emerge</span> tool. This chapter
is not meant to duplicate the information available from the emerge man page.
For a complete rundown of emerge's options, please consult the man page:
</p>
<a name="book_part2_chap1__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: Reading the emerge man page</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
$ <span class="code-input">man emerge</span>
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part2_chap1__chap2"></a><span class="chapnum">1.b. </span>The Portage Tree</p>
<p class="secthead"><a name="book_part2_chap1__chap2_sect1">Ebuilds</a></p>
<p>
When we talk about packages, we often mean software titles that are available to
the Gentoo users through the Portage tree. The Portage tree is a collection of
<span class="emphasis">ebuilds</span>, files that contain all information Portage needs to maintain
software (install, search, query, ...). These ebuilds reside in
<span class="path" dir="ltr">/usr/portage</span> by default.
</p>
<p>
Whenever you ask Portage to perform some action regarding software titles, it
will use the ebuilds on your system as a base. It is therefore important that
you regularly update the ebuilds on your system so Portage knows about new
software, security updates, etc.
</p>
<p class="secthead"><a name="book_part2_chap1__chap2_sect2">Updating the Portage Tree</a></p>
<p>
The Portage tree is usually updated with <a href="http://rsync.samba.org/">rsync</a>, a fast incremental file transfer
utility. Updating is fairly simple as the <span class="code" dir="ltr">emerge</span> command provides a
front-end for rsync:
</p>
<a name="book_part2_chap1__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: Updating the Portage tree</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge --sync</span>
</pre></td></tr>
</table>
<p>
If you are unable to rsync due to firewall restrictions you can still update
your Portage tree by using our daily generated Portage tree snapshots. The
<span class="code" dir="ltr">emerge-webrsync</span> tool automatically fetches and installs the latest
snapshot on your system:
</p>
<a name="book_part2_chap1__chap2_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.2: Running emerge-webrsync</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge-webrsync</span>
</pre></td></tr>
</table>
<p>
An additional advantage of using <span class="code" dir="ltr">emerge-webrsync</span> is that it allows the
administrator to only pull in portage tree snapshots that are signed by the
Gentoo release engineering GPG key. More information on this can be found
in the <a href="#book_part2_chap3">Portage Features</a> section on
<a href="#webrsync-gpg">Fetching Validated Portage Tree
Snapshots</a>.
</p>
<p class="chaphead"><a name="book_part2_chap1__chap3"></a><span class="chapnum">1.c. </span>Maintaining Software</p>
<p class="secthead"><a name="book_part2_chap1__chap3_sect1">Searching for Software</a></p>
<p>
To search through the Portage tree after software titles, you can use
<span class="code" dir="ltr">emerge</span> built-in search capabilities. By default, <span class="code" dir="ltr">emerge --search</span>
returns the names of packages whose title matches (either fully or partially)
the given search term.
</p>
<p>
For instance, to search for all packages who have "pdf" in their name:
</p>
<a name="book_part2_chap1__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: Searching for pdf-named packages</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
$ <span class="code-input">emerge --search pdf</span>
</pre></td></tr>
</table>
<p>
If you want to search through the descriptions as well you can use the
<span class="code" dir="ltr">--searchdesc</span> (or <span class="code" dir="ltr">-S</span>) switch:
</p>
<a name="book_part2_chap1__chap3_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.2: Searching for pdf-related packages</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
$ <span class="code-input">emerge --searchdesc pdf</span>
</pre></td></tr>
</table>
<p>
When you take a look at the output, you'll notice that it gives you a lot of
information. The fields are clearly labelled so we won't go further into their
meanings:
</p>
<a name="book_part2_chap1__chap3_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.3: Example 'emerge --search' output</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
* net-print/cups-pdf
Latest version available: 1.5.2
Latest version installed: [ Not Installed ]
Size of downloaded files: 15 kB
Homepage: http://cip.physik.uni-wuerzburg.de/~vrbehr/cups-pdf/
Description: Provides a virtual printer for CUPS to produce PDF files.
License: GPL-2
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part2_chap1__chap3_sect2">Installing Software</a></p>
<p>
Once you've found a software title to your liking, you can easily install it
with <span class="code" dir="ltr">emerge</span>: just add the package name. For instance, to install
<span class="code" dir="ltr">gnumeric</span>:
</p>
<a name="book_part2_chap1__chap3_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.4: Installing gnumeric</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge gnumeric</span>
</pre></td></tr>
</table>
<p>
Since many applications depend on each other, any attempt to install a certain
software package might result in the installation of several dependencies as
well. Don't worry, Portage handles dependencies well. If you want to find out
what Portage <span class="emphasis">would</span> install when you ask it to install a certain package,
add the <span class="code" dir="ltr">--pretend</span> switch. For instance:
</p>
<a name="book_part2_chap1__chap3_pre5"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.5: Pretend to install gnumeric</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge --pretend gnumeric</span>
</pre></td></tr>
</table>
<p>
When you ask Portage to install a package, it will download the necessary source
code from the internet (if necessary) and store it by default in
<span class="path" dir="ltr">/usr/portage/distfiles</span>. After this it will unpack, compile and
install the package. If you want Portage to only download the sources without
installing them, add the <span class="code" dir="ltr">--fetchonly</span> option to the <span class="code" dir="ltr">emerge</span> command:
</p>
<a name="book_part2_chap1__chap3_pre6"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.6: Download the sourcecode for gnumeric</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge --fetchonly gnumeric</span>
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part2_chap1__chap3_sect3">Finding Installed Package Documentation</a></p>
<p>
Many packages come with their own documentation. Sometimes, the <span class="code" dir="ltr">doc</span> USE
flag determines whether the package documentation should be installed or not.
You can check the existence of a <span class="code" dir="ltr">doc</span> USE flag with the <span class="code" dir="ltr">emerge -vp
&lt;package name&gt;</span> command.
</p>
<a name="book_part2_chap1__chap3_pre7"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.7: Checking the existence of a doc USE flag</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment">(alsa-lib is just an example, of course.)</span>
# <span class="code-input">emerge -vp alsa-lib</span>
[ebuild N ] media-libs/alsa-lib-1.0.14_rc1 -debug +doc 698 kB
</pre></td></tr>
</table>
<p>
The best way of enabling the <span class="code" dir="ltr">doc</span> USE flag is doing it on a per-package
basis via <span class="path" dir="ltr">/etc/portage/package.use</span>, so that you get documentation
only for packages that you are interested in. Enabling this flag globally is
known to cause problems with circular dependencies. For more information, please
read the <a href="#book_part2_chap2">USE Flags</a> chapter.
</p>
<p>
Once the package installed, its documentation is generally found in a
subdirectory named after the package under the <span class="path" dir="ltr">/usr/share/doc</span>
directory. You can also list all installed files with the <span class="code" dir="ltr">equery</span> tool
which is part of the <span class="code" dir="ltr">app-portage/gentoolkit</span> <a href="https://wiki.gentoo.org/wiki/Gentoolkit">package</a>.
</p>
<a name="book_part2_chap1__chap3_pre8"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.8: Locating package documentation</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">ls -l /usr/share/doc/alsa-lib-1.0.14_rc1</span>
total 28
-rw-r--r-- 1 root root 669 May 17 21:54 ChangeLog.gz
-rw-r--r-- 1 root root 9373 May 17 21:54 COPYING.gz
drwxr-xr-x 2 root root 8560 May 17 21:54 html
-rw-r--r-- 1 root root 196 May 17 21:54 TODO.gz
<span class="code-comment">(Alternatively, use equery to locate interesting files:)</span>
# <span class="code-input">equery files alsa-lib | less</span>
media-libs/alsa-lib-1.0.14_rc1
* Contents of media-libs/alsa-lib-1.0.14_rc1:
/usr
/usr/bin
/usr/bin/alsalisp
<span class="code-comment">(Output truncated)</span>
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part2_chap1__chap3_sect4">Removing Software</a></p>
<p>
When you want to remove a software package from your system, use <span class="code" dir="ltr">emerge
--unmerge</span>. This will tell Portage to remove all files installed by that
package from your system <span class="emphasis">except</span> the configuration files of that
application if you have altered those after the installation. Leaving the
configuration files allows you to continue working with the package if you ever
decide to install it again.
</p>
<p>
However, a <font color="#ff0000"><b>big warning</b></font> applies: Portage will <span class="emphasis">not</span> check if
the package you want to remove is required by another package. It will however
warn you when you want to remove an important package that breaks your system
if you unmerge it.
</p>
<a name="book_part2_chap1__chap3_pre9"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.9: Removing gnumeric from the system</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge --unmerge gnumeric</span>
</pre></td></tr>
</table>
<p>
When you remove a package from your system, the dependencies of that package
that were installed automatically when you installed the software are left. To
have Portage locate all dependencies that can now be removed, use
<span class="code" dir="ltr">emerge</span>'s <span class="code" dir="ltr">--depclean</span> functionality. We will talk about this later
on.
</p>
<p class="secthead"><a name="book_part2_chap1__chap3_sect5">Updating your System</a></p>
<p>
To keep your system in perfect shape (and not to mention install the latest
security updates) you need to update your system regularly. Since Portage only
checks the ebuilds in your Portage tree you first have to update your Portage
tree. When your Portage tree is updated, you can update your system with
<span class="code" dir="ltr">emerge --update @world</span>. In the next example, we'll also use the
<span class="code" dir="ltr">--ask</span> switch which will tell Portage to display the list of packages it
wants to upgrade and ask you if you want to continue:
</p>
<a name="book_part2_chap1__chap3_pre10"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.10: Updating your system</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge --update --ask @world</span>
</pre></td></tr>
</table>
<p>
Portage will then search for newer version of the applications you have
installed. However, it will only verify the versions for the applications you
have <span class="emphasis">explicitly</span> installed (the applications listed in
<span class="path" dir="ltr">/var/lib/portage/world</span>) - it does not thoroughly check their
dependencies. If you want to update the dependencies of those packages as well,
add the <span class="code" dir="ltr">--deep</span> argument:
</p>
<a name="book_part2_chap1__chap3_pre11"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.11: Updating your system with dependencies</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge --update --deep @world</span>
</pre></td></tr>
</table>
<p>
Still, this doesn't mean <span class="emphasis">all packages</span>: some packages on your system are
needed during the compile and build process of packages, but once that package
is installed, these dependencies are no longer required. Portage calls those
<span class="emphasis">build dependencies</span>. To include those in an update cycle, add
<span class="code" dir="ltr">--with-bdeps=y</span>:
</p>
<a name="book_part2_chap1__chap3_pre12"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.12: Updating your entire system</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge --update --deep --with-bdeps=y @world</span>
</pre></td></tr>
</table>
<p>
Since security updates also happen in packages you have not explicitly installed
on your system (but that are pulled in as dependencies of other programs), it
is recommended to run this command once in a while.
</p>
<p>
If you have altered any of your <a href="#book_part2_chap2">USE flags</a>
lately you might want to add <span class="code" dir="ltr">--newuse</span> as well. Portage will then verify
if the change requires the installation of new packages or recompilation of
existing ones:
</p>
<a name="book_part2_chap1__chap3_pre13"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.13: Performing a full update</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge --update --deep --with-bdeps=y --newuse @world</span>
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part2_chap1__chap3_sect6">Metapackages</a></p>
<p>
Some packages in the Portage tree don't have any real content but are used to
install a collection of packages. For instance, the <span class="code" dir="ltr">kde-meta</span> package will
install a complete KDE environment on your system by pulling in various
KDE-related packages as dependencies.
</p>
<p>
If you ever want to remove such a package from your system, running <span class="code" dir="ltr">emerge
--unmerge</span> on the package won't have much effect as the dependencies remain
on the system.
</p>
<p>
Portage has the functionality to remove orphaned dependencies as well, but since
the availability of software is dynamically dependent you first need to update
your entire system fully, including the new changes you applied when changing
USE flags. After this you can run <span class="code" dir="ltr">emerge --depclean</span> to remove the
orphaned dependencies. When this is done, you need to rebuild the applications
that were dynamically linked to the now-removed software titles but don't
require them anymore.
</p>
<p>
All this is handled with the following three commands:
</p>
<a name="book_part2_chap1__chap3_pre14"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.14: Removing orphaned dependencies</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge --update --deep --newuse @world</span>
# <span class="code-input">emerge --depclean</span>
# <span class="code-input">revdep-rebuild</span>
</pre></td></tr>
</table>
<p>
<span class="code" dir="ltr">revdep-rebuild</span> is provided by the <span class="code" dir="ltr">gentoolkit</span> package; don't forget
to emerge it first:
</p>
<a name="book_part2_chap1__chap3_pre15"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.15: Installing the gentoolkit package</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge gentoolkit</span>
</pre></td></tr>
</table>
<p class="chaphead"><a name="license"></a><a name="book_part2_chap1__chap4"></a><span class="chapnum">1.d. </span>Licenses</p>
<p>
Beginning with Portage version 2.1.7, you can accept or reject software
installation based on its license. All packages in the tree contain a
<span class="code" dir="ltr">LICENSE</span> entry in their ebuilds. Running <span class="code" dir="ltr">emerge --search
packagename</span> will tell you the package's license.
</p>
<p>
By default, Portage permits all licenses, except End User License Agreements
(EULAs) that require reading and signing an acceptance agreement.
</p>
<p>
The variable that controls permitted licenses is <span class="code" dir="ltr">ACCEPT_LICENSE</span>, which
can be set in <span class="path" dir="ltr">/etc/portage/make.conf</span>. In the next example, this
default value is shown:
</p>
<a name="book_part2_chap1__chap4_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.1: Setting ACCEPT_LICENSE in /etc/portage/make.conf</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
ACCEPT_LICENSE="* -@EULA"
</pre></td></tr>
</table>
<p>
With this configuration, packages that require interaction during installation
to approve their EULA <span class="emphasis">will not</span> be installable. Packages without an EULA
<span class="emphasis">will</span> be installable.
</p>
<p>
You can set <span class="code" dir="ltr">ACCEPT_LICENSE</span> globally in <span class="path" dir="ltr">/etc/portage/make.conf</span>
, or you can specify it on a per-package basis in
<span class="path" dir="ltr">/etc/portage/package.license</span>.
</p>
<p>
For example, if you want to allow the <span class="code" dir="ltr">truecrypt-2.7</span> license for
<span class="code" dir="ltr">app-crypt/truecrypt</span>, add the following to
<span class="path" dir="ltr">/etc/portage/package.license</span>:
</p>
<a name="book_part2_chap1__chap4_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.2: Specifying a truecrypt license in package.license</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
app-crypt/truecrypt truecrypt-2.7
</pre></td></tr>
</table>
<p>
This permits installation of truecrypt versions that have the
<span class="code" dir="ltr">truecrypt-2.7</span> license, but not versions with the <span class="code" dir="ltr">truecrypt-2.8</span>
license.
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffffbb"><p class="note"><b>Important: </b>
Licenses are stored in <span class="path" dir="ltr">/usr/portage/licenses</span>, and license groups
are kept in <span class="path" dir="ltr">/usr/portage/profiles/license_groups</span>. The first entry
of each line in CAPITAL letters is the name of the license group, and every
entry after that is an individual license.
</p></td></tr></table>
<p>
License groups defined in <span class="code" dir="ltr">ACCEPT_LICENSE</span> are prefixed with an <b>@</b>
sign. A commonly requested setting is to only allow the installation of free
software and documentation. To accomplish this, we can remove all currently
accepted licenses (using <span class="code" dir="ltr">-*</span>) and then only allow the licenses in the
<span class="code" dir="ltr">FREE</span> group as follows:
</p>
<a name="book_part2_chap1__chap4_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.3: Only allowing free software and documentation licenses in /etc/portage/make.conf</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
ACCEPT_LICENSE="-* @FREE"
</pre></td></tr>
</table>
<p>
In this case, "free" is mostly defined by the <a href="http://www.gnu.org/philosophy/free-sw.html">FSF</a> and <a href="http://www.opensource.org/docs/osd">OSI</a>. Any package whose license
does not meet these requirements will not be installable on your system.
</p>
<p class="chaphead"><a name="book_part2_chap1__chap5"></a><span class="chapnum">1.e. </span>When Portage is Complaining...</p>
<p class="secthead"><a name="book_part2_chap1__chap5_sect1">About SLOTs, Virtuals, Branches, Architectures and Profiles</a></p>
<p>
As we stated before, Portage is extremely powerful and supports many features
that other software management tools lack. To understand this, we explain a few
aspects of Portage without going into too much detail.
</p>
<p>
With Portage different versions of a single package can coexist on a system.
While other distributions tend to name their package to those versions (like
<span class="code" dir="ltr">freetype</span> and <span class="code" dir="ltr">freetype2</span>) Portage uses a technology called
<span class="emphasis">SLOT</span>s. An ebuild declares a certain SLOT for its version. Ebuilds with
different SLOTs can coexist on the same system. For instance, the
<span class="code" dir="ltr">freetype</span> package has ebuilds with <span class="code" dir="ltr">SLOT="1"</span> and <span class="code" dir="ltr">SLOT="2"</span>.
</p>
<p>
There are also packages that provide the same functionality but are implemented
differently. For instance, <span class="code" dir="ltr">metalogd</span>, <span class="code" dir="ltr">sysklogd</span> and <span class="code" dir="ltr">syslog-ng</span>
are all system loggers. Applications that rely on the availability of "a system
logger" cannot depend on, for instance, <span class="code" dir="ltr">metalogd</span>, as the other system
loggers are as good a choice as any. Portage allows for <span class="emphasis">virtuals</span>: each
system logger is listed as an "exclusive" dependency of the logging service in the
<span class="code" dir="ltr">logger</span> virtual package of the <span class="code" dir="ltr">virtual</span> category, so that
applications can depend on the <span class="code" dir="ltr">virtual/logger</span> package. When installed,
the package will pull in the first logging package mentioned in the package,
unless a logging package was already installed (in which case the virtual is
satisfied).
</p>
<p>
Software in the Portage tree can reside in different branches. By default your
system only accepts packages that Gentoo deems stable. Most new software titles,
when committed, are added to the testing branch, meaning more testing needs to
be done before it is marked as stable. Although you will see the ebuilds for
those software in the Portage tree, Portage will not update them before they are
placed in the stable branch.
</p>
<p>
Some software is only available for a few architectures. Or the software doesn't
work on the other architectures, or it needs more testing, or the developer that
committed the software to the Portage tree is unable to verify if the package
works on different architectures.
</p>
<p>
Each Gentoo installation adheres to a certain <span class="code" dir="ltr">profile</span> which contains,
amongst other information, the list of packages that are required for a system
to function normally.
</p>
<p class="secthead"><a name="blocked"></a><a name="book_part2_chap1__chap5_sect2">Blocked Packages</a></p>
<a name="book_part2_chap1__chap5_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.1: Portage warning about blocked packages (with --pretend)</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
[blocks B ] mail-mta/ssmtp (is blocking mail-mta/postfix-2.2.2-r1)
</pre></td></tr>
</table>
<a name="book_part2_chap1__chap5_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.2: Portage warning about blocked packages (without --pretend)</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
!!! Error: the mail-mta/postfix package conflicts with another package.
!!! both can't be installed on the same system together.
!!! Please use 'emerge --pretend' to determine blockers.
</pre></td></tr>
</table>
<p>
Ebuilds contain specific fields that inform Portage about its dependencies.
There are two possible dependencies: build dependencies, declared in
<span class="code" dir="ltr">DEPEND</span> and run-time dependencies, declared in <span class="code" dir="ltr">RDEPEND</span>. When one of
these dependencies explicitly marks a package or virtual as being <span class="emphasis">not</span>
compatible, it triggers a blockage.
</p>
<p>
While recent versions of Portage are smart enough to work around minor blockages
without user intervention, occasionally you will need to fix it yourself, as
explained below.
</p>
<p>
To fix a blockage, you can choose to not install the package or unmerge the
conflicting package first. In the given example, you can opt not to install
<span class="code" dir="ltr">postfix</span> or to remove <span class="code" dir="ltr">ssmtp</span> first.
</p>
<p>
You may also see blocking packages with specific atoms, such as
<b>&lt;</b>media-video/mplayer-1.0_rc1-r2. In this case, updating to a more
recent version of the blocking package would remove the block.
</p>
<p>
It is also possible that two packages that are yet to be installed are blocking
each other. In this rare case, you should find out why you need to install both.
In most cases you can do with one of the packages alone. If not, please file a
bug on <a href="https://bugs.gentoo.org">Gentoo's bugtracking system</a>.
</p>
<p class="secthead"><a name="masked"></a><a name="book_part2_chap1__chap5_sect3">Masked Packages</a></p>
<a name="book_part2_chap1__chap5_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.3: Portage warning about masked packages</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
!!! all ebuilds that could satisfy "bootsplash" have been masked.
</pre></td></tr>
</table>
<a name="book_part2_chap1__chap5_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.4: Portage warning about masked packages - reason</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
!!! possible candidates are:
- gnome-base/gnome-2.8.0_pre1 (masked by: <span class="code-input">~x86 keyword</span>)
- lm-sensors/lm-sensors-2.8.7 (masked by: <span class="code-input">-sparc keyword</span>)
- sys-libs/glibc-2.3.4.20040808 (masked by: <span class="code-input">-* keyword</span>)
- dev-util/cvsd-1.0.2 (masked by: <span class="code-input">missing keyword</span>)
- games-fps/unreal-tournament-451 (masked by: <span class="code-input">package.mask</span>)
- sys-libs/glibc-2.3.2-r11 (masked by: <span class="code-input">profile</span>)
- net-im/skype-2.1.0.81 (masked by: skype-eula <span class="code-input">license</span>(s))
</pre></td></tr>
</table>
<p>
When you want to install a package that isn't available for your system, you
will receive this masking error. You should try installing a different
application that is available for your system or wait until the package is put
available. There is always a reason why a package is masked:
</p>
<ul>
<li>
<b>~arch keyword</b> means that the application is not tested sufficiently
to be put in the stable branch. Wait a few days or weeks and try again.
</li>
<li>
<b>-arch keyword</b> or <b>-* keyword</b> means that the application does
not work on your architecture. If you believe the package does work file
a bug at our <a href="https://bugs.gentoo.org">bugzilla</a> website.
</li>
<li>
<b>missing keyword</b> means that the application has not been tested on
your architecture yet. Ask the architecture porting team to test the package
or test it for them and report your findings on our <a href="https://bugs.gentoo.org">bugzilla</a> website.
</li>
<li>
<b>package.mask</b> means that the package has been found corrupt, unstable
or worse and has been deliberately marked as do-not-use.
</li>
<li>
<b>profile</b> means that the package has been found not suitable for your
profile. The application might break your system if you installed it or is
just not compatible with the profile you use.
</li>
<li>
<b>license</b> means that the package's license is not compatible with your
<span class="code" dir="ltr">ACCEPT_LICENSE</span> setting. You must explicitly permit its license or
license group by setting it in <span class="path" dir="ltr">/etc/portage/make.conf</span> or in
<span class="path" dir="ltr">/etc/portage/package.license</span>. Refer to <a href="#license">Licenses</a> to learn how licenses work.
</li>
</ul>
<p class="secthead"><a name="USEdependency"></a><a name="book_part2_chap1__chap5_sect4">Necessary USE Flag Changes</a></p>
<a name="book_part2_chap1__chap5_pre5"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.5: Portage warning about USE flag change requirement</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
The following USE changes are necessary to proceed:
#required by app-text/happypackage-2.0, required by happypackage (argument)
&gt;=app-text/feelings-1.0.0 test
</pre></td></tr>
</table>
<p>
The error message might also be displayed as follows, if <span class="code" dir="ltr">--autounmask</span>
isn't set:
</p>
<a name="book_part2_chap1__chap5_pre6"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.6: Portage error about USE flag change requirement</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
emerge: there are no ebuilds built with USE flags to satisfy "app-text/feelings[test]".
!!! One of the following packages is required to complete your request:
- app-text/feelings-1.0.0 (Change USE: +test)
(dependency required by "app-text/happypackage-2.0" [ebuild])
(dependency required by "happypackage" [argument])
</pre></td></tr>
</table>
<p>
Such warning or error occurs when you want to install a package which not only
depends on another package, but also requires that that package is built with a
particular USE flag (or set of USE flags). In the given example, the package
<span class="code" dir="ltr">app-text/feelings</span> needs to be built with <span class="code" dir="ltr">USE="test"</span>, but this USE
flag is not set on the system.
</p>
<p>
To resolve this, either add the requested USE flag to your global USE flags in
<span class="path" dir="ltr">/etc/portage/make.conf</span>, or set it for the specific package in
<span class="path" dir="ltr">/etc/portage/package.use</span>.
</p>
<p class="secthead"><a name="missingdependencies"></a><a name="book_part2_chap1__chap5_sect5">Missing Dependencies</a></p>
<a name="book_part2_chap1__chap5_pre7"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.7: Portage warning about missing dependency</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
emerge: there are no ebuilds to satisfy "&gt;=sys-devel/gcc-3.4.2-r4".
!!! Problem with ebuild sys-devel/gcc-3.4.2-r2
!!! Possibly a DEPEND/*DEPEND problem.
</pre></td></tr>
</table>
<p>
The application you are trying to install depends on another package that is not
available for your system. Please check <a href="https://bugs.gentoo.org">bugzilla</a> if the issue is known and if not,
please report it. Unless you are mixing branches this should not occur and is
therefore a bug.
</p>
<p class="secthead"><a name="ambiguousebuild"></a><a name="book_part2_chap1__chap5_sect6">Ambiguous Ebuild Name</a></p>
<a name="book_part2_chap1__chap5_pre8"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.8: Portage warning about ambiguous ebuild names</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
[ Results for search key : listen ]
[ Applications found : 2 ]
* dev-tinyos/listen [ Masked ]
Latest version available: 1.1.15
Latest version installed: [ Not Installed ]
Size of files: 10,032 kB
Homepage: http://www.tinyos.net/
Description: Raw listen for TinyOS
License: BSD
* media-sound/listen [ Masked ]
Latest version available: 0.6.3
Latest version installed: [ Not Installed ]
Size of files: 859 kB
Homepage: http://www.listen-project.org
Description: A Music player and management for GNOME
License: GPL-2
!!! The short ebuild name "listen" is ambiguous. Please specify
!!! one of the above fully-qualified ebuild names instead.
</pre></td></tr>
</table>
<p>
The application you want to install has a name that corresponds with more than
one package. You need to supply the category name as well. Portage will inform
you of possible matches to choose from.
</p>
<p class="secthead"><a name="circulardependencies"></a><a name="book_part2_chap1__chap5_sect7">Circular Dependencies</a></p>
<a name="book_part2_chap1__chap5_pre9"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.9: Portage warning about circular dependencies</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
!!! Error: circular dependencies:
ebuild / net-print/cups-1.1.15-r2 depends on ebuild / app-text/ghostscript-7.05.3-r1
ebuild / app-text/ghostscript-7.05.3-r1 depends on ebuild / net-print/cups-1.1.15-r2
</pre></td></tr>
</table>
<p>
Two (or more) packages you want to install depend on each other and can
therefore not be installed. This is most likely a bug in the Portage tree.
Please resync after a while and try again. You can also check <a href="https://bugs.gentoo.org">bugzilla</a> if the issue is known and if not,
report it.
</p>
<p class="secthead"><a name="fetchfailed"></a><a name="book_part2_chap1__chap5_sect8">Fetch failed</a></p>
<a name="book_part2_chap1__chap5_pre10"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.10: Portage warning about fetch failed</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
!!! Fetch failed for sys-libs/ncurses-5.4-r5, continuing...
<span class="code-comment">(...)</span>
!!! Some fetch errors were encountered. Please see above for details.
</pre></td></tr>
</table>
<p>
Portage was unable to download the sources for the given application and will
try to continue installing the other applications (if applicable). This failure
can be due to a mirror that has not synchronised correctly or because the ebuild
points to an incorrect location. The server where the sources reside can also be
down for some reason.
</p>
<p>
Retry after one hour to see if the issue still persists.
</p>
<p class="secthead"><a name="profileprotect"></a><a name="book_part2_chap1__chap5_sect9">System Profile Protection</a></p>
<a name="book_part2_chap1__chap5_pre11"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.11: Portage warning about profile-protected package</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
!!! Trying to unmerge package(s) in system profile. 'sys-apps/portage'
!!! This could be damaging to your system.
</pre></td></tr>
</table>
<p>
You have asked to remove a package that is part of your system's core packages.
It is listed in your profile as required and should therefore not be removed
from the system.
</p>
<p class="secthead"><a name="digesterror"></a><a name="book_part2_chap1__chap5_sect10">Digest Verification Failures</a></p>
<p>
Sometimes, when you attempt to emerge a package, it will fail with the message:
</p>
<a name="book_part2_chap1__chap5_pre12"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.12: Digest verification failure</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
&gt;&gt;&gt; checking ebuild checksums
!!! Digest verification failed:
</pre></td></tr>
</table>
<p>
This is a sign that something is wrong with the Portage tree -- often, it is
because a developer may have made a mistake when committing a package to the
tree.
</p>
<p>
When the digest verification fails, do <span class="emphasis">not</span> try to re-digest the package
yourself. Running <span class="code" dir="ltr">ebuild foo manifest</span> will not fix the problem; it will
almost certainly make it worse!
</p>
<p>
Instead, wait an hour or two for the tree to settle down. It's likely that the
error was noticed right away, but it can take a little time for the fix to
trickle down the Portage tree. While you're waiting, check <a href="https://bugs.gentoo.org">Bugzilla</a> and see if anyone has reported
the problem yet. If not, go ahead and file a bug for the broken package.
</p>
<p>
Once you see that the bug has been fixed, you may want to re-sync to pick up
the fixed digest.
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffffbb"><p class="note"><b>Important: </b>
This does <span class="emphasis">not</span> mean that you can re-sync your tree multiple times! As
stated in the rsync policy (when you run <span class="code" dir="ltr">emerge --sync</span>), users who sync
too often will be banned! In fact, it's better to just wait until your next
scheduled sync, so that you don't overload the rsync servers.
</p></td></tr></table>
<a name="book_part2_chap2"></a><h3>2. USE flags</h3>
<p class="chaphead"><a name="book_part2_chap2__chap1"></a><span class="chapnum">2.a. </span>What are USE flags?</p>
<p class="secthead"><a name="book_part2_chap2__chap1_sect1">The ideas behind USE flags</a></p>
<p>
When you are installing Gentoo (or any other distribution, or even operating
system for that matter) you make choices depending on the environment you are
working with. A setup for a server differs from a setup for a workstation.
A gaming workstation differs from a 3D rendering workstation.
</p>
<p>
This is not only true for choosing what packages you want to install, but also
what features a certain package should support. If you don't need OpenGL, why
would you bother installing OpenGL and build OpenGL support in most of your
packages? If you don't want to use KDE, why would you bother compiling packages
with KDE support if those packages work flawlessly without?
</p>
<p>
To help users in deciding what to install/activate and what not, we wanted the
user to specify his/her environment in an easy way. This forces the user into
deciding what they really want and eases the process for Portage, our package
management system, to make useful decisions.
</p>
<p class="secthead"><a name="book_part2_chap2__chap1_sect2">Definition of a USE flag</a></p>
<p>
Enter the USE flags. Such a flag is a keyword that embodies support and
dependency-information for a certain concept. If you define a certain USE flag,
Portage will know that you want support for the chosen keyword. Of course
this also alters the dependency information for a package.
</p>
<p>
Let us take a look at a specific example: the <span class="code" dir="ltr">kde</span> keyword. If you do not
have this keyword in your <span class="code" dir="ltr">USE</span> variable, all packages that have
<span class="emphasis">optional</span> KDE support will be compiled <span class="emphasis">without</span> KDE support. All
packages that have an <span class="emphasis">optional</span> KDE dependency will be installed
<span class="emphasis">without</span> installing the KDE libraries (as dependency). If you have defined
the <span class="code" dir="ltr">kde</span> keyword, then those packages <span class="emphasis">will</span> be compiled with KDE
support, and the KDE libraries will be installed as dependency.
</p>
<p>
By correctly defining the keywords you will receive a system tailored
specifically to your needs.
</p>
<p class="secthead"><a name="book_part2_chap2__chap1_sect3">What USE flags exist?</a></p>
<p>
There are two types of USE flags: <span class="emphasis">global</span> and <span class="emphasis">local</span> USE flags.
</p>
<ul>
<li>
A <span class="emphasis">global</span> USE flag is used by several packages, system-wide. This is
what most people see as USE flags.
</li>
<li>
A <span class="emphasis">local</span> USE flag is used by a single package to make package-specific
decisions.
</li>
</ul>
<p>
A list of available global USE flags can be found <a href="/dyn/use-index.xml?style=printable#doc_chap1">online</a> or locally in
<span class="path" dir="ltr">/usr/portage/profiles/use.desc</span>.
</p>
<p>
A list of available local USE flags can be found <a href="/dyn/use-index.xml?style=printable#doc_chap2">online</a> or locally in
<span class="path" dir="ltr">/usr/portage/profiles/use.local.desc</span>.
</p>
<p class="chaphead"><a name="book_part2_chap2__chap2"></a><span class="chapnum">2.b. </span>Using USE flags</p>
<p class="secthead"><a name="book_part2_chap2__chap2_sect1">Declare permanent USE flags</a></p>
<p>
In the hope you are convinced of the importance of USE flags we will now inform
you how to declare USE flags.
</p>
<p>
As previously mentioned, all USE flags are declared inside the <span class="code" dir="ltr">USE</span>
variable. To make it easy for users to search and pick USE flags, we already
provide a <span class="emphasis">default</span> USE setting. This setting is a collection of USE flags
we think are commonly used by the Gentoo users. This default setting is declared
in the <span class="path" dir="ltr">make.defaults</span> files part of your profile.
</p>
<p>
The profile your system listens to is pointed to by the
<span class="path" dir="ltr">/etc/portage/make.profile</span> symlink. Each profile works on top of
another, larger profile, the end result is therefore the sum of all profiles.
The top profile is the <span class="path" dir="ltr">base</span> profile
(<span class="path" dir="ltr">/usr/portage/profiles/base</span>).
</p>
<p>
Let us take a look at this default setting for the 13.0 profile:
</p>
<a name="book_part2_chap2__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: Cumulative make.defaults USE variable for the 13.0 profile</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment">(This example is the sum of the settings in base, default/linux,
default/linux/x86 and default/linux/x86/13.0/)</span>
USE="a52 aac acpi alsa branding cairo cdr dbus dts dvd dvdr emboss encode exif
fam firefox flac gif gpm gtk hal jpeg lcms ldap libnotify mad mikmod mng mp3
mp4 mpeg ogg opengl pango pdf png ppds qt3support qt4 sdl spell
startup-notification svg tiff truetype vorbis unicode usb X xcb x264 xml xv
xvid"
</pre></td></tr>
</table>
<p>
As you can see, this variable already contains quite a lot of keywords. Do
<b>not</b> alter any <span class="path" dir="ltr">make.defaults</span> file to tailor
the <span class="code" dir="ltr">USE</span> variable to your needs: changes in this file will be undone when
you update Portage!
</p>
<p>
To change this default setting, you need to add or remove keywords to the
<span class="code" dir="ltr">USE</span> variable. This is done globally by defining the <span class="code" dir="ltr">USE</span> variable
in <span class="path" dir="ltr">/etc/portage/make.conf</span>. In this variable you add the extra USE
flags you require, or remove the USE flags you don't want. This latter is done
by prefixing the keyword with the minus-sign ("-").
</p>
<p>
For instance, to remove support for KDE and QT but add support for ldap, the
following <span class="code" dir="ltr">USE</span> can be defined in <span class="path" dir="ltr">/etc/portage/make.conf</span>:
</p>
<a name="book_part2_chap2__chap2_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.2: An example USE setting in /etc/portage/make.conf</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
USE="-kde -qt4 ldap"
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part2_chap2__chap2_sect2">Declaring USE flags for individual packages</a></p>
<p>
Sometimes you want to declare a certain USE flag for one (or a couple) of
applications but not system-wide. To accomplish this, you will need to create
the <span class="path" dir="ltr">/etc/portage</span> directory (if it doesn't exist yet) and edit
<span class="path" dir="ltr">/etc/portage/package.use</span>. This is usually a single file, but can
also be a directory; see <span class="code" dir="ltr">man portage</span> for more information. The following
examples assume <span class="path" dir="ltr">package.use</span> is a single file.
</p>
<p>
For instance, if you don't want <span class="code" dir="ltr">berkdb</span> support globally but you do want
it for <span class="code" dir="ltr">mysql</span>, you would add:
</p>
<a name="book_part2_chap2__chap2_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.3: /etc/portage/package.use example</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
dev-db/mysql berkdb
</pre></td></tr>
</table>
<p>
You can of course also explicitly <span class="emphasis">disable</span> USE flags for a certain
application. For instance, if you don't want <span class="code" dir="ltr">java</span> support in PHP:
</p>
<a name="book_part2_chap2__chap2_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.4: /etc/portage/package.use 2nd example</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
dev-php/php -java
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part2_chap2__chap2_sect3">Declare temporary USE flags</a></p>
<p>
Sometimes you want to set a certain USE setting only once. Instead of editing
<span class="path" dir="ltr">/etc/portage/make.conf</span> twice (to do and undo the USE changes) you
can just declare the USE variable as environment variable. Remember that, when
you re-emerge or update this application (either explicitly or as part of a
system update) your changes will be lost!
</p>
<p>
As an example we will temporarily remove java from the USE setting
during the installation of seamonkey.
</p>
<a name="book_part2_chap2__chap2_pre5"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.5: Using USE as environment variable</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">USE="-java" emerge seamonkey</span>
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part2_chap2__chap2_sect4">Precedence</a></p>
<p>
Of course there is a certain precedence on what setting has priority over the
USE setting. You don't want to declare <span class="code" dir="ltr">USE="-java"</span> only to see that
<span class="code" dir="ltr">java</span> is still used due to a setting that has a higher priority.
The precedence for the USE setting is, ordered
by priority (first has lowest priority):
</p>
<ol>
<li>
Default USE setting declared in the <span class="path" dir="ltr">make.defaults</span> files part of
your profile
</li>
<li>
User-defined USE setting in <span class="path" dir="ltr">/etc/portage/make.conf</span>
</li>
<li>
User-defined USE setting in <span class="path" dir="ltr">/etc/portage/package.use</span>
</li>
<li>
User-defined USE setting as environment variable
</li>
</ol>
<p>
To view the final <span class="code" dir="ltr">USE</span> setting as seen by Portage, run <span class="code" dir="ltr">emerge
--info</span>. This will list all relevant variables (including the <span class="code" dir="ltr">USE</span>
variable) with the content used by Portage.
</p>
<a name="book_part2_chap2__chap2_pre6"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.6: Running emerge --info</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge --info</span>
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part2_chap2__chap2_sect5">Adapting your Entire System to New USE Flags</a></p>
<p>
If you have altered your USE flags and you wish to update your entire system to
use the new USE flags, use <span class="code" dir="ltr">emerge</span>'s <span class="code" dir="ltr">--newuse</span> option:
</p>
<a name="book_part2_chap2__chap2_pre7"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.7: Rebuilding your entire system</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge --update --deep --newuse @world</span>
</pre></td></tr>
</table>
<p>
Next, run Portage's depclean to remove the conditional dependencies that
were emerged on your "old" system but that have been obsoleted by the new USE
flags.
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffbbbb"><p class="note"><b>Warning: </b>
Running <span class="code" dir="ltr">emerge --depclean</span> is a dangerous operation and should be handled
with care. Double-check the provided list of "obsoleted" packages to make sure
it doesn't remove packages you need. In the following example we add the
<span class="code" dir="ltr">-p</span> switch to have depclean only list the packages without removing them.
</p></td></tr></table>
<a name="book_part2_chap2__chap2_pre8"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.8: Removing obsoleted packages</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge -p --depclean</span>
</pre></td></tr>
</table>
<p>
When depclean has finished, run <span class="code" dir="ltr">revdep-rebuild</span> to rebuild the
applications that are dynamically linked against shared objects provided by
possibly removed packages. <span class="code" dir="ltr">revdep-rebuild</span> is part of the
<span class="code" dir="ltr">gentoolkit</span> package; don't forget to emerge it first.
</p>
<a name="book_part2_chap2__chap2_pre9"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.9: Running revdep-rebuild</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">revdep-rebuild</span>
</pre></td></tr>
</table>
<p>
When all this is accomplished, your system is using the new USE flag settings.
</p>
<p class="chaphead"><a name="book_part2_chap2__chap3"></a><span class="chapnum">2.c. </span>Package specific USE flags</p>
<p class="secthead"><a name="book_part2_chap2__chap3_sect1">Viewing available USE flags</a></p>
<p>
Let us take the example of <span class="code" dir="ltr">seamonkey</span>: what USE flags does it listen to? To
find out, we use <span class="code" dir="ltr">emerge</span> with the <span class="code" dir="ltr">--pretend</span> and <span class="code" dir="ltr">--verbose</span>
options:
</p>
<a name="book_part2_chap2__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: Viewing the used USE flags</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge --pretend --verbose seamonkey</span>
These are the packages that I would merge, in order:
Calculating dependencies ...done!
[ebuild R ] www-client/seamonkey-1.0.7 USE="crypt gnome java -debug -ipv6
-ldap -mozcalendar -mozdevelop -moznocompose -moznoirc -moznomail -moznopango
-moznoroaming -postgres -xinerama -xprint" 0 kB
</pre></td></tr>
</table>
<p>
<span class="code" dir="ltr">emerge</span> isn't the only tool for this job. In fact, we have a tool
dedicated to package information called <span class="code" dir="ltr">equery</span> which resides in the
<span class="code" dir="ltr">gentoolkit</span> package. First, install <span class="code" dir="ltr">gentoolkit</span>:
</p>
<a name="book_part2_chap2__chap3_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.2: Installing gentoolkit</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge gentoolkit</span>
</pre></td></tr>
</table>
<p>
Now run <span class="code" dir="ltr">equery</span> with the <span class="code" dir="ltr">uses</span> argument to view the USE flags of a
certain package. For instance, for the <span class="code" dir="ltr">gnumeric</span> package:
</p>
<a name="book_part2_chap2__chap3_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.3: Using equery to view used USE flags</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">equery --nocolor uses =gnumeric-1.6.3 -a</span>
[ Searching for packages matching =gnumeric-1.6.3... ]
[ Colour Code : set unset ]
[ Legend : Left column (U) - USE flags from make.conf ]
[ : Right column (I) - USE flags packages was installed with ]
[ Found these USE variables for app-office/gnumeric-1.6.3 ]
U I
- - debug : Enable extra debug codepaths, like asserts and extra output.
If you want to get meaningful backtraces see
http://www.gentoo.org/proj/en/qa/backtraces.xml .
+ + gnome : Adds GNOME support
+ + python : Adds support/bindings for the Python language
- - static : !!do not set this during bootstrap!! Causes binaries to be
statically linked instead of dynamically
</pre></td></tr>
</table>
<a name="book_part2_chap3"></a><h3>3. Portage Features</h3>
<p class="chaphead"><a name="book_part2_chap3__chap1"></a><span class="chapnum">3.a. </span>Portage Features</p>
<p>
Portage has several additional features that makes your Gentoo experience even
better. Many of these features rely on certain software tools that improve
performance, reliability, security, ...
</p>
<p>
To enable or disable certain Portage features you need to edit
<span class="path" dir="ltr">/etc/portage/make.conf</span>'s <span class="code" dir="ltr">FEATURES</span> variable which contains
the various feature keywords, separated by white space. In several cases you
will also need to install the additional tool on which the feature relies.
</p>
<p>
Not all features that Portage supports are listed here. For a full overview,
please consult the <span class="path" dir="ltr">make.conf</span> man page:
</p>
<a name="book_part2_chap3__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: Consulting the make.conf man page</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
$ <span class="code-input">man make.conf</span>
</pre></td></tr>
</table>
<p>
To find out what FEATURES are default set, run <span class="code" dir="ltr">emerge --info</span> and search
for the FEATURES variable or grep it out:
</p>
<a name="book_part2_chap3__chap1_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.2: Finding out the FEATURES that are already set</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
$ <span class="code-input">emerge --info | grep ^FEATURES=</span>
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part2_chap3__chap2"></a><span class="chapnum">3.b. </span>Distributed Compiling</p>
<p class="secthead"><a name="book_part2_chap3__chap2_sect1">Using distcc</a></p>
<p>
<span class="code" dir="ltr">distcc</span> is a program to distribute compilations across several, not
necessarily identical, machines on a network. The <span class="code" dir="ltr">distcc</span> client sends all
necessary information to the available distcc servers (running <span class="code" dir="ltr">distccd</span>)
so they can compile pieces of source code for the client. The net result is a
faster compilation time.
</p>
<p>
You can find more information about <span class="code" dir="ltr">distcc</span> (and how to have it work
with Gentoo) in our <a href="https://wiki.gentoo.org/wiki/Distcc">Gentoo Distcc
Documentation</a>.
</p>
<p class="secthead"><a name="book_part2_chap3__chap2_sect2">Installing distcc</a></p>
<p>
Distcc ships with a graphical monitor to monitor tasks that your computer is
sending away for compilation. If you use Gnome then put 'gnome' in your USE
variable. However, if you don't use Gnome and would still like to have the
monitor then you should put 'gtk' in your USE variable.
</p>
<a name="book_part2_chap3__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: Installing distcc</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge distcc</span>
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part2_chap3__chap2_sect3">Activating Portage Support</a></p>
<p>
Add <span class="code" dir="ltr">distcc</span> to the FEATURES variable inside <span class="path" dir="ltr">/etc/portage/make.conf</span>.
Next, edit the MAKEOPTS variable to your liking. A known guideline is to fill in
"-jX" with X the number of CPUs that run <span class="code" dir="ltr">distccd</span> (including the current
host) plus one, but you might have better results with other numbers.
</p>
<p>
Now run <span class="code" dir="ltr">distcc-config</span> and enter the list of available distcc servers. For
a simple example we assume that the available DistCC servers are 192.168.1.102
(the current host), 192.168.1.103 and 192.168.1.104 (two "remote" hosts):
</p>
<a name="book_part2_chap3__chap2_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.2: Configuring distcc to use three available distcc servers</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">distcc-config --set-hosts "192.168.1.102 192.168.1.103 192.168.1.104"</span>
</pre></td></tr>
</table>
<p>
Don't forget to run the <span class="code" dir="ltr">distccd</span> daemon as well:
</p>
<a name="book_part2_chap3__chap2_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.3: Starting the distccd daemons</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">rc-update add distccd default</span>
# <span class="code-input">/etc/init.d/distccd start</span>
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part2_chap3__chap3"></a><span class="chapnum">3.c. </span>Caching Compilation</p>
<p class="secthead"><a name="book_part2_chap3__chap3_sect1">About ccache</a></p>
<p>
<span class="code" dir="ltr">ccache</span> is a fast compiler cache. When you compile a program, it will
cache intermediate results so that, whenever you recompile the same program, the
compilation time is greatly reduced. The first time you run ccache, it will be
much slower than a normal compilation. Subsequent recompiles should be faster.
ccache is only helpful if you will be recompiling the same application many
times; thus it's mostly only useful for software developers.
</p>
<p>
If you are interested in the ins and outs of ccache, please visit the
<a href="http://ccache.samba.org">ccache homepage</a>.
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffbbbb"><p class="note"><b>Warning: </b>
<span class="code" dir="ltr">ccache</span> is known to cause numerous compilation failures. Sometimes ccache
will retain stale code objects or corrupted files, which can lead to packages
that cannot be emerged. If this happens (if you receive errors like "File not
recognized: File truncated"), try recompiling the application with ccache
disabled (<span class="code" dir="ltr">FEATURES="-ccache"</span> in <span class="path" dir="ltr">/etc/portage/make.conf</span>)
<span class="emphasis">before</span> reporting a bug. Unless you are doing development work, <span class="emphasis">do not
enable ccache</span>.
</p></td></tr></table>
<p class="secthead"><a name="book_part2_chap3__chap3_sect2">Installing ccache</a></p>
<p>
To install <span class="code" dir="ltr">ccache</span>, run <span class="code" dir="ltr">emerge ccache</span>:
</p>
<a name="book_part2_chap3__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: Installing ccache</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge ccache</span>
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part2_chap3__chap3_sect3">Activating Portage Support</a></p>
<p>
Open <span class="path" dir="ltr">/etc/portage/make.conf</span> and add <span class="code" dir="ltr">ccache</span> to the FEATURES
variable. Next, add a new variable called CCACHE_SIZE and set it to "2G":
</p>
<a name="book_part2_chap3__chap3_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.2: Editing CCACHE_SIZE in /etc/portage/make.conf</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
CCACHE_SIZE="2G"
</pre></td></tr>
</table>
<p>
To check if ccache functions, ask ccache to provide you with its statistics.
Because Portage uses a different ccache home directory, you need to set the
<span class="code" dir="ltr">CCACHE_DIR</span> variable as well:
</p>
<a name="book_part2_chap3__chap3_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.3: Viewing ccache statistics</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">CCACHE_DIR="/var/tmp/ccache" ccache -s</span>
</pre></td></tr>
</table>
<p>
The <span class="path" dir="ltr">/var/tmp/ccache</span> location is Portage' default ccache home
directory; if you want to alter this setting you can set the <span class="code" dir="ltr">CCACHE_DIR</span>
variable in <span class="path" dir="ltr">/etc/portage/make.conf</span>.
</p>
<p>
However, if you would run <span class="code" dir="ltr">ccache</span>, it would use the default location of
<span class="path" dir="ltr">${HOME}/.ccache</span>, which is why you needed to set the
<span class="code" dir="ltr">CCACHE_DIR</span> variable when asking for the (Portage) ccache statistics.
</p>
<p class="secthead"><a name="book_part2_chap3__chap3_sect4">Using ccache for non-Portage C Compiling</a></p>
<p>
If you would like to use ccache for non-Portage compilations, add
<span class="path" dir="ltr">/usr/lib/ccache/bin</span> to the beginning of your PATH variable (before
<span class="path" dir="ltr">/usr/bin</span>). This can be accomplished by editing
<span class="path" dir="ltr">.bash_profile</span> in your user's home directory. Using
<span class="path" dir="ltr">.bash_profile</span> is one way to define PATH variables.
</p>
<a name="book_part2_chap3__chap3_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.4: Editing .bash_profile</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
PATH="<span class="code-input">/usr/lib/ccache/bin</span>:/opt/bin:${PATH}"
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part2_chap3__chap4"></a><span class="chapnum">3.d. </span>Binary Package Support</p>
<p class="secthead"><a name="book_part2_chap3__chap4_sect1">Creating Prebuilt Packages</a></p>
<p>
Portage supports the installation of prebuilt packages. Even though Gentoo does
not provide prebuilt packages by itself Portage
can be made fully aware of prebuilt packages.
</p>
<p>
To create a prebuilt package you can use <span class="code" dir="ltr">quickpkg</span> if the package is
already installed on your system, or <span class="code" dir="ltr">emerge</span> with the <span class="code" dir="ltr">--buildpkg</span> or
<span class="code" dir="ltr">--buildpkgonly</span> options.
</p>
<p>
If you want Portage to create prebuilt packages of every single package you
install, add <span class="code" dir="ltr">buildpkg</span> to the FEATURES variable.
</p>
<p>
More extended support for creating prebuilt package sets can be obtained with
<span class="code" dir="ltr">catalyst</span>. For more information on catalyst please read the <a href="/proj/en/releng/catalyst/faq.xml?style=printable">Catalyst Frequently Asked
Questions</a>.
</p>
<p class="secthead"><a name="book_part2_chap3__chap4_sect2">Installing Prebuilt Packages</a></p>
<p>
Although Gentoo doesn't provide one, you can create a central repository where
you store prebuilt packages. If you want to use this repository, you need to
make Portage aware of it by having the PORTAGE_BINHOST variable point to
it. For instance, if the prebuilt packages are on ftp://buildhost/gentoo:
</p>
<a name="book_part2_chap3__chap4_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.1: Setting PORTAGE_BINHOST in /etc/portage/make.conf</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
PORTAGE_BINHOST="ftp://buildhost/gentoo"
</pre></td></tr>
</table>
<p>
When you want to install a prebuilt package, add the <span class="code" dir="ltr">--getbinpkg</span> option
to the emerge command alongside of the <span class="code" dir="ltr">--usepkg</span> option. The former tells
emerge to download the prebuilt package from the previously defined server
while the latter asks emerge to try to install the prebuilt package first before
fetching the sources and compiling it.
</p>
<p>
For instance, to install <span class="code" dir="ltr">gnumeric</span> with prebuilt packages:
</p>
<a name="book_part2_chap3__chap4_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.2: Installing the gnumeric prebuilt package</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge --usepkg --getbinpkg gnumeric</span>
</pre></td></tr>
</table>
<p>
More information about emerge's prebuilt package options can be found in the
emerge man page:
</p>
<a name="book_part2_chap3__chap4_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.3: Reading the emerge man page</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
$ <span class="code-input">man emerge</span>
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part2_chap3__chap5"></a><span class="chapnum">3.e. </span>Fetching Files</p>
<p class="secthead"><a name="book_part2_chap3__chap5_sect1">Parallel fetch</a></p>
<p>
When you are emerging a series of packages, Portage can fetch the source files
for the next package in the list even while it is compiling another package,
thus shortening compile times. To make use of this capability, add
"parallel-fetch" to your FEATURES. Note that this is on by default, so you
shouldn't need to specifically enable it.
</p>
<p class="secthead"><a name="book_part2_chap3__chap5_sect2">Userfetch</a></p>
<p>
When Portage is run as root, FEATURES="userfetch" will allow Portage to drop
root privileges while fetching package sources. This is a small security
improvement.
</p>
<p class="chaphead"><a name="webrsync-gpg"></a><a name="book_part2_chap3__chap6"></a><span class="chapnum">3.f. </span>Pulling Validated Portage Tree Snapshots</p>
<p>
As an administrator, you can opt to only update your local Portage tree with a
cryptographically validated Portage tree snapshot as released by the Gentoo
infrastructure. This ensures that no rogue rsync mirror is adding unwanted code
or packages in the tree you are downloading.
</p>
<p>
To configure Portage, first create a truststore in which you download and accept
the keys of the Gentoo Infrastructure responsible for signing the Portage tree
snapshots. Of course, if you want to, you can validate this GPG key as per the
<a href="https://wiki.gentoo.org/wiki/GnuPG#Importing_keys">proper guidelines</a>
(like checking the key fingerprint). You can find the list of GPG keys used by
the release engineering team on their <a href="/proj/en/releng/index.xml?style=printable">project page</a>.
</p>
<a name="book_part2_chap3__chap6_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 6.1: Creating a truststore for Portage</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">mkdir -p /etc/portage/gpg</span>
# <span class="code-input">chmod 0700 /etc/portage/gpg</span>
<span class="code-comment">(... Substitute the keys with those mentioned on the release engineering site ...)</span>
# <span class="code-input">gpg --homedir /etc/portage/gpg --keyserver subkeys.pgp.net --recv-keys 0xDB6B8C1F96D8BF6D</span>
# <span class="code-input">gpg --homedir /etc/portage/gpg --edit-key 0xDB6B8C1F96D8BF6D trust</span>
</pre></td></tr>
</table>
<p>
Next, edit <span class="path" dir="ltr">/etc/portage/make.conf</span> and enable support for validating
the signed Portage tree snapshots (using <span class="code" dir="ltr">FEATURES="webrsync-gpg"</span>) and
disabling updating the Portage tree using the regular <span class="code" dir="ltr">emerge --sync</span>
method.
</p>
<a name="book_part2_chap3__chap6_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 6.2: Updating make.conf</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
FEATURES="webrsync-gpg"
PORTAGE_GPG_DIR="/etc/portage/gpg"
</pre></td></tr>
</table>
<a name="book_part2_chap3__chap6_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 6.3: Updating repos.conf</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment"># Make sure sync-type and sync-uri are commented out</span>
# sync-type = rsync
# sync-uri = ...
</pre></td></tr>
</table>
<p>
That's it. Next time you run <span class="code" dir="ltr">emerge-webrsync</span>, only the snapshots with
a valid signature will be expanded on your file system.
</p>
<a name="book_part2_chap4"></a><h3>4. Initscripts</h3>
<p class="chaphead"><a name="book_part2_chap4__chap1"></a><span class="chapnum">4.a. </span>Runlevels</p>
<p class="secthead"><a name="book_part2_chap4__chap1_sect1">Booting your System</a></p>
<p>
When you boot your system, you will notice lots of text floating by. If you pay
close attention, you will notice this text is the same every time you reboot
your system. The sequence of all these actions is called the <span class="emphasis">boot
sequence</span> and is (more or less) statically defined.
</p>
<p>
First, your boot loader will load the kernel image you have defined in the
boot loader configuration into memory after which it tells the CPU to run the
kernel. When the kernel is loaded and run, it initializes all kernel-specific
structures and tasks and starts the <span class="code" dir="ltr">init</span> process.
</p>
<p>
This process then makes sure that all filesystems (defined in
<span class="path" dir="ltr">/etc/fstab</span>) are mounted and ready to be used. Then it executes
several scripts located in <span class="path" dir="ltr">/etc/init.d</span>, which will start the
services you need in order to have a successfully booted system.
</p>
<p>
Finally, when all scripts are executed, <span class="code" dir="ltr">init</span> activates the terminals
(in most cases just the virtual consoles which are hidden beneath <span class="code" dir="ltr">Alt-F1</span>,
<span class="code" dir="ltr">Alt-F2</span>, etc.) attaching a special process called <span class="code" dir="ltr">agetty</span> to it.
This process will then make sure you are able to log on through these terminals
by running <span class="code" dir="ltr">login</span>.
</p>
<p class="secthead"><a name="book_part2_chap4__chap1_sect2">Init Scripts</a></p>
<p>
Now <span class="code" dir="ltr">init</span> doesn't just execute the scripts in <span class="path" dir="ltr">/etc/init.d</span>
randomly. Even more, it doesn't run all scripts in <span class="path" dir="ltr">/etc/init.d</span>,
only the scripts it is told to execute. It decides which scripts to execute by
looking into <span class="path" dir="ltr">/etc/runlevels</span>.
</p>
<p>
First, <span class="code" dir="ltr">init</span> runs all scripts from <span class="path" dir="ltr">/etc/init.d</span> that have
symbolic links inside <span class="path" dir="ltr">/etc/runlevels/boot</span>. Usually, it will
start the scripts in alphabetical order, but some scripts have dependency
information in them, telling the system that another script must be run before
they can be started.
</p>
<p>
When all <span class="path" dir="ltr">/etc/runlevels/boot</span> referenced scripts are executed,
<span class="code" dir="ltr">init</span> continues with running the scripts that have a symbolic link to them
in <span class="path" dir="ltr">/etc/runlevels/default</span>. Again, it will use the alphabetical
order to decide what script to run first, unless a script has dependency
information in it, in which case the order is changed to provide a valid
start-up sequence.
</p>
<p class="secthead"><a name="book_part2_chap4__chap1_sect3">How Init Works</a></p>
<p>
Of course <span class="code" dir="ltr">init</span> doesn't decide all that by itself. It needs a
configuration file that specifies what actions need to be taken. This
configuration file is <span class="path" dir="ltr">/etc/inittab</span>.
</p>
<p>
If you remember the boot sequence we have just described, you will remember
that <span class="code" dir="ltr">init</span>'s first action is to mount all filesystems. This is defined in
the following line from <span class="path" dir="ltr">/etc/inittab</span>:
</p>
<a name="book_part2_chap4__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: The system initialisation line in /etc/inittab</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
si::sysinit:/sbin/rc sysinit
</pre></td></tr>
</table>
<p>
This line tells <span class="code" dir="ltr">init</span> that it must run <span class="code" dir="ltr">/sbin/rc sysinit</span> to
initialize the system. The <span class="path" dir="ltr">/sbin/rc</span> script takes care of the
initialisation, so you might say that <span class="code" dir="ltr">init</span> doesn't do much -- it
delegates the task of initialising the system to another process.
</p>
<p>
Second, <span class="code" dir="ltr">init</span> executed all scripts that had symbolic links in
<span class="path" dir="ltr">/etc/runlevels/boot</span>. This is defined in the following line:
</p>
<a name="book_part2_chap4__chap1_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.2: The system initialisation, continued</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
rc::bootwait:/sbin/rc boot
</pre></td></tr>
</table>
<p>
Again the <span class="code" dir="ltr">rc</span> script performs the necessary tasks. Note that the option
given to <span class="code" dir="ltr">rc</span> (<span class="emphasis">boot</span>) is the same as the subdirectory of
<span class="path" dir="ltr">/etc/runlevels</span> that is used.
</p>
<p>
Now <span class="code" dir="ltr">init</span> checks its configuration file to see what <span class="emphasis">runlevel</span> it
should run. To decide this, it reads the following line from
<span class="path" dir="ltr">/etc/inittab</span>:
</p>
<a name="book_part2_chap4__chap1_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.3: The initdefault line</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
id:3:initdefault:
</pre></td></tr>
</table>
<p>
In this case (which the majority of Gentoo users will use), the <span class="emphasis">runlevel</span>
id is 3. Using this information, <span class="code" dir="ltr">init</span> checks what it must run to start
<span class="emphasis">runlevel 3</span>:
</p>
<a name="book_part2_chap4__chap1_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.4: The runlevel definitions</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
l0:0:wait:/sbin/rc shutdown
l1:S1:wait:/sbin/rc single
l2:2:wait:/sbin/rc nonetwork
l3:3:wait:/sbin/rc default
l4:4:wait:/sbin/rc default
l5:5:wait:/sbin/rc default
l6:6:wait:/sbin/rc reboot
</pre></td></tr>
</table>
<p>
The line that defines level 3, again, uses the <span class="code" dir="ltr">rc</span> script to start the
services (now with argument <span class="emphasis">default</span>). Again note that the argument of
<span class="code" dir="ltr">rc</span> is the same as the subdirectory from <span class="path" dir="ltr">/etc/runlevels</span>.
</p>
<p>
When <span class="code" dir="ltr">rc</span> has finished, <span class="code" dir="ltr">init</span> decides what virtual consoles it should
activate and what commands need to be run at each console:
</p>
<a name="book_part2_chap4__chap1_pre5"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.5: The virtual consoles definition</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
c1:12345:respawn:/sbin/agetty 38400 tty1 linux
c2:12345:respawn:/sbin/agetty 38400 tty2 linux
c3:12345:respawn:/sbin/agetty 38400 tty3 linux
c4:12345:respawn:/sbin/agetty 38400 tty4 linux
c5:12345:respawn:/sbin/agetty 38400 tty5 linux
c6:12345:respawn:/sbin/agetty 38400 tty6 linux
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part2_chap4__chap1_sect4">What is a runlevel?</a></p>
<p>
You have seen that <span class="code" dir="ltr">init</span> uses a numbering scheme to decide what
<span class="emphasis">runlevel</span> it should activate. A <span class="emphasis">runlevel</span> is a state in which
your system is running and contains a collection of scripts (runlevel scripts or
<span class="emphasis">initscripts</span>) that must be executed when you enter or leave a runlevel.
</p>
<p>
In Gentoo, there are seven runlevels defined: three internal runlevels, and four
user-defined runlevels. The internal runlevels are called <span class="emphasis">sysinit</span>,
<span class="emphasis">shutdown</span> and <span class="emphasis">reboot</span> and do exactly what their names imply:
initialize the system, powering off the system and rebooting the system.
</p>
<p>
The user-defined runlevels are those with an accompanying
<span class="path" dir="ltr">/etc/runlevels</span> subdirectory: <span class="path" dir="ltr">boot</span>,
<span class="path" dir="ltr">default</span>, <span class="path" dir="ltr">nonetwork</span> and <span class="path" dir="ltr">single</span>. The
<span class="path" dir="ltr">boot</span> runlevel starts all system-necessary services which all other
runlevels use. The remaining three runlevels differ in what services they start:
<span class="path" dir="ltr">default</span> is used for day-to-day operations, <span class="path" dir="ltr">nonetwork</span>
is used in case no network connectivity is required, and <span class="path" dir="ltr">single</span> is
used when you need to fix the system.
</p>
<p class="secthead"><a name="book_part2_chap4__chap1_sect5">Working with the Init Scripts</a></p>
<p>
The scripts that the <span class="code" dir="ltr">rc</span> process starts are called <span class="emphasis">init scripts</span>.
Each script in <span class="path" dir="ltr">/etc/init.d</span> can be executed with the arguments
<span class="emphasis">start</span>, <span class="emphasis">stop</span>, <span class="emphasis">restart</span>, <span class="emphasis">zap</span>,
<span class="emphasis">status</span>, <span class="emphasis">ineed</span>, <span class="emphasis">iuse</span>, <span class="emphasis">needsme</span>, <span class="emphasis">usesme</span> or
<span class="emphasis">broken</span>.
</p>
<p>
To start, stop or restart a service (and all depending services), <span class="code" dir="ltr">start</span>,
<span class="code" dir="ltr">stop</span> and <span class="code" dir="ltr">restart</span> should be used:
</p>
<a name="book_part2_chap4__chap1_pre6"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.6: Starting Postfix</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">/etc/init.d/postfix start</span>
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
Only the services that <span class="emphasis">need</span> the given service are stopped or restarted.
The other depending services (those that <span class="emphasis">use</span> the service but don't need
it) are left untouched.
</p></td></tr></table>
<p>
If you want to stop a service, but not the services that depend on it, you can
use the <span class="code" dir="ltr">--nodeps</span> argument together with the <span class="code" dir="ltr">stop</span> command:
</p>
<a name="book_part2_chap4__chap1_pre7"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.7: Stopping Postfix but keep the depending services running</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">/etc/init.d/postfix --nodeps stop</span>
</pre></td></tr>
</table>
<p>
If you want to see what status a service has (started, stopped, ...) you
can use the <span class="code" dir="ltr">status</span> argument:
</p>
<a name="book_part2_chap4__chap1_pre8"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.8: Status information for postfix</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">/etc/init.d/postfix status</span>
</pre></td></tr>
</table>
<p>
If the status information tells you that the service is running, but you know
that it is not, then you can reset the status information to "stopped" with the
<span class="code" dir="ltr">zap</span> argument:
</p>
<a name="book_part2_chap4__chap1_pre9"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.9: Resetting status information for postfix</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">/etc/init.d/postfix zap</span>
</pre></td></tr>
</table>
<p>
To also ask what dependencies the service has, you can use <span class="code" dir="ltr">iuse</span> or
<span class="code" dir="ltr">ineed</span>. With <span class="code" dir="ltr">ineed</span> you can see the services that are really
necessary for the correct functioning of the service. <span class="code" dir="ltr">iuse</span> on the other
hand shows the services that can be used by the service, but are not necessary
for the correct functioning.
</p>
<a name="book_part2_chap4__chap1_pre10"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.10: Requesting a list of all necessary services on which Postfix depends</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">/etc/init.d/postfix ineed</span>
</pre></td></tr>
</table>
<p>
Similarly, you can ask what services require the service (<span class="code" dir="ltr">needsme</span>) or can
use it (<span class="code" dir="ltr">usesme</span>):
</p>
<a name="book_part2_chap4__chap1_pre11"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.11: Requesting a list of all services that require Postfix</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">/etc/init.d/postfix needsme</span>
</pre></td></tr>
</table>
<p>
Finally, you can ask what dependencies the service requires that are missing:
</p>
<a name="book_part2_chap4__chap1_pre12"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.12: Requesting a list of missing dependencies for Postfix</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">/etc/init.d/postfix broken</span>
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part2_chap4__chap2"></a><span class="chapnum">4.b. </span>Working with rc-update</p>
<p class="secthead"><a name="book_part2_chap4__chap2_sect1">What is rc-update?</a></p>
<p>
Gentoo's init system uses a dependency-tree to decide what service needs to be
started first. As this is a tedious task that we wouldn't want our users to
have to do manually, we have created tools that ease the administration of the
runlevels and init scripts.
</p>
<p>
With <span class="code" dir="ltr">rc-update</span> you can add and remove init scripts to a runlevel. The
<span class="code" dir="ltr">rc-update</span> tool will then automatically ask the <span class="code" dir="ltr">depscan.sh</span> script
to rebuild the dependency tree.
</p>
<p class="secthead"><a name="book_part2_chap4__chap2_sect2">Adding and Removing Services</a></p>
<p>
You have already added init scripts to the "default" runlevel during the
installation of Gentoo. At that time you might not have had a clue what the
"default" is for, but now you should. The <span class="code" dir="ltr">rc-update</span> script requires a
second argument that defines the action: <span class="emphasis">add</span>, <span class="emphasis">del</span> or <span class="emphasis">show</span>.
</p>
<p>
To add or remove an init script, just give <span class="code" dir="ltr">rc-update</span> the <span class="code" dir="ltr">add</span> or
<span class="code" dir="ltr">del</span> argument, followed by the init script and the runlevel. For instance:
</p>
<a name="book_part2_chap4__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: Removing Postfix from the default runlevel</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">rc-update del postfix default</span>
</pre></td></tr>
</table>
<p>
The <span class="code" dir="ltr">rc-update -v show</span> command will show all the available init scripts and
list at which runlevels they will execute:
</p>
<a name="book_part2_chap4__chap2_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.2: Receiving init script information</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">rc-update -v show</span>
</pre></td></tr>
</table>
<p>
You can also run <span class="code" dir="ltr">rc-update show</span> (without <span class="code" dir="ltr">-v</span>) to just view enabled
init scripts and their runlevels.
</p>
<p class="chaphead"><a name="book_part2_chap4__chap3"></a><span class="chapnum">4.c. </span>Configuring Services</p>
<p class="secthead"><a name="book_part2_chap4__chap3_sect1">Why the Need for Extra Configuration?</a></p>
<p>
Init scripts can be quite complex. It is therefore not really desirable to
have the users edit the init script directly, as it would make it more
error-prone. It is however important to be able to configure such a service. For
instance, you might want to give more options to the service itself.
</p>
<p>
A second reason to have this configuration outside the init script is to be
able to update the init scripts without the fear that your configuration
changes will be undone.
</p>
<p class="secthead"><a name="book_part2_chap4__chap3_sect2">The /etc/conf.d Directory</a></p>
<p>
Gentoo provides an easy way to configure such a service: every init script that
can be configured has a file in <span class="path" dir="ltr">/etc/conf.d</span>. For instance, the
apache2 initscript (called <span class="path" dir="ltr">/etc/init.d/apache2</span>) has a
configuration file called <span class="path" dir="ltr">/etc/conf.d/apache2</span>, which can contain
the options you want to give to the Apache 2 server when it is started:
</p>
<a name="book_part2_chap4__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: Variable defined in /etc/conf.d/apache2</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
APACHE2_OPTS="-D PHP5"
</pre></td></tr>
</table>
<p>
Such a configuration file contains variables and variables alone (just like
<span class="path" dir="ltr">/etc/portage/make.conf</span>), making it very easy to configure services.
It also allows us to provide more information about the variables (as comments).
</p>
<p class="chaphead"><a name="book_part2_chap4__chap4"></a><span class="chapnum">4.d. </span>Writing Init Scripts</p>
<p class="secthead"><a name="book_part2_chap4__chap4_sect1">Do I Have To?</a></p>
<p>
No, writing an init script is usually not necessary as Gentoo provides
ready-to-use init scripts for all provided services. However, you might have
installed a service without using Portage, in which case you will most likely
have to create an init script.
</p>
<p>
Do not use the init script provided by the service if it isn't explicitly
written for Gentoo: Gentoo's init scripts are not compatible with the init
scripts used by other distributions!
</p>
<p class="secthead"><a name="book_part2_chap4__chap4_sect2">Layout</a></p>
<p>
The basic layout of an init script is shown below.
</p>
<a name="book_part2_chap4__chap4_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.1: Basic layout of an init script</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
#!/sbin/runscript
depend() {
<span class="code-comment">(Dependency information)</span>
}
start() {
<span class="code-comment">(Commands necessary to start the service)</span>
}
stop() {
<span class="code-comment">(Commands necessary to stop the service)</span>
}
</pre></td></tr>
</table>
<p>
Any init script <span class="emphasis">requires</span> the <span class="code" dir="ltr">start()</span> function to be defined. All
other sections are optional.
</p>
<p class="secthead"><a name="book_part2_chap4__chap4_sect3">Dependencies</a></p>
<p>
There are two dependency-alike settings you can define that influence the
start-up or sequencing of init scripts: <span class="code" dir="ltr">use</span> and <span class="code" dir="ltr">need</span>. Next to
these two, there are also two order-influencing methods called <span class="code" dir="ltr">before</span> and
<span class="code" dir="ltr">after</span>. These last two are no dependencies per se - they do not make the
original init script fail if the selected one isn't scheduled to start (or fails
to start).
</p>
<ul>
<li>
The <span class="code" dir="ltr">use</span> settings informs the init system that this script <span class="emphasis">uses</span>
functionality offered by the selected script, but does not directly depend
on it. A good example would be <span class="code" dir="ltr">use logger</span> or <span class="code" dir="ltr">use dns</span>. If those
services are available, they will be put in good use, but if you do not have
a logger or DNS server the services will still work. If the services exist,
then they are started before the script that <span class="code" dir="ltr">use</span>'s them.
</li>
<li>
The <span class="code" dir="ltr">need</span> setting is a hard dependency. It means that the script that
is <span class="code" dir="ltr">need</span>'ing another script will not start before the other script is
launched successfully. Also, if that other script is restarted, then this
one will be restarted as well.
</li>
<li>
When using <span class="code" dir="ltr">before</span>, then the given script is launched before the
selected one <span class="emphasis">if</span> the selected one is part of the init level. So an
init script <span class="path" dir="ltr">xdm</span> that defines <span class="code" dir="ltr">before alsasound</span> will start
before the <span class="path" dir="ltr">alsasound</span> script, but only if <span class="path" dir="ltr">alsasound</span>
is scheduled to start as well in the same init level. If
<span class="path" dir="ltr">alsasound</span> is not scheduled to start too, then this particular
setting has no effect and <span class="path" dir="ltr">xdm</span> will be started when the init
system deems it most appropriate.
</li>
<li>
Similarly, <span class="code" dir="ltr">after</span> informs the init system that the given script should
be launched after the selected one <span class="emphasis">if</span> the selected one is part of the
init level. If not, then the setting has no effect and the script will be
launched by the init system when it deems it most appropriate.
</li>
</ul>
<p>
It should be clear from the above that <span class="code" dir="ltr">need</span> is the only "true" dependency
setting as it affects if the script will be started or not. All the others are
merely pointers towards the init system to clarify in which order scripts can be
(or should be) launched.
</p>
<p>
Now, if you look at many of Gentoo's available init scripts, you will notice
that some have dependencies on things that are no init scripts. These "things"
we call <span class="emphasis">virtuals</span>.
</p>
<p>
A <span class="emphasis">virtual</span> dependency is a dependency that a service provides, but that is
not provided solely by that service. Your init script can depend on a system
logger, but there are many system loggers available (metalogd, syslog-ng,
sysklogd, ...). As you cannot <span class="code" dir="ltr">need</span> every single one of them (no sensible
system has all these system loggers installed and running) we made sure that
all these services <span class="code" dir="ltr">provide</span> a virtual dependency.
</p>
<p>
Let us take a look at the dependency information for the postfix service.
</p>
<a name="book_part2_chap4__chap4_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.2: Dependency information for Postfix</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
depend() {
need net
use logger dns
provide mta
}
</pre></td></tr>
</table>
<p>
As you can see, the postfix service:
</p>
<ul>
<li>
requires the (virtual) <span class="code" dir="ltr">net</span> dependency (which is provided by, for
instance, <span class="path" dir="ltr">/etc/init.d/net.eth0</span>)
</li>
<li>
uses the (virtual) <span class="code" dir="ltr">logger</span> dependency (which is provided by, for
instance, <span class="path" dir="ltr">/etc/init.d/syslog-ng</span>)
</li>
<li>
uses the (virtual) <span class="code" dir="ltr">dns</span> dependency (which is provided by, for
instance, <span class="path" dir="ltr">/etc/init.d/named</span>)
</li>
<li>
provides the (virtual) <span class="code" dir="ltr">mta</span> dependency (which is common for all mail
servers)
</li>
</ul>
<p class="secthead"><a name="book_part2_chap4__chap4_sect4">Controlling the Order</a></p>
<p>
As we described in the previous section, you can tell the init system what order
it should use for starting (or stopping) scripts. This ordering is handled both
through the dependency settings <span class="code" dir="ltr">use</span> and <span class="code" dir="ltr">need</span>, but also through the
order settings <span class="code" dir="ltr">before</span> and <span class="code" dir="ltr">after</span>. As we have described these
earlier already, let's take a look at the Portmap service as an example of such
init script.
</p>
<a name="book_part2_chap4__chap4_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.3: The depend() function in the Portmap service</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
depend() {
need net
before inetd
before xinetd
}
</pre></td></tr>
</table>
<p>
You can also use the "*" glob to catch all services in the same runlevel,
although this isn't advisable.
</p>
<a name="book_part2_chap4__chap4_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.4: Running an init script as first script in the runlevel</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
depend() {
before *
}
</pre></td></tr>
</table>
<p>
If your service must write to local disks, it should need <span class="code" dir="ltr">localmount</span>. If
it places anything in <span class="path" dir="ltr">/var/run</span> such as a pidfile, then it should
start after <span class="code" dir="ltr">bootmisc</span>:
</p>
<a name="book_part2_chap4__chap4_pre5"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.5: Example depend() function</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
depend() {
need localmount
after bootmisc
}
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part2_chap4__chap4_sect5">Standard Functions</a></p>
<p>
Next to the <span class="code" dir="ltr">depend()</span> functionality, you also need to define the
<span class="code" dir="ltr">start()</span> function. This one contains all the commands necessary to
initialize your service. It is advisable to use the <span class="code" dir="ltr">ebegin</span> and
<span class="code" dir="ltr">eend</span> functions to inform the user about what is happening:
</p>
<a name="book_part2_chap4__chap4_pre6"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.6: Example start() function</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
start() {
if [ "${RC_CMD}" = "restart" ];
then
<span class="code-comment"># Do something in case a restart requires more than stop, start</span>
fi
ebegin "Starting my_service"
start-stop-daemon --start --exec /path/to/my_service \
--pidfile /path/to/my_pidfile
eend $?
}
</pre></td></tr>
</table>
<p>
Both <span class="code" dir="ltr">--exec</span> and <span class="code" dir="ltr">--pidfile</span> should be used in start and stop
functions. If the service does not create a pidfile, then use
<span class="code" dir="ltr">--make-pidfile</span> if possible, though you should test this to be sure.
Otherwise, don't use pidfiles. You can also add <span class="code" dir="ltr">--quiet</span> to the
<span class="code" dir="ltr">start-stop-daemon</span> options, but this is not recommended unless the
service is extremely verbose. Using <span class="code" dir="ltr">--quiet</span> may hinder debugging if the
service fails to start.
</p>
<p>
Another notable setting used in the above example is to check the contents of
the <span class="code" dir="ltr">RC_CMD</span> variable. Unlike the previous init script system, the newer
<span class="code" dir="ltr">openrc</span> system does not support script-specific restart functionality.
Instead, the script needs to check the contents of the <span class="code" dir="ltr">RC_CMD</span> variable
to see if a function (be it <span class="code" dir="ltr">start()</span> or <span class="code" dir="ltr">stop()</span>) is called as part
of a restart or not.
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
Make sure that <span class="code" dir="ltr">--exec</span> actually calls a service and not just a shell
script that launches services and exits -- that's what the init script is
supposed to do.
</p></td></tr></table>
<p>
If you need more examples of the <span class="code" dir="ltr">start()</span> function, please read the
source code of the available init scripts in your <span class="path" dir="ltr">/etc/init.d</span>
directory.
</p>
<p>
Another function you can define is <span class="code" dir="ltr">stop()</span>. You are not obliged to define
this function though! Our init system is intelligent enough to fill in this
function by itself if you use <span class="code" dir="ltr">start-stop-daemon</span>.
</p>
<p>
Here is an example of a <span class="code" dir="ltr">stop()</span> function:
</p>
<a name="book_part2_chap4__chap4_pre7"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.7: Example stop() function</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
stop() {
ebegin "Stopping my_service"
start-stop-daemon --stop --exec /path/to/my_service \
--pidfile /path/to/my_pidfile
eend $?
}
</pre></td></tr>
</table>
<p>
If your service runs some other script (for example, bash, python, or perl),
and this script later changes names (for example, <span class="code" dir="ltr">foo.py</span> to <span class="code" dir="ltr">foo</span>),
then you will need to add <span class="code" dir="ltr">--name</span> to <span class="code" dir="ltr">start-stop-daemon</span>. You must
specify the name that your script will be changed to. In this example, a
service starts <span class="code" dir="ltr">foo.py</span>, which changes names to <span class="code" dir="ltr">foo</span>:
</p>
<a name="book_part2_chap4__chap4_pre8"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.8: A service that starts the foo script</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
start() {
ebegin "Starting my_script"
start-stop-daemon --start --exec /path/to/my_script \
--pidfile /path/to/my_pidfile --name foo
eend $?
}
</pre></td></tr>
</table>
<p>
<span class="code" dir="ltr">start-stop-daemon</span> has an excellent man page available if you need more
information:
</p>
<a name="book_part2_chap4__chap4_pre9"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.9: Getting the man page for start-stop-daemon</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
$ <span class="code-input">man start-stop-daemon</span>
</pre></td></tr>
</table>
<p>
Gentoo's init script syntax is based on the POSIX Shell so you are
free to use sh-compatible constructs inside your init script. Keep other
constructs, like bash-specific ones, out of the init scripts to ensure that the
scripts remain functional regardless of the change Gentoo might do on its init
system.
</p>
<p class="secthead"><a name="book_part2_chap4__chap4_sect6">Adding Custom Options</a></p>
<p>
If you want your init script to support more options than the ones we have
already encountered, you should add the option to the <span class="code" dir="ltr">extra_commands</span>
variable, and create a function with the same name as the option. For instance,
to support an option called <span class="code" dir="ltr">restartdelay</span>:
</p>
<a name="book_part2_chap4__chap4_pre10"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.10: Supporting the restartdelay option</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
extra_commands="restartdelay"
restartdelay() {
stop
sleep 3 <span class="code-comment"># Wait 3 seconds before starting again</span>
start
}
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffffbb"><p class="note"><b>Important: </b>
The function <span class="code" dir="ltr">restart()</span> cannot be overridden in openrc!
</p></td></tr></table>
<p class="secthead"><a name="book_part2_chap4__chap4_sect7">Service Configuration Variables</a></p>
<p>
You don't have to do anything to support a configuration file in
<span class="path" dir="ltr">/etc/conf.d</span>: if your init script is executed, the following files
are automatically sourced (i.e. the variables are available to use):
</p>
<ul>
<li><span class="path" dir="ltr">/etc/conf.d/&lt;your init script&gt;</span></li>
<li><span class="path" dir="ltr">/etc/conf.d/basic</span></li>
<li><span class="path" dir="ltr">/etc/rc.conf</span></li>
</ul>
<p>
Also, if your init script provides a virtual dependency (such as <span class="code" dir="ltr">net</span>),
the file associated with that dependency (such as <span class="path" dir="ltr">/etc/conf.d/net</span>)
will be sourced too.
</p>
<p class="chaphead"><a name="book_part2_chap4__chap5"></a><span class="chapnum">4.e. </span>Changing the Runlevel Behaviour</p>
<p class="secthead"><a name="book_part2_chap4__chap5_sect1">Who might benefit from this?</a></p>
<p>
Many laptop users know the situation: at home you need to start <span class="code" dir="ltr">net.eth0</span>
while you don't want to start <span class="code" dir="ltr">net.eth0</span> while you're on the road (as
there is no network available). With Gentoo you can alter the runlevel behaviour
to your own will.
</p>
<p>
For instance you can create a second "default" runlevel which you can boot that
has other init scripts assigned to it. You can then select at boottime what
default runlevel you want to use.
</p>
<p class="secthead"><a name="book_part2_chap4__chap5_sect2">Using softlevel</a></p>
<p>
First of all, create the runlevel directory for your second "default" runlevel.
As an example we create the <span class="path" dir="ltr">offline</span> runlevel:
</p>
<a name="book_part2_chap4__chap5_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.1: Creating a runlevel directory</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">mkdir /etc/runlevels/offline</span>
</pre></td></tr>
</table>
<p>
Add the necessary init scripts to the newly created runlevels. For instance, if
you want to have an exact copy of your current <span class="code" dir="ltr">default</span> runlevel but
without <span class="code" dir="ltr">net.eth0</span>:
</p>
<a name="book_part2_chap4__chap5_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.2: Adding the necessary init scripts</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment">(Copy all services from default runlevel to offline runlevel)</span>
# <span class="code-input">cd /etc/runlevels/default</span>
# <span class="code-input">for service in *; do rc-update add $service offline; done</span>
<span class="code-comment">(Remove unwanted service from offline runlevel)</span>
# <span class="code-input">rc-update del net.eth0 offline</span>
<span class="code-comment">(Display active services for offline runlevel)</span>
# <span class="code-input">rc-update show offline</span>
<span class="code-comment">(Partial sample Output)</span>
acpid | offline
domainname | offline
local | offline
net.eth0 |
</pre></td></tr>
</table>
<p>
Even though <span class="code" dir="ltr">net.eth0</span> has been removed from the offline runlevel,
<span class="code" dir="ltr">udev</span> might want to attempt to start any devices it detects and launch the
appropriate services, a functionality that is called <span class="emphasis">hotplugging</span>. By
default, Gentoo does not enable hotplugging.
</p>
<p>
If you do want to enable hotplugging, but only for a selected set of scripts,
use the <span class="code" dir="ltr">rc_hotplug</span> variable in <span class="path" dir="ltr">/etc/rc.conf</span>:
</p>
<a name="book_part2_chap4__chap5_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.3: Disabling device initiated services in /etc/rc.conf</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment"># Allow net.wlan as well as any other service, except those matching net.*
# to be hotplugged</span>
rc_hotplug="net.wlan !net.*"
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
For more information on device initiated services, please see the comments
inside <span class="path" dir="ltr">/etc/rc.conf</span>.
</p></td></tr></table>
<p>
Now edit your bootloader configuration and add a new entry for the
<span class="code" dir="ltr">offline</span> runlevel. For instance, in <span class="path" dir="ltr">/boot/grub/grub.conf</span>:
</p>
<a name="book_part2_chap4__chap5_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.4: Adding an entry for the offline runlevel</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
title Gentoo Linux Offline Usage
root (hd0,0)
kernel (hd0,0)/kernel-2.4.25 root=/dev/hda3 <span class="code-input">softlevel=offline</span>
</pre></td></tr>
</table>
<p>
Voilà, you're all set now. If you boot your system and select the newly added
entry at boot, the <span class="code" dir="ltr">offline</span> runlevel will be used instead of the
<span class="code" dir="ltr">default</span> one.
</p>
<p class="secthead"><a name="book_part2_chap4__chap5_sect3">Using bootlevel</a></p>
<p>
Using <span class="code" dir="ltr">bootlevel</span> is completely analogous to <span class="code" dir="ltr">softlevel</span>. The only
difference here is that you define a second "boot" runlevel instead of a second
"default" runlevel.
</p>
<a name="book_part2_chap5"></a><h3>5. Environment Variables</h3>
<p class="chaphead"><a name="book_part2_chap5__chap1"></a><span class="chapnum">5.a. </span>Environment Variables?</p>
<p class="secthead"><a name="book_part2_chap5__chap1_sect1">What they are</a></p>
<p>
An environment variable is a named object that contains information used by one
or more applications. Many users (and especially those new to Linux) find this
a bit weird or unmanageable. However, this is a mistake: by using environment
variables one can easily change a configuration setting for one or more
applications.
</p>
<p class="secthead"><a name="book_part2_chap5__chap1_sect2">Important Examples</a></p>
<p>
The following table lists a number of variables used by a Linux system and
describes their use. Example values are presented after the table.
</p>
<table class="ntable">
<tr>
<td class="infohead"><b>Variable</b></td>
<td class="infohead"><b>Description</b></td>
</tr>
<tr>
<td class="tableinfo">PATH</td>
<td class="tableinfo">
This variable contains a colon-separated list of directories in which your
system looks for executable files. If you enter a name of an executable
(such as <span class="code" dir="ltr">ls</span>, <span class="code" dir="ltr">rc-update</span> or <span class="code" dir="ltr">emerge</span>) but this executable
is not located in a listed directory, your system will not execute it
(unless you enter the full path as command, such as <span class="code" dir="ltr">/bin/ls</span>).
</td>
</tr>
<tr>
<td class="tableinfo">ROOTPATH</td>
<td class="tableinfo">
This variable has the same function as <span class="code" dir="ltr">PATH</span>, but this one only lists
the directories that should be checked when the root-user enters a command.
</td>
</tr>
<tr>
<td class="tableinfo">LDPATH</td>
<td class="tableinfo">
This variable contains a colon-separated list of directories in which the
dynamical linker searches through to find a library.
</td>
</tr>
<tr>
<td class="tableinfo">MANPATH</td>
<td class="tableinfo">
This variable contains a colon-separated list of directories in which the
<span class="code" dir="ltr">man</span> command searches for the man pages.
</td>
</tr>
<tr>
<td class="tableinfo">INFODIR</td>
<td class="tableinfo">
This variable contains a colon-separated list of directories in which the
<span class="code" dir="ltr">info</span> command searches for the info pages.
</td>
</tr>
<tr>
<td class="tableinfo">PAGER</td>
<td class="tableinfo">
This variable contains the path to the program used to list the contents of
files through (such as <span class="code" dir="ltr">less</span> or <span class="code" dir="ltr">more</span>).
</td>
</tr>
<tr>
<td class="tableinfo">EDITOR</td>
<td class="tableinfo">
This variable contains the path to the program used to change the contents
of files with (such as <span class="code" dir="ltr">nano</span> or <span class="code" dir="ltr">vi</span>).
</td>
</tr>
<tr>
<td class="tableinfo">KDEDIRS</td>
<td class="tableinfo">
This variable contains a colon-separated list of directories which contain
KDE-specific material.
</td>
</tr>
<tr>
<td class="tableinfo">CONFIG_PROTECT</td>
<td class="tableinfo">
This variable contains a <span class="emphasis">space</span>-delimited list of directories which
should be protected by Portage during updates.
</td>
</tr>
<tr>
<td class="tableinfo">CONFIG_PROTECT_MASK</td>
<td class="tableinfo">
This variable contains a <span class="emphasis">space</span>-delimited list of directories which
should not be protected by Portage during updates.
</td>
</tr>
</table>
<p>
Below you will find an example definition of all these variables:
</p>
<a name="book_part2_chap5__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: Example definitions</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
PATH="/bin:/usr/bin:/usr/local/bin:/opt/bin:/usr/games/bin"
ROOTPATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
LDPATH="/lib:/usr/lib:/usr/local/lib:/usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3"
MANPATH="/usr/share/man:/usr/local/share/man"
INFODIR="/usr/share/info:/usr/local/share/info"
PAGER="/usr/bin/less"
EDITOR="/usr/bin/vim"
KDEDIRS="/usr"
CONFIG_PROTECT="/usr/X11R6/lib/X11/xkb /opt/tomcat/conf \
/usr/kde/3.1/share/config /usr/share/texmf/tex/generic/config/ \
/usr/share/texmf/tex/platex/config/ /usr/share/config"
CONFIG_PROTECT_MASK="/etc/gconf"
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part2_chap5__chap2"></a><span class="chapnum">5.b. </span>Defining Variables Globally</p>
<p class="secthead"><a name="book_part2_chap5__chap2_sect1">The /etc/env.d Directory</a></p>
<p>
To centralise the definitions of these variables, Gentoo introduced the
<span class="path" dir="ltr">/etc/env.d</span> directory. Inside this directory you will find a number
of files, such as <span class="path" dir="ltr">00basic</span>, <span class="path" dir="ltr">05gcc</span>, etc. which contain
the variables needed by the application mentioned in their name.
</p>
<p>
For instance, when you installed <span class="code" dir="ltr">gcc</span>, a file called <span class="path" dir="ltr">05gcc</span>
was created by the ebuild which contains the definitions of the following
variables:
</p>
<a name="book_part2_chap5__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: /etc/env.d/05gcc</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
PATH="/usr/i686-pc-linux-gnu/gcc-bin/3.2"
ROOTPATH="/usr/i686-pc-linux-gnu/gcc-bin/3.2"
MANPATH="/usr/share/gcc-data/i686-pc-linux-gnu/3.2/man"
INFOPATH="/usr/share/gcc-data/i686-pc-linux-gnu/3.2/info"
CC="gcc"
CXX="g++"
LDPATH="/usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3"
</pre></td></tr>
</table>
<p>
Other distributions tell you to change or add such environment variable
definitions in <span class="path" dir="ltr">/etc/profile</span> or other locations. Gentoo on the other
hand makes it easy for you (and for Portage) to maintain and manage the
environment variables without having to pay attention to the numerous files that
can contain environment variables.
</p>
<p>
For instance, when <span class="code" dir="ltr">gcc</span> is updated, the <span class="path" dir="ltr">/etc/env.d/05gcc</span> file
is updated too without requesting any user-interaction.
</p>
<p>
This not only benefits Portage, but also you, as user. Occasionally you might
be asked to set a certain environment variable system-wide. As an example we
take the <span class="code" dir="ltr">http_proxy</span> variable. Instead of messing about with
<span class="path" dir="ltr">/etc/profile</span>, you can now just create a file
(<span class="path" dir="ltr">/etc/env.d/99local</span>) and enter your definition(s) in it:
</p>
<a name="book_part2_chap5__chap2_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.2: /etc/env.d/99local</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
http_proxy="proxy.server.com:8080"
</pre></td></tr>
</table>
<p>
By using the same file for all your variables, you have a quick overview on the
variables you have defined yourself.
</p>
<p class="secthead"><a name="book_part2_chap5__chap2_sect2">The env-update Script</a></p>
<p>
Several files in <span class="path" dir="ltr">/etc/env.d</span> define the <span class="code" dir="ltr">PATH</span> variable. This
is not a mistake: when you run <span class="code" dir="ltr">env-update</span>, it will append the several
definitions before it updates the environment variables, thereby making it easy
for packages (or users) to add their own environment variable settings without
interfering with the already existing values.
</p>
<p>
The <span class="code" dir="ltr">env-update</span> script will append the values in the alphabetical order
of the <span class="path" dir="ltr">/etc/env.d</span> files. The file names must begin with two
decimal digits.
</p>
<a name="book_part2_chap5__chap2_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.3: Update order used by env-update</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
00basic 99kde-env 99local
+-------------+----------------+-------------+
PATH="/bin:/usr/bin:/usr/kde/3.2/bin:/usr/local/bin"
</pre></td></tr>
</table>
<p>
The concatenation of variables does not always happen, only with the following
variables: <span class="code" dir="ltr">ADA_INCLUDE_PATH</span>, <span class="code" dir="ltr">ADA_OBJECTS_PATH</span>, <span class="code" dir="ltr">CLASSPATH</span>,
<span class="code" dir="ltr">KDEDIRS</span>, <span class="code" dir="ltr">PATH</span>, <span class="code" dir="ltr">LDPATH</span>, <span class="code" dir="ltr">MANPATH</span>,
<span class="code" dir="ltr">INFODIR</span>, <span class="code" dir="ltr">INFOPATH</span>, <span class="code" dir="ltr">ROOTPATH</span>, <span class="code" dir="ltr">CONFIG_PROTECT</span>,
<span class="code" dir="ltr">CONFIG_PROTECT_MASK</span>, <span class="code" dir="ltr">PRELINK_PATH</span>, <span class="code" dir="ltr">PRELINK_PATH_MASK</span>,
<span class="code" dir="ltr">PKG_CONFIG_PATH</span> and <span class="code" dir="ltr">PYTHONPATH</span>.
For all other variables the latest defined value (in alphabetical order of the
files in <span class="path" dir="ltr">/etc/env.d</span>) is used.
</p>
<p>
You can add more variables into this list of concatenate-variables by adding the
variable name to either <span class="code" dir="ltr">COLON_SEPARATED</span> or <span class="code" dir="ltr">SPACE_SEPARATED</span>
variables (also inside an env.d file).
</p>
<p>
When you run <span class="code" dir="ltr">env-update</span>, the script will create all environment variables
and place them in <span class="path" dir="ltr">/etc/profile.env</span> (which is used by
<span class="path" dir="ltr">/etc/profile</span>). It will also extract the information from the
<span class="code" dir="ltr">LDPATH</span> variable and use that to create <span class="path" dir="ltr">/etc/ld.so.conf</span>.
After this, it will run <span class="code" dir="ltr">ldconfig</span> to recreate the
<span class="path" dir="ltr">/etc/ld.so.cache</span> file used by the dynamical linker.
</p>
<p>
If you want to notice the effect of <span class="code" dir="ltr">env-update</span> immediately after you run
it, execute the following command to update your environment. Users who have
installed Gentoo themselves will probably remember this from the installation
instructions:
</p>
<a name="book_part2_chap5__chap2_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.4: Updating the environment</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">env-update &amp;&amp; source /etc/profile</span>
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
The above command only updates the variables in your current terminal,
<span class="emphasis">new</span> consoles, and their children. Thus, if you are working in X11, you
will need to either type <span class="code" dir="ltr">source /etc/profile</span> in every new terminal you
open or restart X so that all new terminals source the new variables. If you
use a login manager, become root and type <span class="code" dir="ltr">/etc/init.d/xdm restart</span>. If
not, you will need to logout and log back in for X to spawn children with the
new variable values.
</p></td></tr></table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffffbb"><p class="note"><b>Important: </b>
You cannot use shell variables when defining other variables. This means things
like <span class="code" dir="ltr">FOO="$BAR"</span> (where <span class="code" dir="ltr">$BAR</span> is another variable) are forbidden.
</p></td></tr></table>
<p class="chaphead"><a name="book_part2_chap5__chap3"></a><span class="chapnum">5.c. </span>Defining Variables Locally</p>
<p class="secthead"><a name="book_part2_chap5__chap3_sect1">User Specific</a></p>
<p>
You do not always want to define an environment variable globally. For instance,
you might want to add <span class="path" dir="ltr">/home/my_user/bin</span> and the current working
directory (the directory you are in) to the <span class="code" dir="ltr">PATH</span> variable
but don't want all other users on your system to have that in their <span class="code" dir="ltr">PATH</span>
too. If you want to define an environment variable locally, you should use
<span class="path" dir="ltr">~/.bashrc</span> or <span class="path" dir="ltr">~/.bash_profile</span>:
</p>
<a name="book_part2_chap5__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: Extending PATH for local usage in ~/.bashrc</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment">(A colon followed by no directory is treated as the current working directory)</span>
PATH="${PATH}:/home/my_user/bin:"
</pre></td></tr>
</table>
<p>
When you relogin, your <span class="code" dir="ltr">PATH</span> variable will be updated.
</p>
<p class="secthead"><a name="book_part2_chap5__chap3_sect2">Session Specific</a></p>
<p>
Sometimes even stricter definitions are requested. You might want to be able to
use binaries from a temporary directory you created without using the path to
the binaries themselves or editing <span class="path" dir="ltr">~/.bashrc</span> for the short time
you need it.
</p>
<p>
In this case, you can just define the <span class="code" dir="ltr">PATH</span> variable in your current
session by using the <span class="code" dir="ltr">export</span> command. As long as you don't log out, the
<span class="code" dir="ltr">PATH</span> variable will be using the temporary settings.
</p>
<a name="book_part2_chap5__chap3_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.2: Defining a session-specific environment variable</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">export PATH="${PATH}:/home/my_user/tmp/usr/bin"</span>
</pre></td></tr>
</table>
<a name="book_part3"></a><h2>C. Working with Portage</h2>
<a name="book_part3_chap1"></a><h3>1. Files and Directories</h3>
<p class="chaphead"><a name="book_part3_chap1__chap1"></a><span class="chapnum">1.a. </span>Portage Files</p>
<p class="secthead"><a name="book_part3_chap1__chap1_sect1">Configuration Directives</a></p>
<p>
Portage comes with a default configuration stored in
<span class="path" dir="ltr">/usr/share/portage/config/make.globals</span>. When you take a look at it, you'll notice that
all Portage configuration is handled through variables. What variables Portage
listens to and what they mean are described later.
</p>
<p>
Since many configuration directives differ between architectures, Portage also
has default configuration files which are part of your profile. Your profile is
pointed to by the <span class="path" dir="ltr">/etc/portage/make.profile</span> symlink; Portage'
configurations are set in the <span class="path" dir="ltr">make.defaults</span> files of your profile
and all parent profiles. We'll explain more about profiles
and the <span class="path" dir="ltr">/etc/portage/make.profile</span> directory later on.
</p>
<p>
If you're planning on changing a configuration variable, <span class="emphasis">don't</span> alter
<span class="path" dir="ltr">/usr/share/portage/config/make.globals</span> or <span class="path" dir="ltr">make.defaults</span>. Instead use
<span class="path" dir="ltr">/etc/portage/make.conf</span> which has precedence over the previous
files. You'll also find a <span class="path" dir="ltr">/usr/share/portage/config/make.conf.example</span>.
As the name implies, this is merely an example file - Portage does not read
in this file.
</p>
<p>
You can also define a Portage configuration variable as an environment variable,
but we don't recommend this.
</p>
<p class="secthead"><a name="book_part3_chap1__chap1_sect2">Profile-Specific Information</a></p>
<p>
We've already encountered the <span class="path" dir="ltr">/etc/portage/make.profile</span> directory.
Well, this isn't exactly a directory but a symbolic link to a profile, by
default one inside <span class="path" dir="ltr">/usr/portage/profiles</span> although you can create
your own profiles elsewhere and point to them. The profile this symlink points
to is the profile to which your system adheres.
</p>
<p>
A profile contains architecture-specific information for Portage, such as a
list of packages that belong to the system corresponding with that profile,
a list of packages that don't work (or are masked-out) for that profile, etc.
</p>
<p class="secthead"><a name="book_part3_chap1__chap1_sect3">User-Specific Configuration</a></p>
<p>
When you need to override Portage's behaviour regarding the installation of
software, you will end up editing files within <span class="path" dir="ltr">/etc/portage</span>. You
are <span class="emphasis">highly recommended</span> to use files within <span class="path" dir="ltr">/etc/portage</span> and
<span class="emphasis">highly discouraged</span> to override the behaviour through environment
variables!
</p>
<p>
Within <span class="path" dir="ltr">/etc/portage</span> you can create the following files:
</p>
<ul>
<li>
<span class="path" dir="ltr">package.mask</span> which lists the packages you never want Portage to
install
</li>
<li>
<span class="path" dir="ltr">package.unmask</span> which lists the packages you want to be able to
install even though the Gentoo developers highly discourage you from
emerging them
</li>
<li>
<span class="path" dir="ltr">package.accept_keywords</span> which lists the packages you want to be
able to install even though the package hasn't been found suitable for your
system or architecture (yet)
</li>
<li>
<span class="path" dir="ltr">package.use</span> which lists the USE flags you want to use for
certain packages without having the entire system use those USE flags
</li>
</ul>
<p>
These don't have to be files; they can also be directories that contain one file
per package. More information about the <span class="path" dir="ltr">/etc/portage</span> directory and
a full list of possible files you can create can be found in the Portage man
page:
</p>
<a name="book_part3_chap1__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: Reading the Portage man page</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
$ <span class="code-input">man portage</span>
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part3_chap1__chap1_sect4">Changing Portage File &amp; Directory Locations</a></p>
<p>
The previously mentioned configuration files cannot be stored elsewhere -
Portage will always look for those configuration files at those exact locations.
However, Portage uses many other locations for various purposes: build
directory, source code storage, Portage tree location, ...
</p>
<p>
All these purposes have well-known default locations but can be altered to your
own taste through <span class="path" dir="ltr">/etc/portage/make.conf</span>. The rest of this chapter
explains what special-purpose locations Portage uses and how to alter their
placement on your filesystem.
</p>
<p>
This document isn't meant to be used as a reference though. If you need 100%
coverage, please consult the Portage and <span class="path" dir="ltr">make.conf</span> man pages:
</p>
<a name="book_part3_chap1__chap1_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.2: Reading the Portage and make.conf man pages</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
$ <span class="code-input">man portage</span>
$ <span class="code-input">man make.conf</span>
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part3_chap1__chap2"></a><span class="chapnum">1.b. </span>Storing Files</p>
<p class="secthead"><a name="book_part3_chap1__chap2_sect1">The Portage Tree</a></p>
<p>
The Portage tree default location is <span class="path" dir="ltr">/usr/portage</span>. This is defined
by the PORTDIR variable. When you store the Portage tree elsewhere (by altering
this variable), don't forget to change the <span class="path" dir="ltr">/etc/portage/make.profile</span>
symbolic link accordingly.
</p>
<p>
If you alter the PORTDIR variable, you might want to alter the following
variables as well since they will not notice the PORTDIR change. This is due to
how Portage handles variables: PKGDIR, DISTDIR, RPMDIR.
</p>
<p class="secthead"><a name="book_part3_chap1__chap2_sect2">Prebuilt Binaries</a></p>
<p>
Even though Portage doesn't use prebuilt binaries by default, it has extensive
support for them. When you ask Portage to work with prebuilt packages, it will
look for them in <span class="path" dir="ltr">/usr/portage/packages</span>. This location is defined by
the PKGDIR variable.
</p>
<p class="secthead"><a name="book_part3_chap1__chap2_sect3">Source Code</a></p>
<p>
Application source code is stored in <span class="path" dir="ltr">/usr/portage/distfiles</span> by
default. This location is defined by the DISTDIR variable.
</p>
<p class="secthead"><a name="book_part3_chap1__chap2_sect4">Portage Database</a></p>
<p>
Portage stores the state of your system (what packages are installed, what files
belong to which package, ...) in <span class="path" dir="ltr">/var/db/pkg</span>. Do <span class="emphasis">not</span> alter
these files manually! It might break Portage's knowledge of your system.
</p>
<p class="secthead"><a name="book_part3_chap1__chap2_sect5">Portage Cache</a></p>
<p>
The Portage cache (with modification times, virtuals, dependency tree
information, ...) is stored in <span class="path" dir="ltr">/var/cache/edb</span>. This location really
is a cache: you can clean it if you are not running any portage-related
application at that moment.
</p>
<p class="chaphead"><a name="book_part3_chap1__chap3"></a><span class="chapnum">1.c. </span>Building Software</p>
<p class="secthead"><a name="book_part3_chap1__chap3_sect1">Temporary Portage Files</a></p>
<p>
Portage's temporary files are stored in <span class="path" dir="ltr">/var/tmp</span> by default. This
is defined by the PORTAGE_TMPDIR variable.
</p>
<p>
If you alter the PORTAGE_TMPDIR variable, you might want to alter the following
variables as well since they will not notice the PORTAGE_TMPDIR change. This
is due to how Portage handles variables: BUILD_PREFIX.
</p>
<p class="secthead"><a name="book_part3_chap1__chap3_sect2">Building Directory</a></p>
<p>
Portage creates specific build directories for each package it emerges inside
<span class="path" dir="ltr">/var/tmp/portage</span>. This location is defined by the BUILD_PREFIX
variable.
</p>
<p class="secthead"><a name="book_part3_chap1__chap3_sect3">Live Filesystem Location</a></p>
<p>
By default Portage installs all files on the current filesystem
(<span class="path" dir="ltr">/</span>), but you can change this by setting the ROOT environment
variable. This is useful when you want to create new build images.
</p>
<p class="chaphead"><a name="book_part3_chap1__chap4"></a><span class="chapnum">1.d. </span>Logging Features</p>
<p class="secthead"><a name="book_part3_chap1__chap4_sect1">Ebuild Logging</a></p>
<p>
Portage can create per-ebuild logfiles, but only when the PORT_LOGDIR variable
is set to a location that is writable by Portage (the portage user). By default
this variable is unset. If you don't set PORT_LOGDIR, then you won't receive
any build logs with the current logging system, though you may receive some
logs from the new <span class="code" dir="ltr">elog</span>. If you do have PORT_LOGDIR defined and you use
elog, you will receive build logs and any logs saved by elog, as explained
below.
</p>
<p>
Portage offers fine-grained control over logging through the use of
<span class="code" dir="ltr">elog</span>:
</p>
<ul>
<li>
PORTAGE_ELOG_CLASSES: This is where you set what kinds of messages to be
logged. You can use any space-separated combination of <span class="code" dir="ltr">info</span>,
<span class="code" dir="ltr">warn</span>, <span class="code" dir="ltr">error</span>, <span class="code" dir="ltr">log</span>, and <span class="code" dir="ltr">qa</span>.
<ul>
<li>
<span class="code" dir="ltr">info</span>: Logs "einfo" messages printed by an ebuild</li>
<li>
<span class="code" dir="ltr">warn</span>: Logs "ewarn" messages printed by an ebuild</li>
<li>
<span class="code" dir="ltr">error</span>: Logs "eerror" messages printed by an ebuild</li>
<li>
<span class="code" dir="ltr">log</span>: Logs the "elog" messages found in some ebuilds</li>
<li>
<span class="code" dir="ltr">qa</span>: Logs the "QA Notice" messages printed by an ebuild</li>
</ul>
</li>
<li>
PORTAGE_ELOG_SYSTEM: This selects the module(s) to process the log messages.
If left empty, logging is disabled. You can use any space-separated
combination of <span class="code" dir="ltr">save</span>, <span class="code" dir="ltr">custom</span>, <span class="code" dir="ltr">syslog</span>, <span class="code" dir="ltr">mail</span>,
<span class="code" dir="ltr">save_summary</span>, and <span class="code" dir="ltr">mail_summary</span>. You must select at least one
module in order to use elog.
<ul>
<li>
<span class="code" dir="ltr">save</span>: This saves one log per package in
<span class="path" dir="ltr">$PORT_LOGDIR/elog</span>, or <span class="path" dir="ltr">/var/log/portage/elog</span> if
$PORT_LOGDIR is not defined.
</li>
<li>
<span class="code" dir="ltr">custom</span>: Passes all messages to a user-defined command in
$PORTAGE_ELOG_COMMAND; this will be discussed later.
</li>
<li>
<span class="code" dir="ltr">syslog</span>: Sends all messages to the installed system logger.
</li>
<li>
<span class="code" dir="ltr">mail</span>: Passes all messages to a user-defined mailserver in
$PORTAGE_ELOG_MAILURI; this will be discussed later. The mail features
of elog require &gt;=<span class="code" dir="ltr">portage-2.1.1</span>.
</li>
<li>
<span class="code" dir="ltr">save_summary</span>: Similar to <span class="code" dir="ltr">save</span>, but it merges all messages
in <span class="path" dir="ltr">$PORT_LOGDIR/elog/summary.log</span>, or
<span class="path" dir="ltr">/var/log/portage/elog/summary.log</span> if $PORT_LOGDIR is not
defined.
</li>
<li>
<span class="code" dir="ltr">mail_summary</span>: Similar to <span class="code" dir="ltr">mail</span>, but it sends all messages
in a single mail when emerge exits.
</li>
</ul>
</li>
<li>
PORTAGE_ELOG_COMMAND: This is only used when the <span class="code" dir="ltr">custom</span> module is
enabled. Here is where you specify a command to process log messages. Note
that you can make use of two variables: ${PACKAGE} is the package name and
version, while ${LOGFILE} is the absolute path to the logfile. Here's one
possible usage:
<ul>
<li>
PORTAGE_ELOG_COMMAND="/path/to/logger -p '\${PACKAGE}' -f '\${LOGFILE}'"
</li>
</ul>
</li>
<li>
PORTAGE_ELOG_MAILURI: This contains settings for the <span class="code" dir="ltr">mail</span> module
such as address, user, password, mailserver, and port number. The default
setting is "root@localhost localhost".
</li>
<li>
Here's an example for an smtp server that requires username and
password-based authentication on a particular port (the default is port
25):
<ul>
<li>
PORTAGE_ELOG_MAILURI="user@some.domain
username:password@smtp.some.domain:995"
</li>
</ul>
</li>
<li>
PORTAGE_ELOG_MAILFROM: Allows you to set the "from" address of log mails;
defaults to "portage" if unset.
</li>
<li>
PORTAGE_ELOG_MAILSUBJECT: Allows you to create a subject line for log
mails. Note that you can make use of two variables: ${PACKAGE} will display
the package name and version, while ${HOST} is the fully qualified domain
name of the host Portage is running on.
</li>
<li>
Here's one possible use:
<ul>
<li>
PORTAGE_ELOG_MAILSUBJECT="package \${PACKAGE} was merged on \${HOST}
with some messages"
</li>
</ul>
</li>
</ul>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffffbb"><p class="note"><b>Important: </b>
If you used <span class="code" dir="ltr">enotice</span> with Portage-2.0.*, you must completely remove
enotice, as it is incompatible with elog.
</p></td></tr></table>
<a name="book_part3_chap2"></a><h3>2. Configuring through Variables</h3>
<p class="chaphead"><a name="book_part3_chap2__chap1"></a><span class="chapnum">2.a. </span>Portage Configuration</p>
<p>
As noted previously, Portage is configurable through many variables which
you should define in <span class="path" dir="ltr">/etc/portage/make.conf</span> or one of the subdirectories
of <span class="path" dir="ltr">/etc/portage</span>. Please refer to the <span class="path" dir="ltr">make.conf</span> and
<span class="path" dir="ltr">portage</span> man pages for more and complete information:
</p>
<a name="book_part3_chap2__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: Reading the man pages</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
$ <span class="code-input">man make.conf</span>
$ <span class="code-input">man portage</span>
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part3_chap2__chap2"></a><span class="chapnum">2.b. </span>Build-specific Options</p>
<p class="secthead"><a name="book_part3_chap2__chap2_sect1">Configure and Compiler Options</a></p>
<p>
When Portage builds applications, it passes the contents of the following
variables to the compiler and configure script:
</p>
<ul>
<li>
CFLAGS &amp; CXXFLAGS define the desired compiler flags for C and C++
compiling.
</li>
<li>
CHOST defines the build host information for the application's configure
script
</li>
<li>
MAKEOPTS is passed to the <span class="code" dir="ltr">make</span> command and is usually set to define
the amount of parallelism used during the compilation. More information
about the make options can be found in the <span class="code" dir="ltr">make</span> man page.
</li>
</ul>
<p>
The USE variable is also used during configure and compilations but has been
explained in great detail in previous chapters.
</p>
<p class="secthead"><a name="book_part3_chap2__chap2_sect2">Merge Options</a></p>
<p>
When Portage has merged a newer version of a certain software title, it will
remove the obsoleted files of the older version from your system. Portage gives
the user a 5 second delay before unmerging the older version. These 5 seconds
are defined by the CLEAN_DELAY variable.
</p>
<p>
You can tell <span class="code" dir="ltr">emerge</span> to use certain options every time it is run by
setting EMERGE_DEFAULT_OPTS. Some useful options would be --ask, --verbose,
--tree, and so on.
</p>
<p class="chaphead"><a name="book_part3_chap2__chap3"></a><span class="chapnum">2.c. </span>Configuration File Protection</p>
<p class="secthead"><a name="book_part3_chap2__chap3_sect1">Portage's Protected Locations</a></p>
<p>
Portage overwrites files provided by newer versions of a software title if the
files aren't stored in a <span class="emphasis">protected</span> location. These protected locations
are defined by the CONFIG_PROTECT variable and are generally configuration file
locations. The directory listing is space-delimited.
</p>
<p>
A file that would be written in such a protected location is renamed and the
user is warned about the presence of a newer version of the (presumable)
configuration file.
</p>
<p>
You can find out about the current CONFIG_PROTECT setting from the <span class="code" dir="ltr">emerge
--info</span> output:
</p>
<a name="book_part3_chap2__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: Getting the CONFIG_PROTECT setting</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
$ <span class="code-input">emerge --info | grep 'CONFIG_PROTECT='</span>
</pre></td></tr>
</table>
<p>
More information about Portage's Configuration File Protection is available
in the CONFIGURATION FILES section of the <span class="code" dir="ltr">emerge</span> manpage:
</p>
<a name="book_part3_chap2__chap3_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.2: More information about Configuration File Protection</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
$ <span class="code-input">man emerge</span>
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part3_chap2__chap3_sect2">Excluding Directories</a></p>
<p>
To 'unprotect' certain subdirectories of protected locations you can use the
CONFIG_PROTECT_MASK variable.
</p>
<p class="chaphead"><a name="book_part3_chap2__chap4"></a><span class="chapnum">2.d. </span>Download Options</p>
<p class="secthead"><a name="book_part3_chap2__chap4_sect1">Server Locations</a></p>
<p>
When the requested information or data is not available on your system, Portage
will retrieve it from the Internet. The server locations for the various
information and data channels are defined by the following variables:
</p>
<ul>
<li>
GENTOO_MIRRORS defines a list of server locations which
contain source code (distfiles)
</li>
<li>
PORTAGE_BINHOST defines a particular server location containing prebuilt
packages for your system
</li>
</ul>
<p>
A third setting involves the location of the rsync server which you use when you
update your Portage tree. This is defined in the <span class="path" dir="ltr">/etc/portage/repos.conf</span>
file (or a file inside that directory if it is defined as a directory):
</p>
<ul>
<li>
sync-type defines the type of server and defaults to "rsync"
</li>
<li>
sync-uri defines a particular server which Portage uses to fetch the
Portage tree from
</li>
</ul>
<p>
The GENTOO_MIRRORS, sync-type and sync-uri variables can be set automatically through the
<span class="code" dir="ltr">mirrorselect</span> application. You need to <span class="code" dir="ltr">emerge mirrorselect</span> first
before you can use it. For more information, see mirrorselect's online
help:
</p>
<a name="book_part3_chap2__chap4_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.1: More information about mirrorselect</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">mirrorselect --help</span>
</pre></td></tr>
</table>
<p>
If your environment requires you to use a proxy server, you can use the
http_proxy, ftp_proxy and RSYNC_PROXY variables to declare a proxy server.
</p>
<p class="secthead"><a name="book_part3_chap2__chap4_sect2">Fetch Commands</a></p>
<p>
When Portage needs to fetch source code, it uses <span class="code" dir="ltr">wget</span> by default. You
can change this through the FETCHCOMMAND variable.
</p>
<p>
Portage is able to resume partially downloaded source code. It uses <span class="code" dir="ltr">wget</span>
by default, but this can be altered through the RESUMECOMMAND variable.
</p>
<p>
Make sure that your FETCHCOMMAND and RESUMECOMMAND stores the source code in the
correct location. Inside the variables you should use \${URI} and \${DISTDIR} to
point to the source code location and distfiles location respectively.
</p>
<p>
You can also define protocol-specific handlers with FETCHCOMMAND_HTTP,
FETCHCOMMAND_FTP, RESUMECOMMAND_HTTP, RESUMECOMMAND_FTP, and so on.
</p>
<p class="secthead"><a name="book_part3_chap2__chap4_sect3">Rsync Settings</a></p>
<p>
You cannot alter the rsync command used by Portage to update the Portage tree,
but you can set some variables related to the rsync command:
</p>
<ul>
<li>
PORTAGE_RSYNC_OPTS sets a number of default variables used during sync,
each space-separated. These shouldn't be changed unless you know
<span class="emphasis">exactly</span> what you're doing. Note that certain absolutely required
options will always be used even if PORTAGE_RSYNC_OPTS is empty.
</li>
<li>
PORTAGE_RSYNC_EXTRA_OPTS can be used to set additional options when
syncing. Each option should be space separated.
<ul>
<li>
--timeout=&lt;number&gt;: This defines the number of seconds an rsync
connection can idle before rsync sees the connection as timed-out. This
variable defaults to 180 but dialup users or individuals with slow
computers might want to set this to 300 or higher.
</li>
<li>
--exclude-from=/etc/portage/rsync_excludes: This points to a file
listing the packages and/or categories rsync should ignore during the
update process. In this case, it points to
<span class="path" dir="ltr">/etc/portage/rsync_excludes</span>. Please read <a href="#book_part3_chap5">Using a Portage Tree Subset</a> for the
syntax of this file.
</li>
<li>--quiet: Reduces output to the screen</li>
<li>--verbose: Prints a complete filelist</li>
<li>--progress: Displays a progress meter for each file</li>
</ul>
</li>
<li>
PORTAGE_RSYNC_RETRIES defines how many times rsync should try connecting to
the mirror pointed to by the SYNC variable before bailing out. This
variable defaults to 3.
</li>
</ul>
<p>
For more information on these options and others, please read <span class="code" dir="ltr">man
rsync</span>.
</p>
<p class="chaphead"><a name="book_part3_chap2__chap5"></a><span class="chapnum">2.e. </span>Gentoo Configuration</p>
<p class="secthead"><a name="book_part3_chap2__chap5_sect1">Branch Selection</a></p>
<p>
You can change your default branch with the ACCEPT_KEYWORDS variable. It
defaults to your architecture's stable branch. More information on Gentoo's
branches can be found in the next chapter.
</p>
<p class="secthead"><a name="book_part3_chap2__chap5_sect2">Portage Features</a></p>
<p>
You can activate certain Portage features through the FEATURES variable. The
Portage Features have been discussed in previous chapters, such as <a href="#book_part2_chap3">Portage Features</a>.
</p>
<p class="chaphead"><a name="book_part3_chap2__chap6"></a><span class="chapnum">2.f. </span>Portage Behaviour</p>
<p class="secthead"><a name="book_part3_chap2__chap6_sect1">Resource Management</a></p>
<p>
With the PORTAGE_NICENESS variable you can augment or reduce the nice value
Portage runs with. The PORTAGE_NICENESS value is <span class="emphasis">added</span> to the current
nice value.
</p>
<p>
For more information about nice values, see the nice man page:
</p>
<a name="book_part3_chap2__chap6_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 6.1: More information about nice</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
$ <span class="code-input">man nice</span>
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part3_chap2__chap6_sect2">Output Behaviour</a></p>
<p>
The NOCOLOR, which defaults to "false", defines if Portage should disable the
use of coloured output.
</p>
<a name="book_part3_chap3"></a><h3>3. Mixing Software Branches</h3>
<p class="chaphead"><a name="book_part3_chap3__chap1"></a><span class="chapnum">3.a. </span>Using One Branch</p>
<p class="secthead"><a name="book_part3_chap3__chap1_sect1">The Stable Branch</a></p>
<p>
The ACCEPT_KEYWORDS variable defines what software branch you use on your
system. It defaults to the stable software branch for your architecture, for
instance <span class="code" dir="ltr">x86</span>.
</p>
<p>
We recommend that you only use the stable branch. However, if you don't care
about stability this much and you want to help out Gentoo by submitting
bugreports to <a href="https://bugs.gentoo.org">https://bugs.gentoo.org</a>, read on.
</p>
<p class="secthead"><a name="book_part3_chap3__chap1_sect2">The Testing Branch</a></p>
<p>
If you want to use more recent software, you can consider using the testing
branch instead. To have Portage use the testing branch, add a ~ in front of your
architecture.
</p>
<p>
The testing branch is exactly what it says - <span class="emphasis">Testing</span>. If a package is in
testing, it means that the developers feel that it is functional but has not
been thoroughly tested. You could very well be the first to discover a bug in
the package in which case you could file a <a href="https://bugs.gentoo.org">bugreport</a> to let the developers know about
it.
</p>
<p>
Beware though, you might notice stability issues, imperfect package handling
(for instance wrong/missing dependencies), too frequent updates (resulting in
lots of building) or broken packages. If you do not know how Gentoo works and
how to solve problems, we recommend that you stick with the stable and tested
branch.
</p>
<p>
For example, to select the testing branch for the x86 architecture, edit
<span class="path" dir="ltr">/etc/portage/make.conf</span> and set:
</p>
<a name="book_part3_chap3__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: Setting the ACCEPT_KEYWORDS variable</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
ACCEPT_KEYWORDS="~x86"
</pre></td></tr>
</table>
<p>
If you update your system now, you will find out that <span class="emphasis">lots</span> of packages
will be updated. Mind you though: when you have updated your system to use the
testing branch there is usually no easy way back to the stable, official branch
(except for using backups of course).
</p>
<p class="chaphead"><a name="book_part3_chap3__chap2"></a><span class="chapnum">3.b. </span>Mixing Stable with Testing</p>
<p class="secthead"><a name="book_part3_chap3__chap2_sect1">The package.accept_keywords location</a></p>
<p>
You can ask Portage to allow the testing branch for particular packages but use
the stable branch for the rest of the system. To achieve this, add the package
category and name you want to use the testing branch of in
<span class="path" dir="ltr">/etc/portage/package.accept_keywords</span>. You can also create a
directory (with the same name) and list the package in the files under that
directory. For instance, to use the testing branch for <span class="code" dir="ltr">gnumeric</span>:
</p>
<a name="book_part3_chap3__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: /etc/portage/package.accept_keywords setting for gnumeric</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
app-office/gnumeric
</pre></td></tr>
</table>
<p class="secthead"><a name="versions"></a><a name="book_part3_chap3__chap2_sect2">Test Particular Versions</a></p>
<p>
If you want to use a specific software version from the testing branch but you
don't want Portage to use the testing branch for subsequent versions, you can
add in the version in the <span class="path" dir="ltr">package.accept_keywords</span> location. In this
case you <span class="emphasis">must</span> use the = operator. You can also enter a version range
using the &lt;=, &lt;, &gt; or &gt;= operators.
</p>
<p>
In any case, if you add version information, you <span class="emphasis">must</span> use an operator. If
you leave out version information, you <span class="emphasis">cannot</span> use an operator.
</p>
<p>
In the following example we ask Portage to accept gnumeric-1.2.13:
</p>
<a name="book_part3_chap3__chap2_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.2: Enabling a particular gnumeric test version</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
=app-office/gnumeric-1.2.13
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part3_chap3__chap3"></a><span class="chapnum">3.c. </span>Using Masked Packages</p>
<p class="secthead"><a name="book_part3_chap3__chap3_sect1">The package.unmask location</a></p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffffbb"><p class="note"><b>Important: </b>
The Gentoo developers do <b>not</b> support the use of this location. Please
exercise due caution when doing so. Support requests related to
<span class="code" dir="ltr">package.unmask</span> and/or <span class="code" dir="ltr">package.mask</span> will not be answered. You have
been warned.
</p></td></tr></table>
<p>
When a package has been masked by the Gentoo developers and you still want to
use it despite the reason mentioned in the <span class="path" dir="ltr">package.mask</span> file
(situated in <span class="path" dir="ltr">/usr/portage/profiles</span> by default), add the
desired version (usually this will be the exact same line from
<span class="path" dir="ltr">profiles</span>) in the <span class="path" dir="ltr">/etc/portage/package.unmask</span> file
(or in a file in that directory if it is a directory).
</p>
<p>
For instance, if <span class="code" dir="ltr">=net-mail/hotwayd-0.8</span> is masked, you can unmask it by
adding the exact same line in the <span class="path" dir="ltr">package.unmask</span> location:
</p>
<a name="book_part3_chap3__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: /etc/portage/package.unmask</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
=net-mail/hotwayd-0.8
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
If an entry in <span class="path" dir="ltr">/usr/portage/profiles/package.mask</span> contains a range
of package versions, you will need to unmask only the version(s) you actually
want. Please read the <a href="#versions">previous section</a> to learn how
to specify versions in <span class="path" dir="ltr">package.unmask</span>.
</p></td></tr></table>
<p class="secthead"><a name="book_part3_chap3__chap3_sect2">The package.mask location</a></p>
<p>
When you don't want Portage to take a certain package or a specific version of a
package into account you can mask it yourself by adding an appropriate line to
the <span class="path" dir="ltr">/etc/portage/package.mask</span> location (either in that file or
in a file in this directory).
</p>
<p>
For instance, if you don't want Portage to install newer kernel sources than
<span class="code" dir="ltr">gentoo-sources-2.6.8.1</span>, you add the following line at the
<span class="path" dir="ltr">package.mask</span> location:
</p>
<a name="book_part3_chap3__chap3_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.2: /etc/portage/package.mask example</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
&gt;sys-kernel/gentoo-sources-2.6.8.1
</pre></td></tr>
</table>
<a name="book_part3_chap4"></a><h3>4. Additional Portage Tools</h3>
<p class="chaphead"><a name="book_part3_chap4__chap1"></a><span class="chapnum">4.a. </span>dispatch-conf</p>
<p>
<span class="code" dir="ltr">dispatch-conf</span> is a tool that aids in merging the
<span class="path" dir="ltr">._cfg0000_&lt;name&gt;</span> files. <span class="path" dir="ltr">._cfg0000_&lt;name&gt;</span>
files are generated by Portage when it wants to overwrite a file in a directory
protected by the CONFIG_PROTECT variable.
</p>
<p>
With <span class="code" dir="ltr">dispatch-conf</span>, you are able to merge updates to your configuration
files while keeping track of all changes. <span class="code" dir="ltr">dispatch-conf</span> stores the
differences between the configuration files as patches or by using the RCS
revision system. This means that if you make a mistake when updating a config
file, you can revert to the previous version of your config file at any time.
</p>
<p>
When using <span class="code" dir="ltr">dispatch-conf</span>, you can ask to keep the configuration file
as-is, use the new configuration file, edit the current one or merge the changes
interactively. <span class="code" dir="ltr">dispatch-conf</span> also has some nice additional features:
</p>
<ul>
<li>
Automatically merge configuration file updates that only contain updates to
comments
</li>
<li>
Automatically merge configuration files which only differ in the amount of
whitespace
</li>
</ul>
<p>
Make certain you edit <span class="path" dir="ltr">/etc/dispatch-conf.conf</span> first and create the
directory referenced by the archive-dir variable.
</p>
<a name="book_part3_chap4__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: Running dispatch-conf</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">dispatch-conf</span>
</pre></td></tr>
</table>
<p>
When running <span class="code" dir="ltr">dispatch-conf</span>, you'll be taken through each changed config
file, one at a time. Press <span class="code" dir="ltr">u</span> to update (replace) the current config file
with the new one and continue to the next file. Press <span class="code" dir="ltr">z</span> to zap (delete)
the new config file and continue to the next file. Once all config files have
been taken care of, <span class="code" dir="ltr">dispatch-conf</span> will exit. You can also press <span class="code" dir="ltr">q</span>
to exit any time.
</p>
<p>
For more information, check out the <span class="code" dir="ltr">dispatch-conf</span> man page. It tells you
how to interactively merge current and new config files, edit new config files,
examine differences between files, and more.
</p>
<a name="book_part3_chap4__chap1_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.2: Reading the dispatch-conf man page</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
$ <span class="code-input">man dispatch-conf</span>
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part3_chap4__chap2"></a><span class="chapnum">4.b. </span>etc-update</p>
<p>
You can also use <span class="code" dir="ltr">etc-update</span> to merge config files. It's not as simple to
use as <span class="code" dir="ltr">dispatch-conf</span>, nor as featureful, but it does provide an
interactive merging setup and can also auto-merge trivial changes.
</p>
<p>
However, unlike <span class="code" dir="ltr">dispatch-conf</span>, <span class="code" dir="ltr">etc-update</span> does <span class="emphasis">not</span> preserve
the old versions of your config files. Once you update the file, the old version
is gone forever! So be very careful, as using <span class="code" dir="ltr">etc-update</span> is
<span class="emphasis">significantly</span> less safe than using <span class="code" dir="ltr">dispatch-conf</span>.
</p>
<a name="book_part3_chap4__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: Running etc-update</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">etc-update</span>
</pre></td></tr>
</table>
<p>
After merging the straightforward changes, you will be prompted with a list of
protected files that have an update waiting. At the bottom you are greeted by
the possible options:
</p>
<a name="book_part3_chap4__chap2_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.2: etc-update options</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
Please select a file to edit by entering the corresponding number.
(-1 to exit) (-3 to auto merge all remaining files)
(-5 to auto-merge AND not use 'mv -i'):
</pre></td></tr>
</table>
<p>
If you enter <span class="code" dir="ltr">-1</span>, <span class="code" dir="ltr">etc-update</span> will exit and discontinue any further
changes. If you enter <span class="code" dir="ltr">-3</span> or <span class="code" dir="ltr">-5</span>, <span class="emphasis">all</span> listed configuration
files will be overwritten with the newer versions. It is therefore very
important to first select the configuration files that should not be
automatically updated. This is simply a matter of entering the number listed to
the left of that configuration file.
</p>
<p>
As an example, we select the configuration file <span class="path" dir="ltr">/etc/pear.conf</span>:
</p>
<a name="book_part3_chap4__chap2_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.3: Updating a specific configuration file</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
Beginning of differences between /etc/pear.conf and /etc/._cfg0000_pear.conf
<span class="code-comment">[...]</span>
End of differences between /etc/pear.conf and /etc/._cfg0000_pear.conf
1) Replace original with update
2) Delete update, keeping original as is
3) Interactively merge original with update
4) Show differences again
</pre></td></tr>
</table>
<p>
You can now see the differences between the two files. If you believe that the
updated configuration file can be used without problems, enter <span class="code" dir="ltr">1</span>. If you
believe that the updated configuration file isn't necessary, or doesn't provide
any new or useful information, enter <span class="code" dir="ltr">2</span>. If you want to interactively
update your current configuration file, enter <span class="code" dir="ltr">3</span>.
</p>
<p>
There is no point in further elaborating the interactive merging here. For
completeness sake, we will list the possible commands you can use while you are
interactively merging the two files. You are greeted with two lines (the
original one, and the proposed new one) and a prompt at which you can enter one
of the following commands:
</p>
<a name="book_part3_chap4__chap2_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.4: Commands available for the interactive merging</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
ed: Edit then use both versions, each decorated with a header.
eb: Edit then use both versions.
el: Edit then use the left version.
er: Edit then use the right version.
e: Edit a new version.
l: Use the left version.
r: Use the right version.
s: Silently include common lines.
v: Verbosely include common lines.
q: Quit.
</pre></td></tr>
</table>
<p>
When you have finished updating the important configuration files, you can now
automatically update all the other configuration files. <span class="code" dir="ltr">etc-update</span> will
exit if it doesn't find any more updateable configuration files.
</p>
<p class="chaphead"><a name="book_part3_chap4__chap3"></a><span class="chapnum">4.c. </span>quickpkg</p>
<p>
With <span class="code" dir="ltr">quickpkg</span> you can create archives of the packages that are already
merged on your system. These archives can be used as prebuilt packages. Running
<span class="code" dir="ltr">quickpkg</span> is straightforward: just add the names of the packages you want
to archive.
</p>
<p>
For instance, to archive <span class="code" dir="ltr">curl</span>, <span class="code" dir="ltr">orage</span>, and <span class="code" dir="ltr">procps</span>:
</p>
<a name="book_part3_chap4__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: Example quickpkg usage</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">quickpkg curl orage procps</span>
</pre></td></tr>
</table>
<p>
The prebuilt packages will be stored in <span class="path" dir="ltr">$PKGDIR</span>
(<span class="path" dir="ltr">/usr/portage/packages/</span> by default). These packages are placed in
<span class="path" dir="ltr">$PKGDIR/&lt;category&gt;</span>.
</p>
<a name="book_part3_chap5"></a><h3>5. Diverting from the Official Tree</h3>
<p class="chaphead"><a name="book_part3_chap5__chap1"></a><span class="chapnum">5.a. </span>Using a Portage Tree Subset</p>
<p class="secthead"><a name="book_part3_chap5__chap1_sect1">Excluding Packages/Categories</a></p>
<p>
You can selectively update certain categories/packages and ignore the other
categories/packages. We achieve this by having <span class="code" dir="ltr">rsync</span> exclude
categories/packages during the <span class="code" dir="ltr">emerge --sync</span> step.
</p>
<p>
You need to define the name of the file that contains the exclude patterns in
the <span class="code" dir="ltr">PORTAGE_RSYNC_EXTRA_OPTS</span> variable in your <span class="path" dir="ltr">/etc/portage/make.conf</span>.
</p>
<a name="book_part3_chap5__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: Defining the exclude file in /etc/portage/make.conf</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
PORTAGE_RSYNC_EXTRA_OPTS="--exclude-from=/etc/portage/rsync_excludes"
</pre></td></tr>
</table>
<a name="book_part3_chap5__chap1_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.2: Excluding all games in /etc/portage/rsync_excludes</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
games-*/*
</pre></td></tr>
</table>
<p>
Note however that this may lead to dependency issues since new, allowed packages
might depend on new but excluded packages.
</p>
<p class="chaphead"><a name="book_part3_chap5__chap2"></a><span class="chapnum">5.b. </span>Adding Unofficial Ebuilds</p>
<p class="secthead"><a name="book_part3_chap5__chap2_sect1">Defining a Portage Overlay Directory</a></p>
<p>
You can ask Portage to use ebuilds that are not officially available through the
Portage tree. Create a new directory (for instance
<span class="path" dir="ltr">/usr/local/portage</span>) in which you store the 3rd-party ebuilds. Use
the same directory structure as the official Portage tree!
</p>
<p>
Then define PORTDIR_OVERLAY in <span class="path" dir="ltr">/etc/portage/make.conf</span> and have it
point to the previously defined directory. When you use Portage now, it will
take those ebuilds into account as well without removing/overwriting those
ebuilds the next time you run <span class="code" dir="ltr">emerge --sync</span>.
</p>
<p class="secthead"><a name="book_part3_chap5__chap2_sect2">Working with Several Overlays</a></p>
<p>
For the powerusers who develop on several overlays, test packages before they
hit the Portage tree or just want to use unofficial ebuilds from various
sources, the <span class="code" dir="ltr">app-portage/layman</span> package brings you
<span class="code" dir="ltr">layman</span>, a tool to help you keep the overlay repositories up to date.
</p>
<p>
First install and configure <span class="code" dir="ltr">layman</span> as shown in the <a href="/proj/en/overlays/userguide.xml?style=printable">Overlays Users' Guide</a>, and add your
desired repositories with <span class="code" dir="ltr">layman -a &lt;overlay-name&gt;</span>.
</p>
<p>
Suppose you have two repositories called <span class="code" dir="ltr">java</span> (for the in-development
java ebuilds) and <span class="code" dir="ltr">entapps</span> (for the applications developed in-house for
your enterprise). You can update those repositories with the following
command:
</p>
<a name="book_part3_chap5__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: Using layman to update all repositories</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">layman -S</span>
</pre></td></tr>
</table>
<p>
For more information on working with overlays, please read <span class="code" dir="ltr">man layman</span> and
the <a href="/proj/en/overlays/userguide.xml?style=printable">layman/overlay users'
guide</a>.
</p>
<p class="chaphead"><a name="book_part3_chap5__chap3"></a><span class="chapnum">5.c. </span>Non-Portage Maintained Software</p>
<p class="secthead"><a name="book_part3_chap5__chap3_sect1">Using Portage with Self-Maintained Software</a></p>
<p>
In some cases you want to configure, install and maintain software yourself
without having Portage automate the process for you, even though Portage
can provide the software titles. Known cases are kernel sources and nvidia
drivers. You can configure Portage so it knows that a certain package is
manually installed on your system. This process is called <span class="emphasis">injecting</span> and
supported by Portage through the
<span class="path" dir="ltr">/etc/portage/profile/package.provided</span> file.
</p>
<p>
For instance, if you want to inform Portage about
<span class="code" dir="ltr">gentoo-sources-2.6.11.6</span> which you've installed manually, add the
following line to <span class="path" dir="ltr">/etc/portage/profile/package.provided</span>:
</p>
<a name="book_part3_chap5__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: Example line for package.provided</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
sys-kernel/gentoo-sources-2.6.11.6
</pre></td></tr>
</table>
<a name="book_part3_chap6"></a><h3>6. Advanced Portage Features</h3>
<p class="chaphead"><a name="book_part3_chap6__chap1"></a><span class="chapnum">6.a. </span>Introduction</p>
<p>
For most users, the information received thus far is sufficient for all their
Linux operations. But Portage is capable of much more; many of its features are
for advanced users or only applicable in specific corner cases. Still, that
would not be an excuse not to document them.
</p>
<p>
Of course, with lots of flexibility comes a huge list of potential cases. It
will not be possible to document them all here. Instead, we hope to focus on
some generic issues which you can then bend to fit your own needs. If you have
need for more specific tweaks and tips, you might find them on the <a href="https://wiki.gentoo.org">Gentoo Wiki</a> instead.
</p>
<p>
Most, if not all of these additional features can be easily found by digging
through the manual pages that portage provides:
</p>
<a name="book_part3_chap6__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: Reading up on portage man pages</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
$ <span class="code-input">man portage</span>
$ <span class="code-input">man make.conf</span>
</pre></td></tr>
</table>
<p>
Finally, know that these are advanced features which, if not worked with
correctly, can make debugging and troubleshooting very difficult. Make sure you
mention these if you think you hit a bug and want to open a bugreport.
</p>
<p class="chaphead"><a name="book_part3_chap6__chap2"></a><span class="chapnum">6.b. </span>Per-Package Environment Variables</p>
<p class="secthead"><a name="book_part3_chap6__chap2_sect1">Using /etc/portage/env</a></p>
<p>
By default, package builds will use the environment variables defined in
<span class="path" dir="ltr">/etc/portage/make.conf</span>, such as <span class="code" dir="ltr">CFLAGS</span>, <span class="code" dir="ltr">MAKEOPTS</span>
and more. In some cases though, you might want to provide different variables
for specific packages. To do so, Portage supports the use of
<span class="path" dir="ltr">/etc/portage/env</span> and <span class="path" dir="ltr">/etc/portage/package.env</span>.
</p>
<p>
The <span class="path" dir="ltr">/etc/portage/package.env</span> file contains the list of packages for
which you want deviating variables as well as a specific identifier that tells
Portage which changes you want. The identifier name you pick yourself, Portage
will look for the variables in the <span class="path" dir="ltr">/etc/portage/env/&lt;identifier&gt;</span>
file.
</p>
<p class="secthead"><a name="book_part3_chap6__chap2_sect2">Example: Using debugging for specific packages</a></p>
<p>
As an example, we enable debugging for the <span class="path" dir="ltr">media-video/mplayer</span>
package.
</p>
<p>
First of all, we set the debugging variables in a file called
<span class="path" dir="ltr">/etc/portage/env/debug-cflags</span>. The name is arbitrarily chosen, but
of course reflects the reason of the deviation to make it more obvious later why
a deviation was put in.
</p>
<a name="book_part3_chap6__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: /etc/portage/env/debug-cflags content</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
CFLAGS="-O2 -ggdb -pipe"
FEATURES="${FEATURES} nostrip"
</pre></td></tr>
</table>
<p>
Next, we tag the <span class="path" dir="ltr">media-video/mplayer</span> package to use this content:
</p>
<a name="book_part3_chap6__chap2_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.2: /etc/portage/package.env content</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
media-video/mplayer debug-cflags
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part3_chap6__chap3"></a><span class="chapnum">6.c. </span>Hooking In the Emerge Process</p>
<p class="secthead"><a name="book_part3_chap6__chap3_sect1">Using /etc/portage/bashrc and affiliated files</a></p>
<p>
When Portage works with ebuilds, it uses a bash environment in which it calls
the various build functions (like src_prepare, src_configure, pkg_postinst,
etc.). But Portage also allows you to set up a bash environment yourself.
</p>
<p>
The advantage of using your own bash environment is that you can hook in the
emerge process during each step it performs. This can be done for every emerge
(through <span class="path" dir="ltr">/etc/portage/bashrc</span>) or by using per-package environments
(through <span class="path" dir="ltr">/etc/portage/env</span> as discussed earlier).
</p>
<p>
To hook in the process, the bash environment can listen to the variables
<span class="code" dir="ltr">EBUILD_PHASE</span>, <span class="code" dir="ltr">CATEGORY</span> as well as the variables that are always
available during ebuild development (such as <span class="code" dir="ltr">P</span>, <span class="code" dir="ltr">PF</span>, ...). Based on
the values of these variables, you can then execute additional steps.
</p>
<p class="secthead"><a name="book_part3_chap6__chap3_sect2">Example: Updating File Databases</a></p>
<p>
In this example, we'll use <span class="path" dir="ltr">/etc/portage/bashrc</span> to call some file
database applications to ensure their databases are up to date with the system.
The applications used in the example are <span class="code" dir="ltr">aide</span> (an intrusion detection
tool) and <span class="code" dir="ltr">updatedb</span> (to use with <span class="code" dir="ltr">locate</span>), but these are meant as
examples. Do not consider this as a HOWTO for AIDE ;-)
</p>
<p>
To use <span class="path" dir="ltr">/etc/portage/bashrc</span> for this case, we need to "hook" in the
<span class="code" dir="ltr">postrm</span> (after removal of files) and <span class="code" dir="ltr">postinst</span> (after installation
of files) functions, because that is when the files on the file system have been
changed.
</p>
<a name="book_part3_chap6__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: Example /etc/portage/bashrc</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
if [ "${EBUILD_PHASE}" == "postinst" ] || [ "${EBUILD_PHASE}" == "postrm" ];
then
echo ":: Calling aide --update to update its database";
aide --update;
echo ":: Calling updatedb to update its database";
updatedb;
fi
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part3_chap6__chap4"></a><span class="chapnum">6.d. </span>Executing Tasks After --sync</p>
<p class="secthead"><a name="book_part3_chap6__chap4_sect1">The /etc/portage/postsync.d location</a></p>
<p>
Until now we've talked about hooking into the ebuild processes. However, Portage
also has another important function: updating the Portage tree. In order to run
tasks after updating the Portage tree, put a script inside
<span class="path" dir="ltr">/etc/portage/postsync.d</span> and make sure it is marked as executable.
</p>
<p class="secthead"><a name="book_part3_chap6__chap4_sect2">Example: Running eix-update</a></p>
<p>
If you didn't use <span class="code" dir="ltr">eix-sync</span> to update the tree, you can still have its
database updated after running <span class="code" dir="ltr">emerge --sync</span> (or <span class="code" dir="ltr">emerge-webrsync</span>)
by putting a symlink to <span class="path" dir="ltr">/usr/bin/eix</span> called <span class="path" dir="ltr">eix-update</span>
in <span class="path" dir="ltr">/etc/portage/postsync.d</span>.
</p>
<a name="book_part3_chap6__chap4_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.1: Running eix-update after a sync operation</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">ln -s /usr/bin/eix /etc/portage/postsync.d/eix-update</span>
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
If you rather use a different name, you will need to make a script that calls
<span class="code" dir="ltr">/usr/bin/eix-update</span> instead. The <span class="code" dir="ltr">eix</span> binary looks at how it has
been called to find out which function it has to execute. If you put in a
symlink to <span class="code" dir="ltr">eix</span> that isn't called <span class="code" dir="ltr">eix-update</span>, it will not run
correctly.
</p></td></tr></table>
<p class="chaphead"><a name="book_part3_chap6__chap5"></a><span class="chapnum">6.e. </span>Overriding Profile Settings</p>
<p class="secthead"><a name="book_part3_chap6__chap5_sect1">The /etc/portage/profile location</a></p>
<p>
By default, Gentoo uses the settings contained in the profile pointed to by
<span class="path" dir="ltr">/etc/portage/make.profile</span> (a symbolic link to the right profile
directory). These profiles define both specific settings as well as inherit
settings from other profiles (through their <span class="path" dir="ltr">parent</span> file).
</p>
<p>
By using <span class="path" dir="ltr">/etc/portage/profile</span>, you can override profile settings
such as <span class="path" dir="ltr">packages</span> (what packages are considered to be part of the
system set), forced use flags and more.
</p>
<p class="secthead"><a name="book_part3_chap6__chap5_sect2">Example: Adding nfs-utils to the System Set</a></p>
<p>
If you use NFS-based file systems for rather critical file systems, you might
want to have <span class="path" dir="ltr">net-fs/nfs-utils</span> "protected" as a system package,
causing Portage to heavily warn you if it would be deleted.
</p>
<p>
To accomplish that, we add the package to
<span class="path" dir="ltr">/etc/portage/profile/packages</span>, prepended with a <span class="code" dir="ltr">*</span>:
</p>
<a name="book_part3_chap6__chap5_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.1: /etc/portage/profile/packages content</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
*net-fs/nfs-utils
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part3_chap6__chap6"></a><span class="chapnum">6.f. </span>Applying Non-Standard Patches</p>
<p class="secthead"><a name="book_part3_chap6__chap6_sect1">Using epatch_user</a></p>
<p>
To manage several ebuilds in a similar manner, ebuild developers use
<span class="emphasis">eclasses</span> (sort-of shell libraries) that define commonly used functions.
One of these eclasses is <span class="path" dir="ltr">eutils.eclass</span> which offers an interesting
function called <span class="code" dir="ltr">epatch_user</span>.
</p>
<p>
The <span class="code" dir="ltr">epatch_user</span> function applies source code patches that are found in
<span class="path" dir="ltr">/etc/portage/patches/&lt;category&gt;/&lt;package&gt;[-&lt;version&gt;[-&lt;revision&gt;]]</span>,
whatever directory is found first. Sadly, not all ebuilds automatically call
this function so just putting your patch in this location might not always work.
</p>
<p>
Luckily, with the information provided above, you can call this function by
hooking into, for instance, the <span class="code" dir="ltr">prepare</span> phase. The function can be called
as many times as you like - it will only apply the patches once.
</p>
<p class="secthead"><a name="book_part3_chap6__chap6_sect2">Example: Applying Patches to Firefox</a></p>
<p>
The <span class="path" dir="ltr">www-client/firefox</span> package is one of the few that already call
<span class="code" dir="ltr">epatch_user</span> from within the ebuild, so you do not need to override
anything specific.
</p>
<p>
If you need to patch firefox (for instance because a developer provided you with
a patch and asked you to check if it fixes the bug you reported), put the patch in
<span class="path" dir="ltr">/etc/portage/patches/www-client/firefox</span> (probably best to use the
full name, including version so that the patch does not interfere with later
versions) and rebuild firefox.
</p>
<a name="book_part4"></a><h2>D. Gentoo Network Configuration</h2>
<a name="book_part4_chap1"></a><h3>1. Getting Started</h3>
<p class="chaphead"><a name="book_part4_chap1__chap1"></a><span class="chapnum">1.a. </span>Getting started</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
This document assumes that you have correctly configured your kernel, its
modules for your hardware and you know the interface name of your hardware.
We also assume that you are configuring <span class="code" dir="ltr">eth0</span>, but it could also be
<span class="code" dir="ltr">eno0</span>, <span class="code" dir="ltr">ens1</span>, <span class="code" dir="ltr">wlan0</span>, <span class="code" dir="ltr">enp1s0</span> etc.
</p></td></tr></table>
<p>
To get started configuring your network card, you need to tell the Gentoo RC
system about it. This is done by creating a symbolic link from
<span class="path" dir="ltr">net.lo</span> to <span class="path" dir="ltr">net.eth0</span> (or whatever the network interface
name is on your system) in <span class="path" dir="ltr">/etc/init.d</span>.
</p>
<a name="book_part4_chap1__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: Symlinking net.eth0 to net.lo</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">cd /etc/init.d</span>
# <span class="code-input">ln -s net.lo net.eth0</span>
</pre></td></tr>
</table>
<p>
Gentoo's RC system now knows about that interface. It also needs to know how
to configure the new interface. All the network interfaces are configured in
<span class="path" dir="ltr">/etc/conf.d/net</span>. Below is a sample configuration for DHCP and
static addresses.
</p>
<a name="book_part4_chap1__chap1_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.2: Examples for /etc/conf.d/net</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment"># For DHCP</span>
config_eth0="dhcp"
<span class="code-comment"># For static IP using CIDR notation</span>
config_eth0="192.168.0.7/24"
routes_eth0="default via 192.168.0.1"
dns_servers_eth0="192.168.0.1 8.8.8.8"
<span class="code-comment"># For static IP using netmask notation</span>
config_eth0="192.168.0.7 netmask 255.255.255.0"
routes_eth0="default via 192.168.0.1"
dns_servers_eth0="192.168.0.1 8.8.8.8"
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
If you do not specify a configuration for your interface then DHCP is assumed.
</p></td></tr></table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
CIDR stands for Classless InterDomain Routing. Originally, IPv4 addresses were
classified as A, B, or C. The early classification system did not envision the
massive popularity of the Internet, and is in danger of running out of new
unique addresses. CIDR is an addressing scheme that allows one IP address to
designate many IP addresses. A CIDR IP address looks like a normal IP address
except that it ends with a slash followed by a number; for example,
192.168.0.0/16. CIDR is described in <a href="http://tools.ietf.org/html/rfc1519">RFC 1519</a>.
</p></td></tr></table>
<p>
Now that we have configured our interface, we can start and stop it using the
following commands:
</p>
<a name="book_part4_chap1__chap1_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.3: Starting and stopping network scripts</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">/etc/init.d/net.eth0 start</span>
# <span class="code-input">/etc/init.d/net.eth0 stop</span>
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffffbb"><p class="note"><b>Important: </b>
When troubleshooting networking, take a look at <span class="path" dir="ltr">/var/log/rc.log</span>.
Unless you have <span class="code" dir="ltr">rc_logger="NO"</span> set in <span class="path" dir="ltr">/etc/rc.conf</span>, you
will find information on the boot activity stored in that log file.
</p></td></tr></table>
<p>
Now that you have successfully started and stopped your network interface, you
may wish to get it to start when Gentoo boots. Here's how to do this. The last
"rc" command instructs Gentoo to start any scripts in the current runlevel
that have not yet been started.
</p>
<a name="book_part4_chap1__chap1_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.4: Configuring a network interface to load at boot time</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">rc-update add net.eth0 default</span>
# <span class="code-input">rc</span>
</pre></td></tr>
</table>
<a name="book_part4_chap2"></a><h3>2. Advanced Configuration</h3>
<p class="chaphead"><a name="book_part4_chap2__chap1"></a><span class="chapnum">2.a. </span>Advanced Configuration</p>
<p>
The <span class="code" dir="ltr">config_eth0</span> variable is the heart of an interface configuration. It's
a high level instruction list for configuring the interface (<span class="code" dir="ltr">eth0</span> in this
case). Each command in the instruction list is performed sequentially. The
interface is deemed OK if at least one command works.
</p>
<p>
Here's a list of built-in instructions.
</p>
<table class="ntable">
<tr>
<td class="infohead"><b>Command</b></td>
<td class="infohead"><b>Description</b></td>
</tr>
<tr>
<td class="tableinfo"><span class="code" dir="ltr">null</span></td>
<td class="tableinfo">Do nothing</td>
</tr>
<tr>
<td class="tableinfo"><span class="code" dir="ltr">noop</span></td>
<td class="tableinfo">
If the interface is up and there is an address then abort configuration
successfully
</td>
</tr>
<tr>
<td class="tableinfo">an IPv4 or IPv6 address</td>
<td class="tableinfo">Add the address to the interface</td>
</tr>
<tr>
<td class="tableinfo">
<span class="code" dir="ltr">dhcp</span>, <span class="code" dir="ltr">adsl</span> or <span class="code" dir="ltr">apipa</span> (or a custom command from a 3rd
party module)
</td>
<td class="tableinfo">
Run the module which provides the command. For example <span class="code" dir="ltr">dhcp</span> will run
a module that provides DHCP which can be one of either <span class="code" dir="ltr">dhcpcd</span>,
<span class="code" dir="ltr">dhclient</span> or <span class="code" dir="ltr">pump</span>.
</td>
</tr>
</table>
<p>
If a command fails, you can specify a fallback command. The fallback has to
match the config structure exactly.
</p>
<p>
You can chain these commands together. Here are some real world examples.
</p>
<a name="book_part4_chap2__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: Configuration examples</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment"># Adding three IPv4 addresses</span>
config_eth0="192.168.0.2/24
192.168.0.3/24
192.168.0.4/24"
<span class="code-comment"># Adding an IPv4 address and two IPv6 addresses</span>
config_eth0="192.168.0.2/24
4321:0:1:2:3:4:567:89ab
4321:0:1:2:3:4:567:89ac"
<span class="code-comment"># Keep our kernel assigned address, unless the interface goes
# down so assign another via DHCP. If DHCP fails then add a
# static address determined by APIPA</span>
config_eth0="noop
dhcp"
fallback_eth0="null
apipa"
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
When using the <span class="code" dir="ltr">ifconfig</span> module and adding more than one address,
interface aliases are created for each extra address. So with the above two
examples you will get interfaces <span class="code" dir="ltr">eth0</span>, <span class="code" dir="ltr">eth0:1</span> and <span class="code" dir="ltr">eth0:2</span>.
You cannot do anything special with these interfaces as the kernel and other
programs will just treat <span class="code" dir="ltr">eth0:1</span> and <span class="code" dir="ltr">eth0:2</span> as <span class="code" dir="ltr">eth0</span>.
</p></td></tr></table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffffbb"><p class="note"><b>Important: </b>
The fallback order is important! If we did not specify the <span class="code" dir="ltr">null</span> option
then the <span class="code" dir="ltr">apipa</span> command would only be run if the <span class="code" dir="ltr">noop</span> command
failed.
</p></td></tr></table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
<a href="#apipa">APIPA</a> and <a href="#dhcp">DHCP</a> are discussed later.
</p></td></tr></table>
<p class="chaphead"><a name="book_part4_chap2__chap2"></a><span class="chapnum">2.b. </span>Network Dependencies</p>
<p>
Init scripts in <span class="path" dir="ltr">/etc/init.d</span> can depend on a specific network
interface or just net. All network interfaces in Gentoo's init system provide
what is called <span class="emphasis">net</span>.
</p>
<p>
If, in <span class="path" dir="ltr">/etc/rc.conf</span>, <span class="code" dir="ltr">rc_depend_strict="YES"</span> is set, then all
network interfaces that provide net must be active before a dependency on "net"
is assumed to be met. In other words, if you have a <span class="path" dir="ltr">net.eth0</span> and
<span class="path" dir="ltr">net.eth1</span> and an init script depends on "net", then both must be
enabled.
</p>
<p>
On the other hand, if <span class="code" dir="ltr">rc_depend_strict="NO"</span> is set, then the "net"
dependency is marked as resolved the moment at least one network interface is
brought up.
</p>
<p>
But what about <span class="path" dir="ltr">net.br0</span> depending on <span class="path" dir="ltr">net.eth0</span> and
<span class="path" dir="ltr">net.eth1</span>? <span class="path" dir="ltr">net.eth1</span> may be a wireless or PPP device
that needs configuration before it can be added to the bridge. This cannot be
done in <span class="path" dir="ltr">/etc/init.d/net.br0</span> as that's a symbolic link to
<span class="path" dir="ltr">net.lo</span>.
</p>
<p>
The answer is defining an <span class="code" dir="ltr">rc_need_</span> setting in
<span class="path" dir="ltr">/etc/conf.d/net</span>.
</p>
<a name="book_part4_chap2__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: net.br0 dependency in /etc/conf.d/net</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
rc_need_br0="net.eth0 net.eth1"
</pre></td></tr>
</table>
<p>
That alone, however, is not sufficient. Gentoo's networking init scripts use a
virtual dependency called <span class="emphasis">net</span> to inform the system when networking is
available. Clearly, in the above case, networking should only be marked as
available when <span class="path" dir="ltr">net.br0</span> is up, not when the others are. So we need
to tell that in <span class="path" dir="ltr">/etc/conf.d/net</span> as well:
</p>
<a name="book_part4_chap2__chap2_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.2: Updating virtual dependencies and provisions for networking</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
rc_net_lo_provide="!net"
rc_net_eth0_provide="!net"
rc_net_eth1_provide="!net"
</pre></td></tr>
</table>
<p>
For a more detailed discussion about dependency, consult the section <a href="#book_part2_chap4__chap4">Writing Init Scripts</a> in the Gentoo
Handbook. More information about <span class="path" dir="ltr">/etc/rc.conf</span> is available as
comments within that file.
</p>
<p class="chaphead"><a name="variable_name"></a><a name="book_part4_chap2__chap3"></a><span class="chapnum">2.c. </span>Variable names and values</p>
<p>
Variable names are dynamic. They normally follow the structure of
<span class="code" dir="ltr">variable_${interface|mac|essid|apmac}</span>. For example, the variable
<span class="code" dir="ltr">dhcpcd_eth0</span> holds the value for dhcpcd options for eth0 and
<span class="code" dir="ltr">dhcpcd_essid</span> holds the value for dhcpcd options when any interface
connects to the ESSID "essid".
</p>
<p>
However, there is no hard and fast rule that states interface names must be
ethx. In fact, many wireless interfaces have names like wlanx, rax as well as
ethx. Also, some user defined interfaces such as bridges can be given any name,
such as foo. To make life more interesting, wireless Access Points can have
names with non alpha-numeric characters in them - this is important because
you can configure networking parameters per ESSID.
</p>
<p>
The downside of all this is that Gentoo uses bash variables for networking -
and bash cannot use anything outside of English alpha-numerics. To get around
this limitation we change every character that is not an English alpha-numeric
into a <span class="code" dir="ltr">_</span> character.
</p>
<p>
Another downside of bash is the content of variables - some characters need to
be escaped. This can be achived by placing the <span class="code" dir="ltr">\</span> character in front of
the character that needs to be escaped. The following list of characters needs
to be escaped in this way: <span class="code" dir="ltr">"</span>, <span class="code" dir="ltr">'</span> and <span class="code" dir="ltr">\</span>.
</p>
<p>
In this example we use wireless ESSID as they can contain the widest scope
of characters. We shall use the ESSID <span class="code" dir="ltr">My "\ NET</span>:
</p>
<a name="book_part4_chap2__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: variable name example</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment">(This does work, but the domain is invalid)</span>
dns_domain_My____NET="My \"\\ NET"
<span class="code-comment">(The above sets the dns domain to My "\ NET when a wireless card
connects to an AP whose ESSID is My "\ NET)</span>
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part4_chap2__chap4"></a><span class="chapnum">2.d. </span>Network Interface Naming</p>
<p class="secthead"><a name="book_part4_chap2__chap4_sect1">How It Works</a></p>
<p>
Network interface names are not chosen arbitrarily: the Linux kernel and the
device manager (most systems have udev as their device manager although others
are available as well) choose the interface name through a fixed set of rules.
</p>
<p>
When an interface card is detected on a system, the Linux kernel gathers the
necessary data about this card. This includes:
</p>
<ol>
<li>
the onboard (on the interface itself) registered name of the network card,
which is later seen through the <span class="code" dir="ltr">ID_NET_NAME_ONBOARD</span> parameter;
</li>
<li>
the slot in which the network card is plugged in, which is later seen
through the <span class="code" dir="ltr">ID_NET_NAME_SLOT</span> parameter;
</li>
<li>
the path through which the network card device can be accessed, which is
later seen through the <span class="code" dir="ltr">ID_NET_NAME_PATH</span> parameter;
</li>
<li>
the (vendor-provided) MAC address of the card, which is later seen through
the <span class="code" dir="ltr">ID_NET_NAME_MAC</span> parameter;
</li>
</ol>
<p>
Based on this information, the device manager decides how to name the interface
on the system. By default, it uses the first hit of the first three parameters
above (<span class="code" dir="ltr">ID_NET_NAME_ONBOARD</span>, <span class="code" dir="ltr">_SLOT</span> or <span class="code" dir="ltr">_PATH</span>).
For instance, if <span class="code" dir="ltr">ID_NET_NAME_ONBOARD</span> is found and set to <span class="code" dir="ltr">eno1</span>, then
the interface will be called eno1.
</p>
<p>
If you know your interface name, you can see the values of the provided
parameters using <span class="code" dir="ltr">udevadm</span>:
</p>
<a name="book_part4_chap2__chap4_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.1: Reading the network interface card information</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">udevadm test-builtin net_id /sys/class/net/enp3s0 2&gt;/dev/null</span>
ID_NET_NAME_MAC=enxc80aa9429d76
ID_OUI_FROM_DATABASE=Quanta Computer Inc.
ID_NET_NAME_PATH=enp3s0
</pre></td></tr>
</table>
<p>
As the first (and actually only) hit of the top three parameters is the
<span class="code" dir="ltr">ID_NET_NAME_PATH</span> one, its value is used as the interface name. If none of
the parameters is found, then the system reverts back to the kernel-provided
naming (eth0, eth1, etc.)
</p>
<p class="secthead"><a name="book_part4_chap2__chap4_sect2">Using the Old-style Kernel Naming</a></p>
<p>
Before this change, network interface cards were named by the Linux kernel
itself, depending on the order that drivers are loaded (amongst other, possibly
more obscure reasons). This behavior can still be enabled by setting the
<span class="code" dir="ltr">net.ifnames=0</span> boot option in the boot loader.
</p>
<p class="secthead"><a name="book_part4_chap2__chap4_sect3">Using your Own Names</a></p>
<p>
The entire idea behind the change in naming is not to confuse people, but to
make changing the names easier. Suppose you have two interfaces that are
otherwise called eth0 and eth1. One is meant to access the network through a
wire, the other one is for wireless access. With the support for interface
naming, you can have these called lan0 (wired) and wifi0 (wireless - it is best
to avoid using the previously well-known names like eth* and wlan* as those can
still collide with your suggested names).
</p>
<p>
All you need to do is to find out what the parameters are for the cards and then
use this information to set up your own naming rule:
</p>
<a name="book_part4_chap2__chap4_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.2: Setting the lan0 name for the current eth0 interface</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">udevadm test-builtin net_id /sys/class/net/eth0 2&gt;/dev/null</span>
ID_NET_NAME_MAC=enxc80aa9429d76
ID_OUI_FROM_DATABASE=Quanta Computer Inc.
# <span class="code-input">vim /etc/udev/rules.d/70-net-name-use-custom.rules</span>
<span class="code-comment"># First one uses MAC information, and 70- number to be before other net rules</span>
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="c8:0a:a9:42:9d:76", NAME="lan0"
# <span class="code-input">vim /etc/udev/rules.d/76-net-name-use-custom.rules</span>
<span class="code-comment"># Second one uses ID_NET_NAME_PATH information, and 76- number to be between</span>
<span class="code-comment"># 75-net-*.rules and 80-net-*.rules</span>
SUBSYSTEM=="net", ACTION=="add", ENV{ID_NET_NAME_PATH}=="enp3s0", NAME="wifi0"
</pre></td></tr>
</table>
<p>
Because the rules are triggered before the default one (rules are triggered in
alphanumerical order, so 70 comes before 80) the names provided in the rule file
will be used instead of the default ones. The number granted to the file should
be between 76 and 79 (the environment variables are defined by a rule start
starts with 75 and the fallback naming is done in a rule numbered 80).
</p>
<a name="book_part4_chap3"></a><h3>3. Modular Networking</h3>
<p class="chaphead"><a name="book_part4_chap3__chap1"></a><span class="chapnum">3.a. </span>Network Modules</p>
<p>
We now support modular networking scripts, which means we can easily add support
for new interface types and configuration modules while keeping compatibility
with existing ones.
</p>
<p>
Modules load by default if the package they need is installed. If you specify a
module here that doesn't have its package installed then you get an error
stating which package you need to install. Ideally, you only use the modules
setting when you have two or more packages installed that supply the same
service and you need to prefer one over the other.
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
All settings discussed here are stored in <span class="path" dir="ltr">/etc/conf.d/net</span> unless
otherwise specified.
</p></td></tr></table>
<a name="book_part4_chap3__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: Module preference</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment"># Prefer ifconfig over iproute2</span>
modules="ifconfig"
<span class="code-comment"># You can also specify other modules for an interface
# In this case we prefer pump over dhcpcd</span>
modules_eth0="pump"
<span class="code-comment"># You can also specify which modules not to use - for example you may be
# using a supplicant or linux-wlan-ng to control wireless configuration but
# you still want to configure network settings per ESSID associated with.</span>
modules="!iwconfig"
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part4_chap3__chap2"></a><span class="chapnum">3.b. </span>Interface Handlers</p>
<p>
We provide two interface handlers presently: <span class="code" dir="ltr">ifconfig</span> and
<span class="code" dir="ltr">iproute2</span>. You need one of these to do any kind of network configuration.
</p>
<p>
<span class="code" dir="ltr">ifconfig</span> is installed by default (the <span class="code" dir="ltr">net-tools</span> package is part of
the system profile). <span class="code" dir="ltr">iproute2</span> is a more powerful and flexible package,
but it's not included by default.
</p>
<a name="book_part4_chap3__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: To install iproute2</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge sys-apps/iproute2</span>
<span class="code-comment"># To prefer ifconfig over iproute2 if both are installed as openrc prefers
# to use iproute2 then</span>
modules="ifconfig"
</pre></td></tr>
</table>
<p>
As both <span class="code" dir="ltr">ifconfig</span> and <span class="code" dir="ltr">iproute2</span> do very similar things we allow
their basic configuration to work with each other. For example both the below
code snippet work regardless of which module you are using.
</p>
<a name="book_part4_chap3__chap2_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.2: ifconfig and iproute2 examples</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
config_eth0="192.168.0.2/24"
config_eth0="192.168.0.2 netmask 255.255.255.0"
<span class="code-comment"># We can also specify broadcast</span>
config_eth0="192.168.0.2/24 brd 192.168.0.255"
config_eth0="192.168.0.2 netmask 255.255.255.0 broadcast 192.168.0.255"
</pre></td></tr>
</table>
<p class="chaphead"><a name="dhcp"></a><a name="book_part4_chap3__chap3"></a><span class="chapnum">3.c. </span>DHCP</p>
<p>
DHCP is a means of obtaining network information (IP address, DNS servers,
Gateway, etc) from a DHCP server. This means that if there is a DHCP server
running on the network, you just have to tell each client to use DHCP and it
sets up the network all by itself. Of course, you will have to configure for
other things like wireless, PPP or other things if required before you can use
DHCP.
</p>
<p>
DHCP can be provided by <span class="code" dir="ltr">dhclient</span>, <span class="code" dir="ltr">dhcpcd</span>, or <span class="code" dir="ltr">pump</span>. Each
DHCP module has its pros and cons - here's a quick run down.
</p>
<table class="ntable">
<tr>
<td class="infohead"><b>DHCP Module</b></td>
<td class="infohead"><b>Package</b></td>
<td class="infohead"><b>Pros</b></td>
<td class="infohead"><b>Cons</b></td>
</tr>
<tr>
<td class="tableinfo"><span class="code" dir="ltr">dhclient</span></td>
<td class="tableinfo"><span class="code" dir="ltr">net-misc/dhcp</span></td>
<td class="tableinfo">
Made by ISC, the same people who make the BIND DNS software. Very
configurable
</td>
<td class="tableinfo">
Configuration is overly complex, software is quite bloated, cannot get
NTP servers from DHCP, does not send hostname by default
</td>
</tr>
<tr>
<td class="tableinfo"><span class="code" dir="ltr">dhcpcd</span></td>
<td class="tableinfo"><span class="code" dir="ltr">net-misc/dhcpcd</span></td>
<td class="tableinfo">
Long time Gentoo default, no reliance on outside tools, actively developed
by Gentoo
</td>
<td class="tableinfo">Can be slow at times, does not yet daemonize when lease is infinite</td>
</tr>
<tr>
<td class="tableinfo"><span class="code" dir="ltr">pump</span></td>
<td class="tableinfo"><span class="code" dir="ltr">net-misc/pump</span></td>
<td class="tableinfo">
Lightweight, no reliance on outside tools
</td>
<td class="tableinfo">
No longer maintained upstream, unreliable, especially over modems, cannot
get NIS servers from DHCP
</td>
</tr>
</table>
<p>
If you have more than one DHCP client installed, you need to specify which one
to use - otherwise we default to <span class="code" dir="ltr">dhcpcd</span> if available.
</p>
<p>
To send specific options to the DHCP module, use <span class="code" dir="ltr">module_eth0="..."</span>
<span class="emphasis">(change module to the DHCP module you're using - i.e. <span class="code" dir="ltr">dhcpcd_eth0</span>)</span>.
</p>
<p>
We try and make DHCP relatively agnostic - as such we support the following
commands using the <span class="code" dir="ltr">dhcp_eth0</span> variable. The default is not to set any of
them:
</p>
<ul>
<li>
<span class="code" dir="ltr">release</span> - releases the IP address for re-use</li>
<li>
<span class="code" dir="ltr">nodns</span> - don't overwrite <span class="path" dir="ltr">/etc/resolv.conf</span>
</li>
<li>
<span class="code" dir="ltr">nontp</span> - don't overwrite <span class="path" dir="ltr">/etc/ntp.conf</span>
</li>
<li>
<span class="code" dir="ltr">nonis</span> - don't overwrite <span class="path" dir="ltr">/etc/yp.conf</span>
</li>
</ul>
<a name="book_part4_chap3__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: Sample DHCP configuration in /etc/conf.d/net</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment"># Only needed if you have more than one DHCP module installed</span>
modules="dhcpcd"
config_eth0="dhcp"
dhcpcd_eth0="-t 10" <span class="code-comment"># Timeout after 10 seconds</span>
dhcp_eth0="release nodns nontp nonis" <span class="code-comment"># Only get an address</span>
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
<span class="code" dir="ltr">dhcpcd</span> and <span class="code" dir="ltr">pump</span> send the current hostname to the
DHCP server by default so you don't need to specify this anymore.
</p></td></tr></table>
<p class="chaphead"><a name="book_part4_chap3__chap4"></a><span class="chapnum">3.d. </span>ADSL with PPPoE/PPPoA</p>
<p>
First we need to install the ADSL software.
</p>
<a name="book_part4_chap3__chap4_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.1: Install the ppp package</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge net-dialup/ppp</span>
</pre></td></tr>
</table>
<p>
Second, create the PPP net script and the net script for the ethernet interface
to be used by PPP:
</p>
<a name="book_part4_chap3__chap4_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.2: Creating the PPP and ethernet scripts</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">ln -s /etc/init.d/net.lo /etc/init.d/net.ppp0</span>
# <span class="code-input">ln -s /etc/init.d/net.lo /etc/init.d/net.eth0</span>
</pre></td></tr>
</table>
<p>
Be sure to set <span class="code" dir="ltr">rc_depend_strict</span> to "YES" in <span class="path" dir="ltr">/etc/rc.conf</span>.
</p>
<p>
Now we need to configure <span class="path" dir="ltr">/etc/conf.d/net</span>.
</p>
<a name="book_part4_chap3__chap4_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.3: A basic PPPoE setup</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
config_eth0=null <span class="code-comment">(Specify your ethernet interface)</span>
config_ppp0="ppp"
link_ppp0="eth0" <span class="code-comment">(Specify your ethernet interface)</span>
plugins_ppp0="pppoe"
username_ppp0='user'
password_ppp0='password'
pppd_ppp0="
noauth
defaultroute
usepeerdns
holdoff 3
child-timeout 60
lcp-echo-interval 15
lcp-echo-failure 3
noaccomp noccp nobsdcomp nodeflate nopcomp novj novjccomp"
rc_need_ppp0="net.eth0"
</pre></td></tr>
</table>
<p>
You can also set your password in <span class="path" dir="ltr">/etc/ppp/pap-secrets</span>.
</p>
<a name="book_part4_chap3__chap4_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.4: Sample /etc/ppp/pap-secrets</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment"># The * is important</span>
"username" * "password"
</pre></td></tr>
</table>
<p>
If you use PPPoE with a USB modem you'll need to emerge <span class="code" dir="ltr">br2684ctl</span>. Please
read <span class="path" dir="ltr">/usr/portage/net-dialup/speedtouch-usb/files/README</span> for
information on how to properly configure it.
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffffbb"><p class="note"><b>Important: </b>
Please carefully read the section on ADSL and PPP in
<span class="path" dir="ltr">/usr/share/doc/netifrc-*/net.example.bz2</span>. It contains many
more detailed explanations of all the settings your particular PPP setup will
likely need.
</p></td></tr></table>
<p class="chaphead"><a name="apipa"></a><a name="book_part4_chap3__chap5"></a><span class="chapnum">3.e. </span>APIPA (Automatic Private IP Addressing)</p>
<p>
APIPA tries to find a free address in the range 169.254.0.0-169.254.255.255 by
arping a random address in that range on the interface. If no reply is found
then we assign that address to the interface.
</p>
<p>
This is only useful for LANs where there is no DHCP server and you don't connect
directly to the internet and all other computers use APIPA.
</p>
<p>
For APIPA support, emerge <span class="code" dir="ltr">net-misc/iputils</span> or <span class="code" dir="ltr">net-analyzer/arping</span>.
</p>
<a name="book_part4_chap3__chap5_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 5.1: APIPA configuration in /etc/conf.d/net</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment"># Try DHCP first - if that fails then fallback to APIPA</span>
config_eth0="dhcp"
fallback_eth0="apipa"
<span class="code-comment"># Just use APIPA</span>
config_eth0="apipa"
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part4_chap3__chap6"></a><span class="chapnum">3.f. </span>Bonding</p>
<p>
For link bonding/trunking emerge <span class="code" dir="ltr">net-misc/ifenslave</span>.
</p>
<p>
Bonding is used to increase network bandwidth or to improve resiliency in face
of hardware failures. If you have two network cards going to the same network,
you can bond them together so your applications see just one interface but they
really use both network cards.
</p>
<p>
There are many ways to configure bonding. Some of them, such as the 802.3ad LACP
mode, require support and additional configuration of the network switch. For a
reference of the individual options, please refer to your copy of
<span class="path" dir="ltr">/usr/src/linux/Documentation/networking/bonding.txt</span>.
</p>
<p>
First, clear the configuration of the participating interfaces:
</p>
<a name="book_part4_chap3__chap6_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 6.1: Clearing interface configuration in /etc/conf.d/net</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
config_eth0="null"
config_eth1="null"
config_eth2="null"
</pre></td></tr>
</table>
<p>
Next, define the bonding between the interfaces:
</p>
<a name="book_part4_chap3__chap6_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 6.2: Define the bonding</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
slaves_bond0="eth0 eth1 eth2"
config_bond0="192.168.100.4/24"
<span class="code-comment"># Pick a correct mode and additional configuration options which suit your needs</span>
mode_bond0="balance-alb"
</pre></td></tr>
</table>
<p>
Remove the <span class="path" dir="ltr">net.eth*</span> services from the runlevels, create a
<span class="path" dir="ltr">net.bond0</span> one and add that one to the correct runlevel.
</p>
<p class="chaphead"><a name="book_part4_chap3__chap7"></a><span class="chapnum">3.g. </span>Bridging (802.1d support)</p>
<p>
For bridging support emerge <span class="code" dir="ltr">net-misc/bridge-utils</span>.
</p>
<p>
Bridging is used to join networks together. For example, you may have a server
that connects to the internet via an ADSL modem and a wireless access card to
enable other computers to connect to the internet via the ADSL modem. You could
create a bridge to join the two interfaces together.
</p>
<a name="book_part4_chap3__chap7_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 7.1: Bridge configuration in /etc/conf.d/net</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment"># Configure the bridge - "man brctl" for more details</span>
brctl_br0="setfd 0
sethello 2
stp on"
<span class="code-comment"># To add ports to bridge br0</span>
bridge_br0="eth0 eth1"
<span class="code-comment"># You need to configure the ports to null values so dhcp does not get started</span>
config_eth0="null"
config_eth1="null"
<span class="code-comment"># Finally give the bridge an address - you could use DHCP as well</span>
config_br0="192.168.0.1/24"
<span class="code-comment"># Depend on eth0 and eth1 as they may require extra configuration</span>
rc_need_br0="net.eth0 net.eth1"
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffffbb"><p class="note"><b>Important: </b>
For using some bridge setups, you may need to consult the <a href="#variable_name">variable name</a> documentation.
</p></td></tr></table>
<p class="chaphead"><a name="book_part4_chap3__chap8"></a><span class="chapnum">3.h. </span>MAC Address</p>
<p>
If you need to, you can change the MAC address of your interfaces through
the network configuration file too.
</p>
<a name="book_part4_chap3__chap8_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 8.1: MAC Address change example</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment"># To set the MAC address of the interface</span>
mac_eth0="00:11:22:33:44:55"
<span class="code-comment"># To randomize the last 3 bytes only</span>
mac_eth0="random-ending"
<span class="code-comment"># To randomize between the same physical type of connection (e.g. fibre,
# copper, wireless) , all vendors</span>
mac_eth0="random-samekind"
<span class="code-comment"># To randomize between any physical type of connection (e.g. fibre, copper,
# wireless) , all vendors</span>
mac_eth0="random-anykind"
<span class="code-comment"># Full randomization - WARNING: some MAC addresses generated by this may
# NOT act as expected</span>
mac_eth0="random-full"
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part4_chap3__chap9"></a><span class="chapnum">3.i. </span>Tunnelling</p>
<p>
You don't need to emerge anything for tunnelling as the interface handler can do
it for you.
</p>
<a name="book_part4_chap3__chap9_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 9.1: Tunnelling configuration in /etc/conf.d/net</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment"># For GRE tunnels</span>
iptunnel_vpn0="mode gre remote 207.170.82.1 key 0xffffffff ttl 255"
<span class="code-comment"># For IPIP tunnels</span>
iptunnel_vpn0="mode ipip remote 207.170.82.2 ttl 255"
<span class="code-comment"># To configure the interface</span>
config_vpn0="192.168.0.2 peer 192.168.1.1"
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part4_chap3__chap10"></a><span class="chapnum">3.j. </span>VLAN (802.1q support)</p>
<p>
For VLAN support, make sure that <span class="code" dir="ltr">sys-apps/iproute2</span> is installed and ensure
that iproute2 is used as configuration module rather than ifconfig.
</p>
<p>
Virtual LAN is a group of network devices that behave as if they were connected
to a single network segment - even though they may not be. VLAN members can only
see members of the same VLAN even though they may share the same physical
network.
</p>
<p>
To configure VLANs, first specify the VLAN numbers in
<span class="path" dir="ltr">/etc/conf.d/net</span> like so:
</p>
<a name="book_part4_chap3__chap10_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 10.1: Specifying VLAN numbers</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
vlans_eth0="1 2"
</pre></td></tr>
</table>
<p>
Next, configure the interface for each VLAN:
</p>
<a name="book_part4_chap3__chap10_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 10.2: Interface configuration for each VLAN</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
config_eth0_1="172.16.3.1 netmask 255.255.254.0"
routes_eth0_1="default via 172.16.3.254"
config_eth0_2="172.16.2.1 netmask 255.255.254.0"
routes_eth0_2="default via 172.16.2.254"
</pre></td></tr>
</table>
<p>
VLAN-specific configurations are handled by <span class="code" dir="ltr">vconfig</span> like so:
</p>
<a name="book_part4_chap3__chap10_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 10.3: Configuring the VLANs</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
vlan1_name="vlan1"
vlan1_ingress="2:6 3:5"
eth0_vlan1_egress="1:2"
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffffbb"><p class="note"><b>Important: </b>
For using some VLAN setups, you may need to consult the <a href="#variable_name">variable name</a> documentation.
</p></td></tr></table>
<a name="book_part4_chap4"></a><h3>4. Wireless Networking</h3>
<p class="chaphead"><a name="book_part4_chap4__chap1"></a><span class="chapnum">4.a. </span>Introduction</p>
<p>
Wireless networking on Linux is usually pretty straightforward. There are two
ways of configuring wifi: graphical clients, or the command line.
</p>
<p>
The <span class="emphasis">easiest</span> way is to use a graphical client once you've installed a
desktop environment. Most graphical clients,
such as <a href="http://wicd.sourceforge.net">wicd</a> and <a href="http://www.gnome.org/projects/NetworkManager">NetworkManager</a>, are
pretty self-explanatory. They offer a handy point-and-click interface that gets
you on a network in just a few seconds.
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
<span class="code" dir="ltr">wicd</span> offers a command line utility <span class="emphasis">in addition</span> to the main
graphical interface. You can get it by emerging <span class="code" dir="ltr">wicd</span> with the
<span class="code" dir="ltr">ncurses</span> USE flag set. This <span class="code" dir="ltr">wicd-curses</span> utility is particularly
useful for folks who don't use a gtk-based desktop environment, but still want
an easy command line tool that doesn't require hand-editing configuration
files.
</p></td></tr></table>
<p>
However, if you don't want to use a graphical client, then you can configure
wifi on the command line by editing a few configuration files. This takes a bit
more time to setup, but it also requires the fewest packages to download and
install. Since the graphical clients are mostly self-explanatory (with helpful
screenshots at their homepages), we'll focus on the command line alternatives.
</p>
<p>
You can setup wireless networking on the command line by installing
<span class="code" dir="ltr">wireless-tools</span> or <span class="code" dir="ltr">wpa_supplicant</span>. The important thing to remember
is that you configure wireless networks on a global basis and not an interface
basis.
</p>
<p>
<span class="code" dir="ltr">wpa_supplicant</span> is the best choice. For a list of supported drivers, <a href="http://hostap.epitest.fi/wpa_supplicant">read the wpa_supplicant
site</a>.
</p>
<p>
<span class="code" dir="ltr">wireless-tools</span> supports nearly all cards and drivers, but it cannot
connect to WPA-only Access Points. If your networks only offer WEP encryption or
are completely open, you may prefer the simplicity of <span class="code" dir="ltr">wireless-tools</span>.
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffbbbb"><p class="note"><b>Warning: </b>
The <span class="code" dir="ltr">linux-wlan-ng</span> driver is not supported by baselayout at this time.
This is because <span class="code" dir="ltr">linux-wlan-ng</span> have its own setup and configuration which
is completely different to everyone else's. The <span class="code" dir="ltr">linux-wlan-ng</span> developers
are rumoured to be changing their setup over to <span class="code" dir="ltr">wireless-tools</span>, so when
this happens you may use <span class="code" dir="ltr">linux-wlan-ng</span> with baselayout.
</p></td></tr></table>
<p>
Some wireless cards are deactivated by default. To activate them, please consult
your hardware documentation. Some of these cards can be unblocked using the
rfkill application. If that is the case, use "rfkill list" to see the available
cards and "rfkill unblock &lt;index&gt;" to activate the wireless functionality.
If not, you might need to unblock the wireless card through a button, switch
or special key combination on your laptop.
</p>
<p class="chaphead"><a name="book_part4_chap4__chap2"></a><span class="chapnum">4.b. </span>WPA Supplicant</p>
<p>
<a href="http://hostap.epitest.fi/wpa_supplicant">WPA Supplicant</a> is a
package that allows you to connect to WPA enabled access points.
</p>
<a name="book_part4_chap4__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: Install wpa_supplicant</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge net-wireless/wpa_supplicant</span>
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffffbb"><p class="note"><b>Important: </b>
You have to have <span class="code" dir="ltr">CONFIG_PACKET</span> enabled in your kernel for
<span class="code" dir="ltr">wpa_supplicant</span> to work. Try running <span class="code" dir="ltr">grep CONFIG_PACKET
/usr/src/linux/.config</span> to see if you have it enabled in your kernel.
</p></td></tr></table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
Depending on your USE flags, <span class="code" dir="ltr">wpa_supplicant</span> can install a graphical
interface written in Qt4, which will integrate nicely with KDE. To get it, run
<span class="code" dir="ltr">echo "net-wireless/wpa_supplicant qt4" &gt;&gt; /etc/portage/package.use</span> as
root before emerging <span class="code" dir="ltr">wpa_supplicant</span>.
</p></td></tr></table>
<p>
Now we have to configure <span class="path" dir="ltr">/etc/conf.d/net</span> to so that we prefer
<span class="code" dir="ltr">wpa_supplicant</span> over <span class="code" dir="ltr">wireless-tools</span> (if both are installed,
<span class="code" dir="ltr">wireless-tools</span> is the default).
</p>
<a name="book_part4_chap4__chap2_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.2: configure /etc/conf.d/net for wpa_supplicant</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment"># Prefer wpa_supplicant over wireless-tools</span>
modules="wpa_supplicant"
<span class="code-comment"># It's important that we tell wpa_supplicant which driver we should
# be using as it's not very good at guessing yet</span>
wpa_supplicant_eth0="-Dmadwifi"
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
If you're using the host-ap driver you will need to put the card in <span class="emphasis">Managed
mode</span> before it can be used with <span class="code" dir="ltr">wpa_supplicant</span> correctly. You can use
<span class="code" dir="ltr">iwconfig_eth0="mode managed"</span> to achieve this in
<span class="path" dir="ltr">/etc/conf.d/net</span>.
</p></td></tr></table>
<p>
That was simple, wasn't it? However, we still have to configure
<span class="code" dir="ltr">wpa_supplicant</span> itself which is a bit more tricky depending on how secure
the Access Points are that you are trying to connect to. The below example is
taken and simplified from
<span class="path" dir="ltr">/usr/share/doc/wpa_supplicant-&lt;version&gt;/wpa_supplicant.conf.gz</span>
which ships with <span class="code" dir="ltr">wpa_supplicant</span>.
</p>
<a name="book_part4_chap4__chap2_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.3: An example /etc/wpa_supplicant/wpa_supplicant.conf</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment"># The below line not be changed otherwise we refuse to work</span>
ctrl_interface=/var/run/wpa_supplicant
<span class="code-comment"># Ensure that only root can read the WPA configuration</span>
ctrl_interface_group=0
<span class="code-comment"># Let wpa_supplicant take care of scanning and AP selection</span>
ap_scan=1
<span class="code-comment"># Simple case: WPA-PSK, PSK as an ASCII passphrase, allow all valid ciphers</span>
network={
ssid="simple"
psk="very secret passphrase"
<span class="code-comment"># The higher the priority the sooner we are matched</span>
priority=5
}
<span class="code-comment"># Same as previous, but request SSID-specific scanning (for APs that reject
# broadcast SSID)</span>
network={
ssid="second ssid"
scan_ssid=1
psk="very secret passphrase"
priority=2
}
<span class="code-comment"># Only WPA-PSK is used. Any valid cipher combination is accepted</span>
network={
ssid="example"
proto=WPA
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP WEP104 WEP40
psk=06b4be19da289f475aa46a33cb793029d4ab3db7a23ee92382eb0106c72ac7bb
priority=2
}
<span class="code-comment"># Plaintext connection (no WPA, no IEEE 802.1X)</span>
network={
ssid="plaintext-test"
key_mgmt=NONE
}
<span class="code-comment"># Shared WEP key connection (no WPA, no IEEE 802.1X)</span>
network={
ssid="static-wep-test"
key_mgmt=NONE
<span class="code-comment"># Keys in quotes are ASCII keys</span>
wep_key0="abcde"
<span class="code-comment"># Keys specified without quotes are hex keys</span>
wep_key1=0102030405
wep_key2="1234567890123"
wep_tx_keyidx=0
priority=5
}
<span class="code-comment"># Shared WEP key connection (no WPA, no IEEE 802.1X) using Shared Key
# IEEE 802.11 authentication</span>
network={
ssid="static-wep-test2"
key_mgmt=NONE
wep_key0="abcde"
wep_key1=0102030405
wep_key2="1234567890123"
wep_tx_keyidx=0
priority=5
auth_alg=SHARED
}
<span class="code-comment"># IBSS/ad-hoc network with WPA-None/TKIP</span>
network={
ssid="test adhoc"
mode=1
proto=WPA
key_mgmt=WPA-NONE
pairwise=NONE
group=TKIP
psk="secret passphrase"
}
</pre></td></tr>
</table>
<p class="chaphead"><a name="book_part4_chap4__chap3"></a><span class="chapnum">4.c. </span>Wireless Tools</p>
<p class="secthead"><a name="book_part4_chap4__chap3_sect1">Initial setup and Managed Mode</a></p>
<p>
<a href="http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html">Wireless
Tools</a> provide a generic way to configure basic wireless interfaces up to
the WEP security level. While WEP is a weak security method it's also the most
prevalent.
</p>
<p>
Wireless Tools configuration is controlled by a few main variables. The sample
configuration file below should describe all you need. One thing to bear in mind
is that no configuration means "connect to the strongest unencrypted Access
Point" - we will always try and connect you to something.
</p>
<a name="book_part4_chap4__chap3_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.1: Install wireless-tools</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge net-wireless/wireless-tools</span>
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
Although you can store your wireless settings in
<span class="path" dir="ltr">/etc/conf.d/wireless</span> this guide recommends you store them in
<span class="path" dir="ltr">/etc/conf.d/net</span>.
</p></td></tr></table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffffbb"><p class="note"><b>Important: </b>
You <span class="emphasis">will</span> need to consult the <a href="#variable_name">variable name</a> documentation.
</p></td></tr></table>
<a name="book_part4_chap4__chap3_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.2: sample iwconfig setup in /etc/conf.d/net</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment"># Prefer iwconfig over wpa_supplicant</span>
modules="iwconfig"
<span class="code-comment"># Configure WEP keys for Access Points called ESSID1 and ESSID2</span>
<span class="code-comment"># You may configure up to 4 WEP keys, but only 1 can be active at
# any time so we supply a default index of [1] to set key [1] and then
# again afterwards to change the active key to [1]
# We do this incase you define other ESSID's to use WEP keys other than 1
#
# Prefixing the key with s: means it's an ASCII key, otherwise a HEX key
#
# enc open specified open security (most secure)
# enc restricted specified restricted security (least secure)</span>
key_ESSID1="[1] s:yourkeyhere key [1] enc open"
key_ESSID2="[1] aaaa-bbbb-cccc-dd key [1] enc restricted"
<span class="code-comment"># The below only work when we scan for available Access Points</span>
<span class="code-comment"># Sometimes more than one Access Point is visible so we need to
# define a preferred order to connect in</span>
preferred_aps="'ESSID1' 'ESSID2'"
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part4_chap4__chap3_sect2">Fine tune Access Point Selection</a></p>
<p>
You can add some extra options to fine-tune your Access Point selection, but
these are not normally required.
</p>
<p>
You can decide whether we only connect to preferred Access Points or not. By
default if everything configured has failed and we can connect to an unencrypted
Access Point then we will. This can be controlled by the <span class="code" dir="ltr">associate_order</span>
variable. Here's a table of values and how they control this.
</p>
<table class="ntable">
<tr>
<td class="infohead"><b>Value</b></td>
<td class="infohead"><b>Description</b></td>
</tr>
<tr>
<td class="tableinfo"><span class="code" dir="ltr">any</span></td>
<td class="tableinfo">Default behaviour</td>
</tr>
<tr>
<td class="tableinfo"><span class="code" dir="ltr">preferredonly</span></td>
<td class="tableinfo">We will only connect to visible APs in the preferred list</td>
</tr>
<tr>
<td class="tableinfo"><span class="code" dir="ltr">forcepreferred</span></td>
<td class="tableinfo">
We will forceably connect to APs in the preferred order if they are not
found in a scan
</td>
</tr>
<tr>
<td class="tableinfo"><span class="code" dir="ltr">forcepreferredonly</span></td>
<td class="tableinfo">
Do not scan for APs - instead just try to connect to each one in order
</td>
</tr>
<tr>
<td class="tableinfo"><span class="code" dir="ltr">forceany</span></td>
<td class="tableinfo">Same as <span class="code" dir="ltr">forcepreferred</span> + connect to any other available AP</td>
</tr>
</table>
<p>
Finally we have some <span class="code" dir="ltr">blacklist_aps</span> and <span class="code" dir="ltr">unique_ap</span> selection.
<span class="code" dir="ltr">blacklist_aps</span> works in a similar way to <span class="code" dir="ltr">preferred_aps</span>.
<span class="code" dir="ltr">unique_ap</span> is a <span class="code" dir="ltr">yes</span> or <span class="code" dir="ltr">no</span> value that says if a second
wireless interface can connect to the same Access Point as the first interface.
</p>
<a name="book_part4_chap4__chap3_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.3: blacklist_aps and unique_ap example</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment"># Sometimes you never want to connect to certain access points</span>
blacklist_aps="'ESSID3' 'ESSID4'"
<span class="code-comment"># If you have more than one wireless card, you can say if you want
# to allow each card to associate with the same Access Point or not
# Values are "yes" and "no"
# Default is "yes"</span>
unique_ap="yes"
</pre></td></tr>
</table>
<p class="secthead"><a name="book_part4_chap4__chap3_sect3">Ad-Hoc and Master Modes</a></p>
<p>
If you want to set yourself up as an Ad-Hoc node if you fail to connect to any
Access Point in managed mode, you can do that too.
</p>
<a name="book_part4_chap4__chap3_pre4"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.4: fallback to ad-hoc mode</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
adhoc_essid_eth0="This Adhoc Node"
</pre></td></tr>
</table>
<p>
What about connecting to Ad-Hoc networks or running in Master mode to become an
Access Point? Here's a configuration just for that! You may need to specify WEP
keys as shown above.
</p>
<a name="book_part4_chap4__chap3_pre5"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 3.5: sample ad-hoc/master configuration</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment"># Set the mode - can be managed (default), ad-hoc or master
# Not all drivers support all modes</span>
mode_eth0="ad-hoc"
<span class="code-comment"># Set the ESSID of the interface
# In managed mode, this forces the interface to try and connect to the
# specified ESSID and nothing else</span>
essid_eth0="This Adhoc Node"
<span class="code-comment"># We use channel 3 if you don't specify one</span>
channel_eth0="9"
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffffbb"><p class="note"><b>Important: </b>
The below is taken verbatim from the BSD wavelan documentation found at <a href="http://www.netbsd.org/Documentation/network/wavelan.html">the NetBSD
documentation</a>. There are 14 channels possible; We are told that channels
1-11 are legal for North America, channels 1-13 for most of Europe, channels
10-13 for France, and only channel 14 for Japan. If in doubt, please refer to
the documentation that came with your card or access point. Make sure that the
channel you select is the same channel your access point (or the other card in
an ad-hoc network) is on. The default for cards sold in North America and most
of Europe is 3; the default for cards sold in France is 11, and the default for
cards sold in Japan is 14.
</p></td></tr></table>
<p class="secthead"><a name="book_part4_chap4__chap3_sect4">Troubleshooting Wireless Tools</a></p>
<p>
There are some more variables you can use to help get your wireless up and
running due to driver or environment problems. Here's a table of other things
you can try.
</p>
<table class="ntable">
<tr>
<td class="infohead"><b>Variable</b></td>
<td class="infohead"><b>Default Value</b></td>
<td class="infohead"><b>Description</b></td>
</tr>
<tr>
<td class="tableinfo"><span class="code" dir="ltr">iwconfig_eth0</span></td>
<td class="tableinfo"></td>
<td class="tableinfo">See the iwconfig man page for details on what to send <span class="code" dir="ltr">iwconfig</span>
</td>
</tr>
<tr>
<td class="tableinfo"><span class="code" dir="ltr">iwpriv_eth0</span></td>
<td class="tableinfo"></td>
<td class="tableinfo">See the iwpriv man page for details on what to send <span class="code" dir="ltr">iwpriv</span>
</td>
</tr>
<tr>
<td class="tableinfo"><span class="code" dir="ltr">sleep_scan_eth0</span></td>
<td class="tableinfo"><span class="code" dir="ltr">0</span></td>
<td class="tableinfo">
The number of seconds to sleep before attempting to scan. This is needed
when the driver/firmware needs more time to active before it can be used.
</td>
</tr>
<tr>
<td class="tableinfo"><span class="code" dir="ltr">sleep_associate_eth0</span></td>
<td class="tableinfo"><span class="code" dir="ltr">5</span></td>
<td class="tableinfo">
The number of seconds to wait for the interface to associate with the
Access Point before moving onto the next one
</td>
</tr>
<tr>
<td class="tableinfo"><span class="code" dir="ltr">associate_test_eth0</span></td>
<td class="tableinfo"><span class="code" dir="ltr">MAC</span></td>
<td class="tableinfo">
Some drivers do not reset the MAC address associated with an invalid one
when they lose or attempt association. Some drivers do not reset the
quality level when they lose or attempt association. Valid settings are
<span class="code" dir="ltr">MAC</span>, <span class="code" dir="ltr">quality</span> and <span class="code" dir="ltr">all</span>.
</td>
</tr>
<tr>
<td class="tableinfo"><span class="code" dir="ltr">scan_mode_eth0</span></td>
<td class="tableinfo"></td>
<td class="tableinfo">
Some drivers have to scan in ad-hoc mode, so if scanning fails
try setting <span class="code" dir="ltr">ad-hoc</span> here
</td>
</tr>
<tr>
<td class="tableinfo"><span class="code" dir="ltr">iwpriv_scan_pre_eth0</span></td>
<td class="tableinfo"></td>
<td class="tableinfo">
Sends some <span class="code" dir="ltr">iwpriv</span> commands to the interface before scanning.
See the iwpriv man page for more details.
</td>
</tr>
<tr>
<td class="tableinfo"><span class="code" dir="ltr">iwpriv_scan_post_eth0</span></td>
<td class="tableinfo"></td>
<td class="tableinfo">
Sends some <span class="code" dir="ltr">iwpriv</span> commands to the interface after scanning.
See the iwpriv man page for more details.
</td>
</tr>
</table>
<p class="chaphead"><a name="book_part4_chap4__chap4"></a><span class="chapnum">4.d. </span>Defining network configuration per ESSID</p>
<p>
Sometimes, you need a static IP when you connect to <span class="emphasis">ESSID1</span> and you need
DHCP when you connect to <span class="emphasis">ESSID2</span>. In fact, most module variables can be
defined per ESSID. Here's how we do this.
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
These work if you're using WPA Supplicant or Wireless Tools.
</p></td></tr></table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#ffffbb"><p class="note"><b>Important: </b>
You <span class="emphasis">will</span> need to consult the <a href="#variable_name">variable name</a> documentation.
</p></td></tr></table>
<a name="book_part4_chap4__chap4_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 4.1: override network settings per ESSID</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
config_ESSID1="192.168.0.3/24 brd 192.168.0.255"
routes_ESSID1="default via 192.168.0.1"
config_ESSID2="dhcp"
fallback_ESSID2="192.168.3.4/24"
fallback_route_ESSID2="default via 192.168.3.1"
<span class="code-comment"># We can define nameservers and other things too</span>
<span class="code-comment"># NOTE: DHCP will override these unless it's told not to</span>
dns_servers_ESSID1="192.168.0.1 192.168.0.2"
dns_domain_ESSID1="some.domain"
dns_search_domains_ESSID1="search.this.domain search.that.domain"
<span class="code-comment"># You override by the MAC address of the Access Point
# This handy if you goto different locations that have the same ESSID</span>
config_001122334455="dhcp"
dhcpcd_001122334455="-t 10"
dns_servers_001122334455="192.168.0.1 192.168.0.2"
</pre></td></tr>
</table>
<a name="book_part4_chap5"></a><h3>5. Adding Functionality</h3>
<p class="chaphead"><a name="book_part4_chap5__chap1"></a><span class="chapnum">5.a. </span>Standard function hooks</p>
<p>
Four functions can be defined in <span class="path" dir="ltr">/etc/conf.d/net</span> which will be
called surrounding the <span class="code" dir="ltr">start</span>/<span class="code" dir="ltr">stop</span> operations. The functions are
called with the interface name first so that one function can control multiple
adapters.
</p>
<p>
The return values for the <span class="code" dir="ltr">preup()</span> and <span class="code" dir="ltr">predown()</span> functions should
be 0 (success) to indicate that configuration or deconfiguration of the
interface can continue. If <span class="code" dir="ltr">preup()</span> returns a non-zero value, then
interface configuration will be aborted. If <span class="code" dir="ltr">predown()</span> returns a non-zero
value, then the interface will not be allowed to continue deconfiguration.
</p>
<p>
The return values for the <span class="code" dir="ltr">postup()</span> and <span class="code" dir="ltr">postdown()</span> functions are
ignored since there's nothing to do if they indicate failure.
</p>
<p>
<span class="code" dir="ltr">${IFACE}</span> is set to the interface being brought up/down. <span class="code" dir="ltr">${IFVAR}</span>
is <span class="code" dir="ltr">${IFACE}</span> converted to variable name bash allows.
</p>
<a name="book_part4_chap5__chap1_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 1.1: pre/post up/down function examples in /etc/conf.d/net</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
preup() {
<span class="code-comment"># Test for link on the interface prior to bringing it up. This
# only works on some network adapters and requires the ethtool
# package to be installed.</span>
if ethtool ${IFACE} | grep -q 'Link detected: no'; then
ewarn "No link on ${IFACE}, aborting configuration"
return 1
fi
<span class="code-comment"># Remember to return 0 on success</span>
return 0
}
predown() {
<span class="code-comment"># The default in the script is to test for NFS root and disallow
# downing interfaces in that case. Note that if you specify a
# predown() function you will override that logic. Here it is, in
# case you still want it...</span>
if is_net_fs /; then
eerror "root filesystem is network mounted -- can't stop ${IFACE}"
return 1
fi
<span class="code-comment"># Remember to return 0 on success</span>
return 0
}
postup() {
<span class="code-comment"># This function could be used, for example, to register with a
# dynamic DNS service. Another possibility would be to
# send/receive mail once the interface is brought up.</span>
return 0
}
postdown() {
<span class="code-comment"># This function is mostly here for completeness... I haven't
# thought of anything nifty to do with it yet ;-)</span>
return 0
}
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
For more information on writing your own functions, please read
<span class="path" dir="ltr">/usr/share/doc/netifrc-*/net.example.bz2</span>.
</p></td></tr></table>
<p class="chaphead"><a name="book_part4_chap5__chap2"></a><span class="chapnum">5.b. </span>Wireless Tools function hooks</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
This will not work with WPA Supplicant - but the <span class="code" dir="ltr">${ESSID}</span> and
<span class="code" dir="ltr">${ESSIDVAR}</span> variables are available in the <span class="code" dir="ltr">postup()</span> function.
</p></td></tr></table>
<p>
Two functions can be defined in <span class="path" dir="ltr">/etc/conf.d/net</span> which will be
called surrounding the associate function. The functions are called with the
interface name first so that one function can control multiple adapters.
</p>
<p>
The return values for the <span class="code" dir="ltr">preassociate()</span> function should be 0 (success)
to indicate that configuration or deconfiguration of the interface can continue.
If <span class="code" dir="ltr">preassociate()</span> returns a non-zero value, then interface configuration
will be aborted.
</p>
<p>
The return value for the <span class="code" dir="ltr">postassociate()</span> function is ignored since
there's nothing to do if it indicates failure.
</p>
<p>
<span class="code" dir="ltr">${ESSID}</span> is set to the exact ESSID of the AP you're connecting to.
<span class="code" dir="ltr">${ESSIDVAR}</span> is <span class="code" dir="ltr">${ESSID}</span> converted to a variable name bash allows.
</p>
<a name="book_part4_chap5__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: pre/post association functions in /etc/conf.d/net</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
preassociate() {
<span class="code-comment"># The below adds two configuration variables leap_user_ESSID
# and leap_pass_ESSID. When they are both configured for the ESSID
# being connected to then we run the CISCO LEAP script</span>
local user pass
eval user=\"\$\{leap_user_${ESSIDVAR}\}\"
eval pass=\"\$\{leap_pass_${ESSIDVAR}\}\"
if [[ -n ${user} &amp;&amp; -n ${pass} ]]; then
if [[ ! -x /opt/cisco/bin/leapscript ]]; then
eend "For LEAP support, please emerge net-misc/cisco-aironet-client-utils"
return 1
fi
einfo "Waiting for LEAP Authentication on \"${ESSID//\\\\//}\""
if /opt/cisco/bin/leapscript ${user} ${pass} | grep -q 'Login incorrect'; then
ewarn "Login Failed for ${user}"
return 1
fi
fi
return 0
}
postassociate() {
<span class="code-comment"># This function is mostly here for completeness... I haven't
# thought of anything nifty to do with it yet ;-)</span>
return 0
}
</pre></td></tr>
</table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
<span class="code" dir="ltr">${ESSID}</span> and <span class="code" dir="ltr">${ESSIDVAR}</span> are unavailable in <span class="code" dir="ltr">predown()</span> and
<span class="code" dir="ltr">postdown()</span> functions.
</p></td></tr></table>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
For more information on writing your own functions, please read
<span class="path" dir="ltr">/usr/share/doc/netifrc-*/net.example.bz2</span>.
</p></td></tr></table>
<a name="book_part4_chap6"></a><h3>6. Network Management</h3>
<p class="chaphead"><a name="book_part4_chap6__chap1"></a><span class="chapnum">6.a. </span>Network Management</p>
<p>
If you and your computer are always on the move, you may not always have an
ethernet cable or plugged in or an access point available. Also, you may want
networking to automatically work when an ethernet cable is plugged in or an
access point is found.
</p>
<p>
Here you can find some tools that help you manage this.
</p>
<table class="ncontent" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#bbffbb"><p class="note"><b>Note: </b>
This document only talks about <span class="code" dir="ltr">ifplugd</span>, but there are alternatives such
as <span class="code" dir="ltr">netplug</span>. <span class="code" dir="ltr">netplug</span> is a lightweight alternative to
<span class="code" dir="ltr">ifplugd</span>, but it relies on your kernel network drivers working correctly,
and many drivers do not.
</p></td></tr></table>
<p class="chaphead"><a name="book_part4_chap6__chap2"></a><span class="chapnum">6.b. </span>ifplugd</p>
<p>
<a href="http://0pointer.de/lennart/projects/ifplugd/">ifplugd</a> is a
daemon that starts and stops interfaces when an ethernet cable is inserted or
removed. It can also manage detecting association to Access Points or when new
ones come in range.
</p>
<a name="book_part4_chap6__chap2_pre1"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.1: Installing ifplugd</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge sys-apps/ifplugd</span>
</pre></td></tr>
</table>
<p>
Configuration for ifplugd is fairly straightforward too. The configuration file
is held in <span class="path" dir="ltr">/etc/conf.d/net</span>. Run <span class="code" dir="ltr">man ifplugd</span> for details on
the available variables. Also, see
<span class="path" dir="ltr">/usr/share/doc/netifrc-*/net.example.bz2</span> for more examples.
</p>
<a name="book_part4_chap6__chap2_pre2"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.2: Sample ifplug configuration</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
<span class="code-comment">(Replace eth0 with the interface to be monitored)</span>
ifplugd_eth0="..."
<span class="code-comment">(To monitor a wireless interface)</span>
ifplugd_eth0="--api-mode=wlan"
</pre></td></tr>
</table>
<p>
In addition to managing multiple network connections, you may want to add a tool
that makes it easy to work with multiple DNS servers and configurations. This is
very handy when you receive your IP address via DHCP. Simply emerge
<span class="code" dir="ltr">openresolv</span>.
</p>
<a name="book_part4_chap6__chap2_pre3"></a><table class="ntable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td bgcolor="#7a5ada"><p class="codetitle">Code Listing 2.3: Installing openresolv</p></td></tr>
<tr><td bgcolor="#eeeeff" align="left" dir="ltr"><pre>
# <span class="code-input">emerge openresolv</span>
</pre></td></tr>
</table>
<p>
See <span class="code" dir="ltr">man resolvconf</span> to learn more about its features.
</p>
<p class="copyright">
The contents of this document, unless otherwise expressly stated, are licensed under the <a href="http://creativecommons.org/licenses/by-sa/2.5">CC-BY-SA-2.5</a> license. The <a href="/main/en/name-logo.xml?style=printable"> Gentoo Name and Logo Usage Guidelines </a> apply.
</p>
<!--
<rdf:RDF xmlns="http://web.resource.org/cc/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<license rdf:about="http://creativecommons.org/licenses/by-sa/2.5/">
<permits rdf:resource="http://web.resource.org/cc/Reproduction" />
<permits rdf:resource="http://web.resource.org/cc/Distribution" />
<requires rdf:resource="http://web.resource.org/cc/Notice" />
<requires rdf:resource="http://web.resource.org/cc/Attribution" />
<permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
<requires rdf:resource="http://web.resource.org/cc/ShareAlike" />
</License>
</rdf:RDF>
-->
</body>
</html>