<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE sections SYSTEM "/dtd/book.dtd">

<!-- The content of this document is licensed under the CC-BY-SA license -->
<!-- See http://creativecommons.org/licenses/by-sa/1.0 -->

<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/handbook/2004.3/hb-install-stage.xml,v 1.1 2005/01/04 18:11:21 swift Exp $ -->

<sections>

<version>1.72</version>
<date>2005-01-04</date>

<section>
<title>Installing a Stage Tarball</title>
<subsection>
<title>Setting the Date/Time Right</title>
<body>

<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 <c>date</c>:
</p>

<pre caption="Verifying the date/time">
# <i>date</i>
Fri Oct 29 16:21:18 CEST 2004
</pre>

<p>
If the date/time displayed is wrong, update it using the <c>date
MMDDhhmmYYYY</c> syntax (<b>M</b>onth, <b>D</b>ay, <b>h</b>our, <b>m</b>inute
and <b>Y</b>ear). For instance, to set the date to October 29th, 16:21 in the
year 2004:
</p>

<pre caption="Setting the date/time">
# <i>date 102916212004</i>
</pre>

</body>
</subsection>
<subsection>
<title>Locating the Stage3 File</title>
<body>

<p>
If you have configured networking because you need to download a stage3 file for
your architecture, continue with  <uri link="#download">Alternative: Using a
Stage3 from the Internet</uri>. Otherwise read <uri link="#available">Default:
Using a Stage3 from the LiveCD</uri>.
</p>

</body>
</subsection>
</section>
<section id="available">
<title>Default: Using a Stage from the LiveCD</title>
<subsection>
<title>Extracting the Stage Tarball</title>
<body>

<p>
The stages on the CD reside in the <path>/mnt/cdrom/stages</path> directory. To
see a listing of available stages, use <c>ls</c>:
</p>

<pre caption="List all available stages">
# <i>ls /mnt/cdrom/stages</i>
</pre>

<p>
If the system replies with an error, you may need to mount the CD-ROM first:
</p>

<pre caption="Mounting the CD-ROM">
# <i>ls /mnt/cdrom/stages</i>
ls: /mnt/cdrom/stages: No such file or directory
# <i>mount /dev/cdroms/cdrom0 /mnt/cdrom</i>
# <i>ls /mnt/cdrom/stages</i>
</pre>

<p>
Now go into your Gentoo mountpoint (usually <path>/mnt/gentoo</path>):
</p>

<pre caption="Changing directory to /mnt/gentoo">
# <i>cd /mnt/gentoo</i>
</pre>

<p>
We will now extract the stage tarball of your choice. We will do this with the
GNU <c>tar</c> tool. Make sure you use the same options (<c>-xvjpf</c>)! In the
next example, we extract the stage tarball 
<path>stage3-&lt;subarch&gt;-2004.3.tar.bz2</path>.
Be sure to substitute the tarball filename with your stage.
</p>

<pre caption="Extracting the stage tarball">
# <i>tar -xvjpf /mnt/cdrom/stages/stage3-&lt;subarch&gt;-2004.3.tar.bz2</i>
</pre>

<p>
Now that the stage is installed, continue with <uri
link="#installing_portage">Installing Portage</uri>.
</p>

</body>
</subsection>
</section>
<section id="download">
<title>Alternative: Using a Stage from the Internet</title>
<subsection>
<title>Downloading the Stage Tarball</title>
<body>

<p>
Go to the Gentoo mountpoint at which you mounted your filesystems
(most likely <path>/mnt/gentoo</path>):
</p>

<pre caption="Going to the Gentoo mountpoint">
# <i>cd /mnt/gentoo</i>
</pre>

<p>
Depending on your installation medium, you have a couple of tools available to
download a stage. If you have <c>links2</c> available, then you can immediately
surf to <uri link="/main/en/mirrors.xml">the Gentoo mirrorlist</uri> and 
choose a mirror close to you.
</p>

<p>
If you don't have <c>links2</c> available you should have <c>lynx</c> at your 
disposal. If you need to go through a proxy, export the <c>http_proxy</c> and
<c>ftp_proxy</c> variables:
</p>

<pre caption="Setting proxy information for lynx">
# <i>export http_proxy="http://proxy.server.com:port"</i>
# <i>export ftp_proxy="http://proxy.server.com:port"</i>
</pre>

<p>
We will now assume that you have <c>links2</c> at your disposal.
</p>

<p>
Pick the <path>releases/</path> directory, followed by your architecture (for 
instance <path>x86/</path>) and the Gentoo version (<path>2004.3/</path>) 
to finish up with the <path>stages/</path> directory. There you should see all 
available stage files for your architecture (they might be stored within
subdirectories named to the individual sub architectures). Select one and 
press <c>D</c> to download. When you're finished, press <c>Q</c> to quit the 
browser.
</p>

<pre caption="Surfing to the mirror listing with links2">
# <i>links2 http://www.gentoo.org/main/en/mirrors.xml</i>

<comment>(If you need proxy support with links2:)</comment>
# <i>links2 -http-proxy proxy.server.com:8080 http://www.gentoo.org/main/en/mirrors.xml</i>
</pre>

