Why Use a Source-Based Distribution?

Nowadays, most Linux distributions provide precompiled packages. This means that the distribution builds the packages in the developer’s machine. While compiling packages is not necessarily an issue in today’s high-bandwidth world, there are a number of problems that should be considered in that distribution model:

Compiled binaries mean that you do not have control over how the program is being compiled and what features are included in the program.Relying on binaries means that you give your full trust to the distribution’s developers that they will not include malicious code in their repositories.

Why Use Gentoo?

The reason is simple: Gentoo is a powerful Linux distribution. It gives you almost unrestricted access and freedom to change and modify the whole system.

Portage, the Heart of Gentoo

Portage is the main component that manages a Gentoo Linux system. It installs, manages and tweaks third-party packages. Further, portage also manages basic system configurations. The main difference that Portage offers is that it allows you to install your packages from its source. While this is possible in other distributions, Portage takes it a step further and makes it the default means of obtaining packages.

Obtaining Gentoo

You can obtain a copy of Gentoo from its website. In there, you can choose the installer from a number of different platforms. Gentoo supports both amd64 and arm64. With the downloaded ISO file, you can then use a USB writing program like balenaEtcher to create your bootable flash drive.

Installing Gentoo Linux

Before we continue installing Gentoo, it is important to note that this process is entirely manual, which means a lot of commands will be executed along the way. As such, it is recommended that you not only consult this guide but also check Gentoo’s official handbook for further guidance during the installation. Stick your flash drive into your computer and boot it up. It will boot you into the Gentoo Installer screen.

Setting Up the Network Connection

To install Gentoo, you need to be connected to the Internet. The installer will connect automatically on a wired connection. From there, run the following command to check whether you are online: If you need to connect to a wireless network, you need to set up wpa_supplicant, which will connect you to your wireless access point. Once done, you have to reload the dhcpcd daemon to start your network connection by running this command:

Partitioning the Hard Disk

Next, you need to format the disk you want to install Gentoo on. Do that easily by using the fdisk command. Fdisk is a simple command-line disk partitioning tool. It allows you to partition your hard disk and set the amount of storage you want for your system. Initialize it by typing: If you are not sure of your existing disk partition structure, check it with the -l flag:

Using fdisk to Partition the Hard Disk

Once inside fdisk, you need to first wipe the disk for any existing partitions. Do that by pressing G in the prompt. With that done, you need to create new partitions in the disk:

The + sign tells fdisk that you want the size to be relative to the first sector you have selected.The size is a number that you specify yourself.The last option tells fdisk whether that size is in GB, MB or KB.

Partitioning for a UEFI Gentoo System

With that done, continue partitioning your disk. This process will largely depend on whether you are using a BIOS or UEFI system. If you are using a modern computer with relatively recent hardware, chances are that you are using a UEFI system. To create a UEFI-compatible disk, you need to first create an “EFI System” partition. This should be the first partition in your disk and around 100-256MB in size. With that done, set the type of that partition to “EFI System” by pressing T. This will tell fdisk that you want to change the type of the partition you just created. From there, it will ask which type you want to set the partition to. Type 1.

Partitioning the Rest of the Disk

The next partition you have to make is the “/boot” partition where the Linux kernel and the bootloader will be saved. Ideally, this partition should be around 500M-1G. In my case, I am setting this partition to 1G. From there, create the SWAP partition: part of your hard disk that your RAM can access to dynamically swap its memory whenever it is running out of space. The general rule for the SWAP size is 1/2 to 2 times the amount of memory that you have in your system. My laptop currently has 8GB of memory installed, so I set my SWAP size to 16GB. Further, to properly set this partition as SWAP, set its type to “19.” Lastly, create the root partition where the rest of the system will be installed. To allocate the rest of the disk, just press Enter in the Last Sector option when creating a new partition. With that done, press P to check the partition table that just created. Press W to save your changes to disk.

Formatting the Disks in Gentoo

The next step is to format your hard disk. First, format the EFI System partition as FAT by using the following command: This will create the FAT filesystem that the EFI system requires to boot. From there, create the filesystem for the “/boot” partition by using the simpler ext2 filesystem. Next, create and enable the SWAP partition to tell Gentoo that this partition can be used for swapping with live memory. To do that, run the following: Lastly, create an ext4 filesystem for the root partition by running the following command:

Downloading the Gentoo Stage 3 Tarball

From there, mount the root partition you just created to the “/mnt/gentoo” directory because the installation will now be done in your machine’s hard disk. Once done, download the Stage 3 tarball from the gentoo.org website by using wget: This tarball contains all the programs you need to have a minimal Linux installation. Unpack it using tar:

