"# Gentoo x86 Linux Installation"

Published: Fri 09 November 2018

In content.

Gentoo x86 Linux Installation

This article will guide you on installing Gentoo GNU/Linux for x86 system. This guide was written based on official documentation available here. At the end of this guide, you should have working GNU/Linux operating system. For this installation, I have made several assumptions, which you will encounter while installing operating system.

****NOTE**: Certain initial configurations such as network configuration omitted under assumption that default network configuration used. You can choose to refer [official documentation] for more information.

General Note

You can choose to install on a real hardware or virtual machine, choice is yours, while this guide was produced for virtual machine with network adapter bridged to host adapter, so no network configurations needed at this point.

Gentoo has several installation media. To follow this guide, I have downloaded Minimal Installation CD for x86 from here. Later, you would require to download desired Stage 3 archive file to continue installation. More information on Stage 3 archive file can be found here. This guide used Hardened stage 3 - i686 archive file.

Initial Install Configuration


Once you have prepared your machine, loaded Installation CD, you should be prompted with following:

[code lang=text] boot: [/code]

  • Type following and press Enter:
  • gentoo acpi=off nosound nousb nohutplug nofirewire noapic docache scandelay password=password

Default Keymap

You will be prompted to select keymap. Hit Enter or select desired keymap.

Create New User

While it is not necessary to create new user now, you can choose to skip this and continue and create users at the end of installation

To create new user:

  • #useradd <USERNAME>
  • #useradd -m -G wheel <USERNAME>

Sync Network Time

It is assumed that network-provided time and local time be out of sync. In order to sync, type following command: - ntp -q -g

Partition HardDisk

Typical GNU/Linux installation require / & /swap partition to be created. For this article, while referring to official documentation, I am going to create 4 partitions: - grub - bootloader partiton - 2 MiB - boot - boot partition - 128 MiB - swap - swap partition - rule of thumb: swap size = RAM*2 - rootfs - root partiton - rest of hard disk

To list attached hard disk, type: - #fdisk -l

This article is going to use parted to partition the hard disk. Type the following command, you will fall into parted shell: - #parted

Once you fall into parted shell, type following commands: - mklabel gpt - unit mib - mkpart primary 1 3 - name 1 grub - set 1 bios_grub on - mkpart primary 3 131 - name 2 boot - mkpart primary 131 1155 - name 3 swap - mkpart primary 1155 -1 - name 4 rootfs - set 2 boot on - print - quit

Once you have exited parted shell, you can view partitioned hard disk by typing #fdisk -l .

Formart Hard Disk Partition

Most GNU/Linux operating systems use ext2/3/4 filesystem for hard disk partitions. If you have installed Fedora/Ubuntu/Mint, you might find partition scheme slightly different.

Type following command to format /dev/sda2 & /dev/sda4 into ext4 filesystem: - #mkfs.ext4 /dev/sda2 - boot partition - #mkfs.ext4 /dev/sda4 - root partition

Activate Swap partition

To activate swap partition, type following command: - #mkswap /dev/sda3 - #swapon /dev/sda3

Stage 3 installation

Download & Configure

This article uses Hardened stage 3 - i686 archive file to continue with installation. To proceed with installation, type following commands: - #mount /dev/sda4 /mnt/gentoo - #cd /mnt/gentoo - #cd /mnt/gentoo - #wget <HARDENED_STAGE_3_FILE_URL> - #tar xpvf stage3-*.tar.bz2 --xattrs-include='*.*' --numeric-owner - #nano -w /mnt/gentoo/etc/portage/make.conf - to add following lines into the file. To exit, hold CTRL and X keys.


[code lang=text] CFLAGS="-march=native -O1 -pipe CXXFLAGS="${CFLAGS}" MAKEOPTS="-j1" [/code]

Configuring mirrors

Following configuration is optional as per official documentation but you can follow to get rough idea on Portage package manager.

  • #mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf
  • mkdir --parents /mnt/gentoo/etc/portage/repos.conf
  • cp /mnt/gentoo/usr/share/portage/config/repos.conf /mnt/gentoo/etc/portage/repos.conf/gentoo.conf
  • cp --dereference /etc/resolv.conf /mnt/gentoo/etc

Mount proc, sys, dev & boot partitions

To mount the partitions, type following command: - #mount --types proc /proc /mnt/gento/proc - #mount --rbind /sys /mnt/gentoo/sys - #mount --make-rslave /mnt/gentoo/dev - #mount --make-rslave /mnt/gentoo/dev

chroot Into Installation & mount boot partition

  • #chroot /mnt/gentoo /bin/bash
  • #source /etc/profile
  • #export PS1="(chroot) ${PS1}"
  • #mkdir /boot
  • mount /dev/sda2 /boot

Configuring Portage package manager

Following commands will ensure that latest snapshot of ebuild repository installed. - #emerge-webrsync

Choosing profile

According to official documentation, a profile is a building block for any Gentoo GNU/Linux system. This article uses hardened/linux/x86 . You are free to choose any profile you desire. Type following commands to view & select profile: - #eselect profile list - #eselect profile set <PROFILE_NUM>

Update @world set

@world set is a combination of system set & selected set. Type in following command to update @world set: - #emerge --ask --verbose --update --deep --newuse @world

Configure timezone & locale

To get your desired timezone, visit this link and copy. The format will be following: - Asia/Singapore

Type following commands to configure timezone: - #echo 'Asia/Singapore' > /etc/timezone - #emerge --config sys-libs/timezone-data

