A Beginner’s Guide To Install Gentoo

Gentoo, a distribution of choice for nerds.

Well at least this is what many people think of Gentoo. This distribution is no doubt hard to install and maintain. And to add to the pain, here comes compilation. One have to compile the distribution as well as most of the softwares from source code.

But it is worth the pain as one can get a system fully optimized for the specific hardware he/she has.

Following is a tutorial that would help beginners to install Gentoo for the first time.

Note: When I say “A Beginner to Gentoo”, I literally mean a beginner to Gentoo and not a beginner to Gnu/Linux.

So, let us begin.


1. Any live Gnu/Linux distribution with adequate network connection.
2. The Gentoo stage3 tarball.
3. A lot of patience and some coke.

Step 1 : Boot form Live CD/DVD

Boot from the live distribution you have. Just remember to use a 64bit live CD/DVD if you want to do a 64bit Gentoo install.
To install a 32bit Gentoo system you can use either one of a 32bit or a 64bit Live CD or DVD, but if you choose to go with a 64bit one, in this case it must be able to run 32bit binary as well.

After booting to the live system you must get connected to the Internet.

Step 2 : Setting up Partitions

Now we need a valid partition table on the Hard Drive or SSD that we are using to install Gentoo. We are free to choose any of the utilities available on our live system. I choose cfdisk. You can go with gparted or any other utility you like.

For this tutorial I have the following partitioning scheme.

/dev/sda1 → to be used as /
/dev/sda2 → to be used as /home
/dev/sda3 → to be used as swap

Just create the partitions and you are ready to go, no need to format or worry about mount points at this moment.

Step 3 : Formatting

We shall be formatting sda1 and sda2 with the ext4 filesystem.
At this moment fire up a terminal and do the following. Remember you need to have root access for this.

# mkfs.ext4 /dev/sda1
# mkfs.ext4 /dev/sda2
# mkswap /dev/sda3

Step 4 : Mounting

At this time we only need to mount sda1.

# mkdir /mnt/gentoo
# mount /dev/sda1 /mnt/gentoo

Step 5 : Downloading and Extracting the Tarball

You can download the stage3 tarball from here. Choose your architecture, click on stages and download the latest stage3 tarball.

After downloading the tarball, copy it to /mnt/gentoo and you are ready to extract it.

# cd /mnt/gentoo
# tar xvjpf stage3-*.tar.bz2

Or, If you have the tarball downloaded in the Downloads folder(/home/live/Downloads in this case), you can even extract it to /mnt/gentoo directly from that location and then move to /mnt/gentoo to being with the next step.

# cd /home/live/Downloads
# tar xvjpf stage3-*.tar.bz2 -C /mnt/gentoo
# cd /mnt/gentoo

Step 6 : Copy DNS Info

# cp -L /etc/resolv.conf /mnt/gentoo/etc/

Step 7 : Mounting Filesystems

# mount -t proc none /mnt/gentoo/proc
# mount --rbind /sys /mnt/gentoo/sys
# mount --rbind /dev /mnt/gentoo/dev

Now we are ready to chroot to the newly setup Gentoo system on /mnt/gentoo and begin with installing a kernel and setting up the necessary config files.

Step 8 : Chrooting

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

Step 9 : Edit make.conf

This is one of the most crucial stages of installing Gentoo. Now we must edit /etc/portage/make.conf.

# nano /etc/portage/make.conf

Create your make.conf from the example bellow:

# *** CFLAGS and CXXFLAGS ***
# CFLAGS and CXXFLAGS variables define the optimization flags for gcc C and C++ compiler.
# See https://wiki.gentoo.org/wiki/GCC_optimization for more information.
 CFLAGS="-O2 -pipe -march=native"
# *** CHOST ***
# WARNING: Changing your CHOST is not something that should be done lightly.
# Please consult http://www.gentoo.org/doc/en/change-chost.xml before changing.
# for 64bit Intel PCs
# for 32bit Intel PCs
# CHOST="i686-pc-linux-gnu"
# *** USE flags ***
# These are the USE flags that were used in addition to what is provided by the
# profile used for building.
# See official Gentoo docs for more information.
 USE="bindist mmx sse sse2 udev branding dbus startup-notification"
# *** MAKEOPTS ***
# With MAKEOPTS 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.

Step 10 : Configuring Portage

Now we have to install a protage snapshot, a collection of files that informs portage what softwares you can install.

# emerge-webrsync

You can now update the portage tree to the latest version.

# emerge --sync

If you are warned about a new portage version is available you should update it now by using,

# emerge --oneshot portage


Here you can encounter some error while compiling python. Just put the following in your make.conf and recompile the python packages that failed:


When you are done compiling python packages do not forget to remove or comment out this portion from make.conf.

Step 11 : Choosing the Profile

Now you should choose a profile for your system.

You can list the available profiles:

# eselect profile list
Available profile symlink targets:
[1] default/linux/amd64/13.0
[2] default/linux/amd64/13.0/selinux
[3] default/linux/amd64/13.0/desktop
[4] default/linux/amd64/13.0/desktop/gnome
[5] default/linux/amd64/13.0/desktop/kde
[6] default/linux/amd64/13.0/developer
[7] default/linux/amd64/13.0/no-multilib
[8] default/linux/amd64/13.0/x32
[9] hardened/linux/amd64
[10] hardened/linux/amd64/selinux
[11] hardened/linux/amd64/no-multilib
[12] hardened/linux/amd64/no-multilib/selinux
[13] hardened/linux/amd64/x32
[14] hardened/linux/uclibc/amd64

I recommend beginners to use the desktop profile if you want to stay minimal. If you would like to install KDE or Gnome later do not hesitate to choose the kde or gnome profiles respectively.

To set the desktop profile:

# eselect profile set 3

Setting proper profiles shall set appropriate USE flags for you.

Step 12 : Setting up the Timezone

List all available timezones:

# ls /usr/share/zoneinfo

Suppose you want to use Asia/Kolkata:

# cp /usr/share/zoneinfo/Asia/Kolkata /etc/localtime
# echo "Asia/Kolkata" > /etc/timezone

Step 13 : Choosing and Compiling Kernel

Gentoo provide several kernel sources. Please read http://www.gentoo.org/doc/en/gentoo-kernel.xml for more information.

We are going to use the gentoo-sources.

# emerge gentoo-sources

It would automatically create a symbolic link /usr/src/linux pointing to you kernel source directory in /usr/src.

# cd /usr/src/linux

Now you can manually configure the kernel by running:

# make menuconfig

When done with configuring save the settings and exit. Now, compile the kernel:

# make -j5 && make modules_install

(-j5 because I have 4 cores in my processor. It is number of CPU+1, so if u have a dual core machine use -j3)

Copy the compiled image to /boot.

# cp arch/x86_64/boot/bzImage /boot/kernel-my_kernel_version-gentoo

NOTE: The folder x86_64 exists on an Intel 64bit machine. Just use ‘ls arch/’ (without the quotes) to see the folder name.

Now, if you wish(it is most likely that you need it) to install an initramfs:

# emerge genkernel
# genkernel --install initramfs

Or, you can use genkernel to compile the kernel for you:

# emerge genkernel
# genkernel all

Finally check if you have the kernel image as well as the initramfs installed:

# ls /boot

Step 14 : Setting up the Hostname

You might want to setup a hostname for your system.

# nano /etc/conf.d/hostname

Now set the hostname variable, save and exit.


Step 15 : Setting up the Locale

# nano /etc/locale.gen

Now specify you locale, save and exit. For example:

en_US ISO-8859-1
en_US.UTF-8 UTF-8

Generate locale:

# locale-gen

Setting the default system locale:

# nano /etc/env.d/02locale

Set default locale, save and exit:


Reload environment:

# env-update && source /etc/profile

Step 16 : Creating eth0 Symbolic Link

# cd /etc/init.d
# ln -s net.lo net.eth0

Step 17 : Setup the root Password

# passwd

Step 18 : Install syslog-ng

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

Step 19 : Setting up /etc/fstab

Now we have to setup the mount points for the system.

# nano /etc/fstab

Follow the example and setup your own:

# <dump/pass>
/dev/sda1 / ext4 noatime 0 1
/dev/sda2 /home ext4 noatime 0 1
/dev/sda3 none swap sw 0 0

Step 20 : Install Bootloader

If you wish to install Grub 2:

# echo "sys-boot/grub:2" >> /etc/portage/package.accept_keywords
# echo "emu gentoo_platforms_efi-32 gentoo_platforms_efi-64 pc" >> /etc/portage/make.conf
# emerge -av sys-boot/grub:2
# emerge os-prober

Create and edit configuration:

# grub2-mkconfig -o /boot/grub2/grub.cfg
# nano /boot/grub2/grub.cfg

And check if everything is ok. You might need to add the initrd in you grub configuration after the kernel line. See, http://wiki.gentoo.org/wiki/GRUB2 for more information.

Finally install grub2 on MBR:

# grub2-install /dev/sda

Step 21 : Unmount and Reboot

All set now you can unmount and reboot to the newly installed Gentoo system.

# exit
# cd ~
# umount -l /mnt/gentoo/{sys,dev,proc}
# umount /mnt/gentoo
# reboot

You can also see the official install guide form gentoo.org.