<p>
If you want to check the integrity of the downloaded stage tarball, use
<c>md5sum</c> and compare the output with the MD5 checksum provided on the
mirror. For instance, to check the validity of the x86 stage tarball:
</p>

<pre caption="Example checking integrity of a stage tarball">
# <i>md5sum -c stage1-x86-2004.3.tar.bz2.md5</i>
stage1-x86-2004.3.tar.bz2: OK
</pre>

</body>
</subsection>
<subsection>
<title>Unpacking the Stage Tarball</title>
<body>

<p>
Now unpack your downloaded stage onto your system. We use GNU's <c>tar</c> to
proceed as it is the easiest method:
</p>

<pre caption="Unpacking the stage">
# <i>tar -xvjpf stage?-*.tar.bz2</i>
</pre>

<p>
Make sure that you use the same options (<c>-xvjpf</c>). The <c>x</c> stands for
<e>Extract</e>, the <c>v</c> for <e>Verbose</e> (okay, yes, this is optional),
the <c>j</c> for <e>Decompress with bzip2</e>, the <c>p</c> for <e>Preserve
permissions</e> and the <c>f</c> to denote that we want to extract a file, not
standard input.
</p>

<p>
Now that the stage is installed, continue with <uri
link="#installing_portage">Installing Portage</uri>.
</p>

</body>
</subsection>
</section>
<section id="installing_portage">
<title>Installing Portage</title>
<subsection>
<title>Unpacking a Portage Snapshot</title>
<body>

<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>

</body>
</subsection>
<subsection id="installing_from_LiveCD">
<title>Unpack the Snapshot from the LiveCD</title>
<body>

<p>
To install the snapshot, take a look inside <path>/mnt/cdrom/snapshots/</path> 
to see what snapshot is available:
</p>

<pre caption="Checking the /mnt/cdrom/snapshots content">
# <i>ls /mnt/cdrom/snapshots</i>
</pre>

<p>
Now extract the snapshot using the following construct. Again, make sure you
use the correct options with <c>tar</c>. Also, the <c>-C</c> is with a capital
<c>C</c>, not <c>c</c>. In the next example we use
<path>portage-20041022.tar.bz2</path> as the snapshot filename. Be sure to
substitute with the name of the snapshot that is on your LiveCD.
</p>

<pre caption="Extracting a Portage snapshot">
# <i>tar -xvjf /mnt/cdrom/snapshots/portage-20041022.tar.bz2 -C /mnt/gentoo/usr</i>
</pre>

</body>
</subsection>
<subsection id="copysources">
<title>Copy Source Code Archives</title>
<body>

<p>
You also need to copy over all source code from the Universal LiveCD. 
</p>

<pre caption="Copy over source code">
# <i>mkdir /mnt/gentoo/usr/portage/distfiles</i>
# <i>cp /mnt/cdrom/distfiles/* /mnt/gentoo/usr/portage/distfiles/</i>
</pre>

</body>
</subsection>
</section>
<section id="compile_options">
<title>Configuring the Compile Options</title>
<subsection>
<title>Introduction</title>
<body>

<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
<c>export</c>) but that isn't permanent. To keep your settings, Portage provides
you with <path>/etc/make.conf</path>, a configuration file for Portage. It is
this file we will edit now. 
</p>

<note>
A commented listing of all possible variables can be found in
<path>/mnt/gentoo/etc/make.conf.example</path>. For a successful Gentoo 
installation you'll only need to set the variables which are mentioned beneath.
</note>

<p>
Fire up your favorite editor (in this guide we use <c>nano</c>) so we can alter
the optimization variables we will discuss hereafter. 
</p>

<pre caption="Opening /etc/make.conf">
# <i>nano -w /mnt/gentoo/etc/make.conf</i>
</pre>

<p>
As you probably noticed, the <path>make.conf.example</path> file is
structured in a generic way: commented lines start with "#", other lines define
variables using the <c>VARIABLE="content"</c> syntax. The <path>make.conf</path>
file uses the same syntax. Several of those variables are discussed next. 
</p>

<warn>
Do not make any modifications to the USE variable if you are performing a stage3
with GRP installation. You can alter the USE variable after having installed the
packages you want. Gremlins are known to attack your system if you ignore this
warning!
</warn>

</body>
</subsection>
<subsection>
<title>CHOST</title>
<body>

<warn>
Although it might be tempting for non-stage1 users, they should <e>not</e>
change the <c>CHOST</c> setting in <path>make.conf</path>. Doing so might render
their system unusable. Again: only change this variable if you use a
<e>stage1</e> installation.
</warn>

<p>
The <c>CHOST</c> variable defines what architecture <c>gcc</c> has to
compile programs for. The possibilities are:
</p>

<table>
<tr>
  <th>Architecture</th>
  <th>Subarchitecture</th>
  <th>CHOST Setting</th>
</tr>
<tr>
  <ti>x86</ti>
  <ti>i386</ti>
  <ti>i386-pc-linux-gnu</ti>
</tr>
<tr>
  <ti>x86</ti>
  <ti>i486</ti>
  <ti>i486-pc-linux-gnu</ti>