Locales are languages a system support. Besides that it also specify rules on how strings, numerals are displayed. For this article, I have assumed following locale:

[code lang=text] en_US ISO-8859-1 en_US.UTF-8 UTF-8 [/code]

Type following command and insert above locales into the file. - #nano -w /etc/locale.gen Hit CTRL + X key to save & exit.

Next set of commands will generate locales for the system. - #locale-gen - #locale -a - #eselect locale list - #eselect locale set <NUM> - #echo 'LC_COLLATE="C"'>>/etc/env.d/02locale - #env-update && source /etc/profile && export PS1="(chroot) $PS1"

Configure & Install Kernel

The most interesting part of this article, that is configuring & installing The Kernel. For this article, I will be using emerge to get latest kernel sources from gentoo. Following commands will achieve aforementioned task. - #emerge --ask sys-kernel/gentoo-sources - #cd /usr/src/linux -#make menuconfig

3rd command #make menuconfig will ask for set of options for the kernel. This article used generic + disabling IPv6 support. You can look at here for reference.

[code lang=text] Activating Required Options

Enabling devtmpfs support Device Drivers ---> Generic Driver Options ---> [*] Maintain a devtmpfs filesystem to mount at /dev [ ] Automount devtmpfs at /dev, after the kernel mounted the rootfs

Enabling SCSI disk support Device Drivers ---> SCSI device support ---> <*> SCSI disk support

Selecting necessary file systems File systems ---> <*> Second extended fs support <*> The Extended 3 (ext3) filesystem <*> The Extended 4 (ext4) filesystem <*> Reiserfs support <*> JFS filesystem support <*> XFS filesystem support <*> Btrfs filesystem support DOS/FAT/NT Filesystems ---> <*> MSDOS fs support <*> VFAT (Windows-95) fs support

Pseudo Filesystems ---> [*] /proc file system support [*] Tmpfs virtual memory file system support (former shm fs) Activating SMP support Processor type and features ---> [*] Symmetric multi-processing support

Enable support for GPT -*- Enable the block layer ---> Partition Types ---> [*] Advanced partition selection [*] EFI GUID Partition support


Following commands will build & install the kernel and modules. - #make &amp;&amp; make modules_install &amp;&amp; make install

To speed up above process, following program can be used to generate kernel and additional files required for the system to boot. Following command will install genkernel program. -#emerge --ask sys-kernel/genkernel -#genkernel --install all

Filesystem configuration

Under GNU/Linux, all partitions used by the system must be listed in /etc/fstab file. In this article guide, I have created 4 partitions for the system. It is logical that these partitions be listed in the file in order for the system to boot. Below is generic configuration that is used for this guide.

[code lang=text] /dev/sda2 /boot ext4 defaults,noatime 0 2 /dev/sda3 none swap sw 0 0 /dev/sda4 / ext4 noatime 0 1

/dev/cdrom /mnt/cdrom auto noauto,user 0 0 [/code]

By now, you must be familiar with editing files using nano. Execute following command and insert excerpt into /etc/fstab file. -#nano -w /etc/fstab

Network Configuration

Following commands will help you set hostname & interface you would be using later. - #echo 'hostname="gentoo-x86"'&gt; /etc/conf.d/hostname - #echo 'config_&lt;INTERFACE_NAME&gt;="dhcp"'&gt; /etc/conf.d/net

To find interface name, type ifconfig and you will see output for interface, should be something like enp0s3/enp3s0 & localhost, which is lo. Older GNU/Linux had eth0 like interface name. You can refer to online guides on changing to eth0 like name. For Ubuntu, Fedora like distributions, you can modify grub.cfg/grub2.cfg file to change the interface name. For Gentoo, especially sysvinit/openrc like systems, udev can be set to change interface name.

Next set of commands will link and update with openrc to start up with the system. - #cd /etc/init.d/ - #ln -s net.lo net.&lt;INTERFACE_NAME&gt; - #rc-update add net.&lt;INTERFACE_NAME&gt; default

Next, edit hosts file to add hostname & ip address of your choice. Below excerpt shows an example of /etc/hosts file.

[code lang=text] ###/etc/hostsFilling in the networking information ####### This defines the current system and must be set tux.homenetwork tux localhost

# Optional definition of extra systems on the network jenny.homenetwork jenny benny.homenetwork benny [/code]

Optional : Install System Tools

In this section, you will be installing some system management tools to manage the operating system. Following set of commands will achieve that. -#emerge --ask app-admin/sysklogd -#emerge --ask sys-process/cronie -#emerge --ask sys-apps/mlocate -#emerge --ask net-misc/dhcpcd -#rc-update add sysklogd default -#rc-update add cronie default -#rc-update add sshd default

Install GRUB

This section will help you to install grub bootloader program, which will be used to generate bootmenu at machine startup. Following commands will install grub and generate necessary grub files. -```#emerge --ask --newuse --verbose sys-boot/grub:2-#grub-install /dev/sda-#grub-mkconfig -o /boot/grub/grub.cfg``

Once you're done, run following commands to exit chroot and unmount necessary file systems: -#exit -#cd -#umount -l /mnt/gentoo/dev{/shm,/pts,} -#umount -R /mnt/gentoo

you can choose to reboot the system to see grub menu appearing with newly install Gentoo/Linux system.

Resource: https://wiki.gentoo.org/wiki/Handbook:X86/Full/Installation