Jannah Theme License is not validated, Go to the theme options page to validate the license, You need a single license for each domain name.
ألعاب

What Is Gentoo Linux and How to Install It


Gentoo Linux is a powerful and extensible distribution that stuck to the original source-based package management. Further, its package manager, portage, is a powerful utility that allows you to fine-tune and tweak each distribution aspect. However, it is not a distribution that is easy to install and use. Here we show you how to install Gentoo Linux to enjoy its numerous benefits.

What is Gentoo Linux?

At its core, Gentoo Linux is a highly modular Linux distribution that gives you the power to create custom Linux machines for any purpose. Unlike other distributions, it does this by providing the tools to compile and modify every installable package in the system.

One of the biggest advantages of this approach is that it removes the middleman between you and your system packages. You are not bound to a specific package manager and app format. With the source code, you can compile your own packages and customize them to suit your needs.

Obtaining Gentoo

You can obtain a copy of Gentoo from its website. You can choose the installer for different platforms. Gentoo supports both amd64 and arm64 among other legacy architectures.

With the downloaded ISO file, you can then use a USB writing program such as balenaEtcher and dd 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.

Good to know: Learn how you can test drive a Linux distro from inside your browser.

Step 1: 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. Check whether you are currently online by running the following command:

ping -c 5 maketecheasier.com
A terminal showing the ping command for MakeTechEasier.com.

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.

wpa_passphrase 'Your_SSID_Here' 'Your_Password_Here' >> /etc/wpa_supplicant/wpa_supplicant.conf

Reload the dhcpcd daemon to start your wireless network connection:

rc-service dhcpcd restart

Step 2: Creating the EFI Disk Partition

Format the disk you want to install Gentoo on. Do that by using the fdisk command followed by the device file of your computer’s disk:

A terminal showing the fdisk command for the /dev/vda device.

If you are not sure of your existing disk partition structure, check it with the -l flag:

Once inside fdisk, press G to wipe the disk for any existing partitions.

A terminal showing the process of wiping a disk partition table.

Press N to tell fdisk that you want to create a new partition. Fdisk will ask you for the partition number you want to use. Press Enter to use the default.

A terminal showing the creation of the first partition.

Type “+100M” on the “Last sector” prompt, then press Enter.

A terminal showing the process of setting the size of the first partition.

Change the type of your first partition by pressing T. This will tell fdisk that you want to change the type of the partition you just created. From there, set this partition to “EFI System” by typing 1, then pressing Enter.

A terminal showing the process of setting the type of the first partition.

Step 3: 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. Press N, then Enter to create your system’s second partition.

Type “2”, then press Enter to tell Fdisk that you are editing the second partition for the current disk.

A terminal showing the creation of the second partition.

Press Enter to accept the default first sector value for the partition, then type “+1G”, then press Enter to set the partition size to 1 GB.

A terminal showing the process of setting the size of the second partition.

Press N again, then type “3” to create the third partition of your hard disk. This will serve as your machine’s swap partition which can dynamically swap its memory whenever it is running out of space.

Press Enter to set the default first sector value, then type “+4G”, then press Enter to set the swap partition size to 4 GB.

A terminal showing the process of setting the size for the third partition.

Note: The general rule for swap size is between 1/2 to 2 times the amount of physical memory in your computer. This means that you if you have a 16 GB system, you can set your swap between 8 to 32 GB.

Press T, then type “3” to change the type of the third partition.

Type “19” to properly set this partition as swap, then press Enter.

A terminal showing the process of setting the type of the third partition.

Create the root partition where the rest of the system will be installed. Press N again, then type “4” to set the fourth partition on the disk.

Press Enter on both first sector and last sector prompts to allocate the rest of the disk to your root partition.

A terminal showing the process of setting the size for the fourth partition.

Press P to check whether the partition table layout that you made is correct.

A terminal showing the new partition table layout for Gentoo Linux.

Press W to confirm and write your new partition table to disk.

Step 4: Formatting the Disks in Gentoo

Format the EFI System partition as FAT by using the following command:

Create the filesystem for the “/boot” partition by using the simpler ext2 filesystem.

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:

mkswap /dev/sda3
swapon /dev/sda3

Create an ext4 filesystem for the root partition by running the following command:

Step 5: Downloading the Gentoo Stage 3 Tarball

Mount the root partition that you just made to the “/mnt/gentoo” directory because the installation will now be done in your machine’s hard disk.

mount /dev/sda4 /mnt/gentoo && cd /mnt/gentoo

Download the Stage 3 tarball from the gentoo.org website using wget:

wget https://distfiles.gentoo.org/releases/amd64/autobuilds/20231112T170154Z/stage3-amd64-desktop-openrc-20231112T170154Z.tar.xz
A terminal showing the download process for the Gentoo Linux Stage 3 tarball.

Once that is done, unpack it in your “/mnt/gentoo” directory using tar:

tar xpvf ./stage3-amd64-desktop-openrc-20231112T170154Z.tar.xz --xattrs-include='*.*' --numeric-owner

