Chapter 15. Installing Gentoo Linux

Table of Contents

System Requirements
Booting a Linux Environment
Disk Setup
Installing Gentoo Base
Configuring the System
Preparing the Installation Environment
Configuring Portage
Configuring the Linux Kernel
Configuring the System
Installing System Tools
Configuring the Boot Loader
Finishing Up


I've waited a few chapters before I started discussing the Gentoo Linux installation because it isn't for the faint of heart. Although Gentoo has tried to offer a graphical installer in the past, its user- and developer base swore by the manual installation approach. As a result, the graphical installer has been deprecated and the installation procedure is once more a manual, step by step guide.

With the previous chapters discussed, you should now be able to install a Gentoo Linux yourself with the following simple set of instructions. However, if you want to do it the official way, do not hesitate to read the Gentoo Handbook. There are also handbooks available for other architectures.

System Requirements

Gentoo Linux can be as heavy as you want, or as small as you want. Yet unless you deviate from the documented approach, Gentoo Linux remains a source-based distribution. Because of that, it has a slightly higher disk space requirement than other distributions. A minimal (base) Gentoo Linux installation takes a little less than 2 Gbyte of diskspace (including Linux kernel source code and the Gentoo Portage tree, which take about 640 Mbyte in total). But with 2 Gbyte, you don't have room for much more than a base installation.

To have a comfortable installation, yet with room to spare for additional installations, you should consider a total diskspace of at least 20 Gbyte for the applications alone. With current disk sizes, this should not be a problem. If you don't install a full-blown KDE or GNOME, you should have enough with 10 Gbyte or less.

Disk space aside, Gentoo Linux can run and install with almost any system specification. Of course, the lower the specs, the higher the duration of an installation. Installing Gentoo Linux on an i486 with 32 Mbyte of memory is doable (but not recommended).

Booting a Linux Environment

A Gentoo Linux installation starts from a Linux environment. You can use any Linux environment you want, but most people suggest to use a LiveCD.

A popular LiveCD to install Gentoo from is System Rescue CD. All necessary documentation about booting the CD, including setting up networking (which you definitely need to do in order to install Gentoo) is available on the site.

Disk Setup

Once your environment is set up, you'll need to setup your disks by partitioning them and then putting a file system on them. Partitioning and file system management has been discussed beforehand. If you want, assign labels to the file systems to make it easier to create your fstab file later:

# fdisk /dev/sda
(Partition the disk)
# mkfs.ext2 -L BOOT /dev/sda1
# mkfs.ext3 -L ROOT /dev/sda2
# mkfs.ext3 -L HOME /dev/sda3
# mkswap -L SWAP /dev/sda4

Once that your partitions are created and a file system is put on it, it is time to really start the Gentoo Linux installation.

First, mount all the necessary partitions onto your Linux environment. In the rest of this chapter I will assume the partitioning layout as described in the following table:

Table 15.1. Example partition layout

/dev/sda1/bootSmall boot partition to hold the Linux kernel and bootloader information. Can be ext2
/dev/sda2/Root partition; should be fairly large in this example. Suggested is ext3
/dev/sda3/homeHome partition where all users' files are stored. Best to always have a separate partition for the home directories so that future reinstallations can reuse the home structure.
/dev/sda4<none>Swap partition, roughly 1.5 times the amount of physical memory nowadays (still this large because I want to use hibernate-to-disk).

~# mkdir /mnt/gentoo
~# mount /dev/sda2 /mnt/gentoo
~# mkdir /mnt/gentoo/boot
~# mount /dev/sda1 /mnt/gentoo/boot
~# mkdir /mnt/gentoo/home
~# mount /dev/sda3 /mnt/gentoo/home
~# swapon /dev/sda4

With the above commands executed, the various file systems we will use for the Gentoo installation are now available at /mnt/gentoo. Every file or directory we put beneath /mnt/gentoo will show up on our final Gentoo installation. For instance, /mnt/gentoo/boot = /boot.