</tr>
<tr>
  <ti>x86</ti>
  <ti>i586</ti>
  <ti>i586-pc-linux-gnu</ti>
</tr>
<tr>
  <ti>x86</ti>
  <ti>i686 and above (incl. athlon)</ti>
  <ti>i686-pc-linux-gnu</ti>
</tr>
<tr>
  <ti>alpha</ti>
  <ti></ti>
  <ti>alpha-unknown-linux-gnu</ti>
</tr>
<tr>
  <ti>ppc</ti>
  <ti></ti>
  <ti>powerpc-unknown-linux-gnu</ti>
</tr>
<tr>
  <ti>ppc64</ti>
  <ti></ti>
  <ti>powerpc64-unknown-linux-gnu</ti>
</tr>
<tr>
  <ti>sparc</ti>
  <ti></ti>
  <ti>sparc-unknown-linux-gnu</ti>
</tr>
<tr>
  <ti>sparc64</ti>
  <ti></ti>
  <ti>sparc-unknown-linux-gnu</ti>
</tr>
<tr>
  <ti>hppa</ti>
  <ti>(generic)</ti>
  <ti>hppa-unknown-linux-gnu</ti>
</tr>
<tr>
  <ti>hppa</ti>
  <ti>pa7000</ti>
  <ti>hppa1.1-unknown-linux-gnu</ti>
</tr>
<tr>
  <ti>hppa</ti>
  <ti>pa8000 and above</ti>
  <ti>hppa2.0-unknown-linux-gnu</ti>
</tr>
<tr>
  <ti>mips</ti>
  <ti></ti>
  <ti>mips-unknown-linux-gnu</ti>
</tr>
<tr>
  <ti>amd64</ti>
  <ti></ti>
  <ti>x86_64-pc-linux-gnu</ti>
</tr>
</table>

<p>
Please, make sure that you use the <e>correct</e> CHOST setting. For instance,
the CHOST setting for sparc64 still is <c>sparc-unknown-linux-gnu</c> and
<e>not</e> <c>sparc64-unknown-linux-gnu</c>!
</p>

</body>
</subsection>
<subsection>
<title>CFLAGS and CXXFLAGS</title>
<body>

<p>
The <c>CFLAGS</c> and <c>CXXFLAGS</c> variables define the optimization flags 
for the <c>gcc</c> 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 <path>make.conf</path> you should define the optimization flags you think
will make your system the most responsive <e>generally</e>. 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 <uri link="http://gcc.gnu.org/onlinedocs/">GNU
Online Manual(s)</uri> or the <c>gcc</c> info page (<c>info gcc</c> -- only
works on a working Linux system). The <path>make.conf.example</path> file 
itself also contains lots of examples and information; don't forget to read it 
too. 
</p>

<p>
A first setting is the <c>-march=</c> flag, which specifies the name of the
target architecture. Possible options are described in the
<path>make.conf.example</path> file (as comments). For instance, for the x86 
Athlon XP architecture:
</p>

<pre caption="The GCC march setting">
<comment># AMD64 users who want to use a native 64 bit system should not use athlon-xp</comment>
-march=athlon-xp
</pre>

<p>
A second one is the <c>-O</c> flag (that is a capital O, not a zero),
which specifies the <c>gcc</c> optimization
class flag. Possible classes are <c>s</c> (for size-optimized),
<c>0</c> (zero - for no optimizations), <c>1</c>, <c>2</c> or <c>3</c> for more
speed-optimization flags (every class has the same flags as the one before, plus
some extras). For instance, for a class-2 optimization:
</p>

<pre caption="The GCC O setting">
-O2
</pre>

<p>
Another popular optimization flag is <c>-pipe</c> (use pipes rather than
temporary files for communication between the various stages of compilation).
</p>

<p>
Mind you that using <c>-fomit-frame-pointer</c> (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 <c>CFLAGS</c> and <c>CXXFLAGS</c>, you should combine
several optimization flags, like in the following example:
</p>

<pre caption="Defining the CFLAGS and CXXFLAGS variable">
CFLAGS="-march=athlon-xp -pipe -O2"   <comment># AMD64 users should not use athlon-xp</comment>
CXXFLAGS="${CFLAGS}"                  <comment># Use the same settings for both variables</comment>
</pre>

</body>
</subsection>
<subsection>
<title>MAKEOPTS</title>
<body>

<p>
With <c>MAKEOPTS</c> you define how many parallel compilations should occur when
you install a package. A good choice is the number of CPUs in your system plus 
one, but this guideline isn't always perfect.
</p>

<pre caption="MAKEOPTS for a regular, 1-CPU system">
MAKEOPTS="-j2"
</pre>

</body>
</subsection>
<subsection>
<title>Ready, Set, Go!</title>
<body>

<p>
Update your <path>/mnt/gentoo/etc/make.conf</path> to your own preference and
save (<c>nano</c> users would hit <c>Ctrl-X</c>). You are now ready to continue
with <uri link="?part=1&amp;chap=6">Chrooting into the Gentoo Base System</uri>.
</p>

</body>
</subsection>
</section>
</sections>