Step 6: Selecting a Download Mirror and Copying DNS Info

Indicate where you want to download your packages for this system by running the mirrorselect command:

mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf

This will open a TUI program where you can select the closest server location to you.

A terminal showing the available download mirrors for Gentoo Linux.

Copy the default repository file for Gentoo to your “/etc/portage” folder. This is a configuration file that tell Portage how to download its packages:

mkdir -p /mnt/gentoo/etc/portage/repos.conf && 
      cp /mnt/gentoo/usr/share/portage/config/repos.conf 
         /mnt/gentoo/etc/portage/repos.conf/gentoo.conf

Copy the resolver information from your USB installer to the “/mnt/gentoo” directory:

cp --dereference /etc/resolv.conf /mnt/gentoo/etc/

Step 7: Mounting the Device Files and Chrooting

Mount the special directories from the USB installer to your hard disk:

mount --types proc /proc /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --make-rslave /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
mount --make-rslave /mnt/gentoo/dev
mount --bind /run /mnt/gentoo/run
mount --make-slave /mnt/gentoo/run

Change the root of your current shell session from the Live ISO to the “/mnt/gentoo” directory:

chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="[chroot] ${PS1}"

Step 8: 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:

mount /dev/sda2 /boot
mkdir /boot/efi
mount /dev/sda1 /boot/efi

Update your Gentoo repositories to make sure you get the latest packages when you do the first system update:

Update and install all the base EBUILDS for your system by running this emerge command:

emerge --ask --verbose --update --deep --newuse @world

Step 9: Time Zone and Locales

Once that is done, set up your system’s 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.

Write the path to the folder and zonefile to your “/etc/timezone” file. For example, the closest location to me is “Asia/Manila”:

echo "Asia/Manila" > /etc/timezone
emerge --config sys-libs/timezone-data
A terminal showing the process of setting the system timezone.

Open the “locale.gen” file with your favorite text editor:

Remove the pound sign (#) in front of the first two lines in the locale.gen file.

A terminal showing the process of setting the system locale.

Note: You can view the full listing of available locales by running the following: cat /usr/share/i18n/SUPPORTED.

Apply your new locale settings by running the locale-gen program.

Step 10: Installing the Linux Kernel and Configuring the fstab

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 start, install the installkernel package and the kernel itself:

emerge --ask sys-kernel/installkernel-gentoo sys-kernel/gentoo-kernel-bin

Good to know: Learn how you can downgrade your Linux kernel in Ubuntu.

With the kernel installed, open the fstab file with your favorite text editor:

Indicate all of the partitions you created in fdisk. For example, in a UEFI system, your fstab file could look something like this:

[...]
 
/dev/sda1    /boot/efi    vfat    defaults    0    2
/dev/sda2    /boot    ext2    defaults,noatime    0    2
/dev/sda3    none    swap    sw    0    0
/dev/sda4    /    ext4    noatime    0    1
A terminal showing a simple fstab partition layout.

Step 11: Setting Up the Root Password and Installing Additional Tools

Create a root password for your system. This will ensure that you can still access your system after the installation process:

A terminal showing the process of setting a new root password.

Install additional network support tools for your Gentoo system. For example, if you want both Ethernet and wireless connectivity, install the following:

emerge --ask net-misc/dhcpcd net-wireless/iw net-wireless/wpa_supplicant
rc-update add dhcpcd default

Once done, also install a system logger if you want to monitor the behavior of your system:

emerge --ask app-admin/sysklogd
rc-update add sysklogd default

Lastly, install the filesystem utilities for the most common filesystems you will interact with:

emerge --ask sys-fs/dosfstools sys-fs/ntfs3g

Step 12: Installing the Bootloader

The final step in installing Gentoo is the bootloader. This is a small program that loads immediately after your machine’s BIOS and prepares to load the OS’ kernel.

To install the GRUB Bootloader, run the following command:

emerge --ask sys-boot/grub
A terminal showing the process of obtaining the Grub bootloader.

Once installed, run the following commands to properly initialize and configure GRUB:

grub-install --target=x86_64-efi --efi-directory=/boot/efi
grub-mkconfig -o /boot/grub/grub.cfg

Unmount the USB installer and reboot the system by running the following:

exit
cd
umount -l /mnt/gentoo/dev{/shm,/pts,}
umount -R /mnt/gentoo
reboot

Installing Gentoo Linux is just the first step in understanding how your Linux distribution works under the hood. Learn how you can further optimize your system by speeding up compile times in Gentoo.

However, if you are still not sure which desktop environment to install, check out what we think are the best desktop environments on Linux.

Image credit: Dell via Unsplash (Background) and Wikimedia Commons (Logo). All alterations and screenshots by Ramces Red.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Ramces Red

Ramces is a technology writer that lived with computers all his life. A prolific reader and a student of Anthropology, he is an eccentric character that writes articles about Linux and anything *nix.

اترك تعليقاً

لن يتم نشر عنوان بريدك الإلكتروني. الحقول الإلزامية مشار إليها بـ *

زر الذهاب إلى الأعلى