Installing Gentoo Base

First, set your system time correct so that the files you're going to create do not have a weird time stamp:

~# ntpdate

Next, surf to the Gentoo mirror list and pick a mirror close to you. On most LiveCDs browsers are available. On the sysresccd you can use links or lynx (command-line browsers). Navigate to releases, select your architecture, autobuilds, the latest date directory to find a listing of stage3 files and install files.

~# cd /mnt/gentoo
~# links
  • A stage3 file is an archive of a prebuilt Gentoo environment which we will extract to the installation location (/mnt/gentoo)

  • An install file is an ISO file (CD image) which contains a minimal Gentoo environment from which you can boot and install Gentoo from.

Download the stage3 file and store it in /mnt/gentoo. If you have the full URL at hand, you can also use wget:

# cd /mnt/gentoo
# wget

On many forums, you will find the notion of "funtoo" stages. Funtoo is, to say it in the author's own words (who happens to be Daniel Robbins, the founder of Gentoo Linux), a Gentoo Linux variant which offers freshly-built Gentoo Linux stable stages using Gentoo's official stable branch. You can use a funtoo stage instead of a Gentoo official stage if you want. After all, they both contain roughly the same material. However, some caution is still in place: the Funtoo stages continuously evolve and diverge into their own set so I recommend to take a quick stab at the Funtoo installation instructions nevertheless. At the time of writing, the instructions are quite resembling.

Finally, quit your browser and extract the downloaded files on your installation location.

~# tar xvjpf stage3-*.tar.bz2