Selecting a Download Mirror and Copying DNS Info

Indicate where you want to download your packages for this system by running the mirrorselect command: This will open a TUI program where you can select the closest server location to you. From there, copy the repository file for Gentoo to your “/etc/portage” folder, which is a configuration file that contains the links to how Gentoo will download its packages: Lastly, copy the resolver information from your USB installer to the “/mnt/gentoo” directory to ensure that once you change the root directory to the hard disk, the network will still work. To do that, run this command:

Mounting the Device Files and Chrooting

Begin mounting the special directories from the USB installer to the hard disk to make sure that once you have run chroot, the peripherals you are using still work. The last thing to do in the USB installer is to run the chroot command to move the base root directory from the USB to your hard disk:

Mounting the /boot partition and Updating Gentoo

Mount the “/boot” partition to your Gentoo machine to ensure that when you install the kernel later that it will be saved in the correct place: Once that is done, update your Gentoo repositories to make sure you get the latest packages when you do the first system update: From here, emerge-webrsync will connect to the mirrors that you have selected and download the latest EBUILDS available for Gentoo.

Your First Gentoo System Update

You can now update your system to match the latest EBUILDS by running this emerge command: This will ask emerge to check your Stage 3 packages to the ones that are currently on the Gentoo repository. Emerge will update the packages that it finds to have a more recent version. As such, this process will take a while, as Emerge will fetch and compile each and every package it needs to update.

Time Zone and Locales

Next, you need to set up region-specific information, which includes both your time zone and system locale. To set the time zone to your area, find the closest location to you listed in the “/usr/share/zoneinfo” folder. From there, write it to your “/etc/timezone” file. For example, the closest location to me is “Asia/Manila”: Now set your locale for Gentoo will determine the default system language for the computer. To do this, edit the “/etc/locale.gen” file: From there, add the locale you want Gentoo to use. You can view the full listing of available locales by checking the “/usr/share/i18n/SUPPORTED” file. In my case, I want the system to use a U.S. English locale: Then run locale-gen to recreate your system locale.

Installing the Linux Kernel

There are multiple ways to install the Linux Kernel in Gentoo. Either manually configure all of its features or use a pre-built one from the Gentoo developers. For our purposes, we are opting for the latter. To install the pre-built Linux kernel, install two things – the installkernel package and the kernel itself – by running the following command:

Configuring the fstab

With the kernel installed, populate the fstab file: the file that tells Gentoo on startup which partitions to mount and where. Run this command to edit it: Indicate all of the partitions you created in fdisk. For example, in a UEFI system, your fstab file could look something like this:

Setting Up the Root Password

From there, you want to set the root password for the system, as by default, the Stage 3 tarball sets a random password for the root account. If you do not add a password here, it would be impossible to access it once you reboot. To change the root password, run the following:

Installing Additional Tools

Once done, install additional third-party tools you may need for your Gentoo system. For example, if you want both Ethernet and wireless connectivity, install the following: Further, you can install a system logger if you want to monitor the behavior of your system: You can also install the filesystem utilities for the most common filesystems you might interact with:

Installing the Bootloader

From there, the final step in installing Gentoo is the bootloader, a simple program that sits between the BIOS and the Linux kernel. Its function is to instruct the BIOS to load the kernel, which then bootstraps the operating system. To install the GRUB Bootloader, run the following command: Once installed, run the following commands to properly initialize and configure GRUB: After that, all that is left to do is to unmount the USB installer and reboot the system by running the following: Once the system reboots, you will be greeted by your newly installed Gentoo Linux system. From there, start installing basic software and packages to build your own custom Linux distribution. However, if you are still not sure which desktop environment to install, check out our article on what we think are the best desktop environments on Linux.

1. Is there a way to speed up the compile times in Gentoo?

Yes! You can massively speed up the compile times in Gentoo by adding a few values to your “/etc/portage/make.conf” file. For example, set this value to allow your computer to utilize most of its cores during program compilation:

2. My system did not boot up! It showed GRUB, but after booting up, it is just blank.

This could be due to a number of things. One of the most common reasons is that your fstab file was not properly set up. Fix this by plugging in your USB installer and following the steps that we took to chroot to the hard drive.

3. Xorg doesn’t display fonts; is there something wrong?

This is most likely because Xft was not properly installed. When installing programs, you need to add the “Xft” USE flag in your make.conf so that the programs you compile will use X-compatible fonts. To do that, add the following line to your /etc/portage/make.conf: Image credit: Unsplash