Next, edit the /mnt/gentoo/etc/portage/make.conf file. As discussed previously, this file contains variables that define Portage' behaviour. Right now I'm focussing on the variables CFLAGS, CXXFLAGS and MAKEOPTS...

  • CFLAGS (C) and CXXFLAGS (C++) inform gcc (GNU's Compiler Collection) what optimizations it should use (see Compiler Directives)

  • MAKEOPTS defines how many parallel compilations should occur when you install a package (especially useful for multicore / SMP systems). A good choice is the number of core's in your system plus one (for instance, a dual-core CPU would lead to MAKEOPTS="-j3").

You can edit the make.conf file using nano, vim or any other text editor.

Configuring the System

Our next step is to configure the installation environment.

Preparing the Installation Environment

First, prepare the environment for chrooting. Chrooting is the process of altering your sessions' file system root to another location. In our case, /mnt/gentoo should become / for your running session. In order to chroot successfully, we need to ensure that networking will still function properly and that both kernel data and device drivers are available inside the chroot:

~# cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
~# mount -t proc none /mnt/gentoo/proc
~# mount -o bind /dev /mnt/gentoo/dev


Now, chroot into the Gentoo installation environment, update your environment variables and, for safety reasons, change your prompt so that you know you're inside your Gentoo installation environment.

~# chroot /mnt/gentoo /bin/bash
~# env-update
~# source /etc/profile
~# export PS1="(chroot) $PS1"

Right now, this session (where the prompt starts with "(chroot)") is inside your Gentoo installation environment.

Configuring Portage

Now, update the Portage tree to make sure you have the current set of packages at your disposal:

~# mkdir /usr/portage; emerge-webrsync;

Next, select a Gentoo profile for your environment. A Gentoo profile is a collection of default Portage settings. If you want to know what a particular profile selects of default settings, check out its content at /usr/portage/profiles (and don't forget to read up on cascading profiles). Currently, the '13.0' set of profiles is the stable, default one.

~# eselect profile list
~# eselect profile set <number>

Finally, set the USE flags you want in either /etc/portage/make.conf (global USE flags) or /etc/portage/package.use (local USE flags).

~# nano -w /etc/portage/make.conf

For those of you who want to run Gentoo Linux with support for international locales, edit /etc/locale.gen and specify the locales you want to support. An example of locales are given below. Once set, generate the locale files for your system.

~# nano -w /etc/locale.gen
en_US ISO-8859-1
en_US.UTF-8 UTF-8
de_DE ISO-8859-1
de_DE@euro ISO-8859-15

~# locale-gen

If you want to know which locales are supported, view the contents of the /usr/share/i18n/SUPPORTED file:

# less /usr/share/i18n/SUPPORTED

Configuring the Linux Kernel

First select your time zone file from inside /usr/share/zoneinfo and copy it to /etc/localtime. For instance, to use the GMT time zone:

~# cp /usr/share/zoneinfo/GMT /etc/localtime

Next, install the kernel sources. Gentoo profiles a few kernel packages like vanilla-sources (bare Linux kernel as delivered by the kernel developers) and gentoo-sources (vanilla Linux kernel with patches managed by Gentoo developers).

~# emerge gentoo-sources

You will find the kernel sources at /usr/src/linux. Now continue with building the Linux kernel as discussed in Configuring a Kernel.

Configuring the System

There are three blocks of information we need to configure now:

  • file system information (/etc/fstab)

  • networking information

  • system information

To start with the file system information, you need to edit the /etc/fstab file. The structure of this file has been discussed before so this shouldn't be an issue (see The mount command). If you want to use labels instead of device locations, use the LABEL="..." syntax in the first column.

/dev/sda1  /boot    ext2  noauto,noatime    0 0
/dev/sda2  /        ext3  defaults,noatime  0 0
/dev/sda3  /home    ext3  defaults,noatime  0 0
/dev/sda4  none     swap  sw                0 0
none       /dev/shm tmpfs defaults          0 0

Next, configure your network settings. Start by setting the system host name in /etc/conf.d/hostname and then configure the networking settings in /etc/conf.d/net. Finally, add your network interface initialization script to the default run level so that networking is automatically started at boot time.

~# nano -w /etc/conf.d/hostname
~# nano -w /etc/conf.d/net
~# rc-update add net.eth0 default

Also edit your /etc/hosts file to include the IP addresses and host names of other systems you might need. Also add your host name to the entry in /etc/hosts.

~# nano -w /etc/hosts

Now, set your root password

~# passwd

Next, edit /etc/rc.conf which contains your general system configuration settings:

~# nano -w /etc/rc.conf

Next, edit /etc/conf.d/keymaps to set your system-wide keyboard layout settings:

~# nano -w /etc/conf.d/keymaps

Finally, edit /etc/conf.d/clock to set the clock options:

~# nano -w /etc/conf.d/clock

Installing System Tools

Install a system logger, like syslog-ng:

~# emerge syslog-ng
~# rc-update add syslog-ng default

Install a system scheduler (cron daemon), like vixie-cron:

~# emerge vixie-cron
~# rc-update add vixie-cron default

Install the file system tools for the file systems you use:

~# emerge xfsprogs
~# emerge reiserfsprogs
~# emerge jfsutils
~# emerge btrfs-progs

Install the necessary networking tools, like a DHCP client:

~# emerge dhcpcd

Configuring the Boot Loader

Now, we install the GRUB boot loader:

~# emerge grub:2

Once installed, edit the grub configuration file (/etc/default/grub). Finally, install GRUB on the master boot record:

~# grub-install /dev/sda
~# grub-mkconfig -o /boot/grub/grub.cfg

Finishing Up

Now that everything is installed, reboot your system by exiting the chroot, umounting all mounted file systems and reboot:

~# exit
~# cd
~# umount /mnt/gentoo/boot /mnt/gentoo/dev /mnt/gentoo/proc
~# umount /mnt/gentoo/home /mnt/gentoo
~# reboot

Once rebooted (and hopefully inside your Gentoo Linux environment), log in as root and create a user for daily use:

~# useradd -m -G users,wheel,audio -s /bin/bash yournick
~# passwd yournick

And to remove the traces from the installation, remove the downloaded tarballs from your / file system:

~# rm /stage3-*.tar.bz2
~# rm /portage-*.tar.bz2