I would like to preface this guide by addressing a few points:
- Firstly, this is a very basic installation for Gentoo. The intended audience, therefore, is not hard-core Linux advocates but rather the Linux beginner who wants something more optimised and customisable than the mainstream Linux distros. Gentoo is meant to be an extremely customisable operating system, and this guide will not give justice to all of Gentoo’s capabilities. Rather, this guide can be used to show the basic premise of installing an operating system from command line and provide a framework for future installations.
- Secondly, like every Linux installation, there is almost always more than one way to achieve something. Different scripts and commands can be input that do the same thing as the commands in this guide. If you prefer a certain partition manager, bootloader or text editor for example, then work with your preference, not what is necessarily included in this guide.
- Finally, while this guide can be applied to many systems, it may not work with yours. Being aware of your system specifications and components is necessary to identify where this guide may fall apart. This is intended for 64-bit Intel and AMD systems with “regular” components and settings. If you need additional instruction or have specialised hardware, go to the Gentoo handbook: http://www.gentoo.org/doc/en/handbook/handbook-amd64.xml .
- All credit goes to this handbook as well as a few more specialised installation guides from the Gentoo site.
This guide should get you to a desktop environment, running off a partitioned disk with sound, optimal compilation settings, desired preferences and profile, a functioning kernel, a connection to the internet, system tools installed and a bootloader.
- Network (temporary)
- Partitions
- Filesystems
- Installation Files
- Compile Options
- Chrooting
- Portage
- Profiles
- Preferences
- Kernel
- Network (permanent)
- System Tools
- Bootloader
- Rebooting
- Clean-up
- Desktop Environment
Network (temporary)
A temporary internet connection must be established to download the latest source code and packages for the Gentoo operating system.
Assumptions and choices:
- No proxy is used;
- No ADSL (PPPOE) connection;
- No PPTP connection;
- No hard-core manual network configuration is required.
Test network connection:
ping www.google.com –c 3
Finding existing network configurations:
ifconfig
Identify the existing network configuration label (such as eth0, enp5s0, enp2s1 etc) and write it down.
The lo label is the local loopback and is not the correct network label to establish an internet connection.
There may be more than one, so you may need to use trial and error to determine the correct one.
The network configuration label must be noted because it will be used to configure the permanent network for the system later.
If the ping test was successfully, skip to Partitions.
Establish an internet connection (wired):
net-setup <network configuration label>
Where <network configuration label> is the network configuration label found using ifconfig.
Configuring a wireless network:
iwconfig <network configuration label> essid <network name>
iwconfig <network configuration label> key s:<WEP key>
Where <network configuration label> is the network configuration label found using ifconfig and <network name> is the wireless network name (SSID) and <WEP key> is the WEP password for the wireless network.
The s: parameter is only required if the WEP key uses an ASCII format. If the key uses a hexadecimal format, do not include the s: parameter.
Establish an internet connection (wireless):
net-setup <network configuration label>
Where <network configuration label> is the network configuration label found using ifconfig.
Testing the network connection again to see if net-setup was successful:
ping www.google.com –c 3
If the test still fails, you may need to load a module for Gentoo to recognise your network device, or your network requires more advanced configuration. Consult the Gentoo handbook to find the necessary instructions.
Partitions
Partitions should be created to categorise filesystems intuitively and methodically.
Assumptions and choices:
- A GUID Partition Table (GPT) will be used for the partitioning technology (if you are dual-booting with a Windows operating system, you must use a Master Boot Record (MBR) setup);
- No swap partition will be created. If you are running a 64-bit system then you most likely have more than 4 GB of Random Access Memory (RAM). Therefore, a swap partition is not really necessary unless you plan on using hibernation or running very memory intensive applications.
- A BIOS boot partition will be created for the GRUB2 bootloader. If you are using a non-GRUB bootloader, this partition is not required.
- Only one partition will be created for storing files and this will be the root partition. If you want added security by separating your files from the root partition, you should create an additional partition.
- The size of each partition has been chosen quite generally and therefore can be tailored to suit your preferences.
Initialise a partition manager (we will use parted and assume the disk is located at /dev/sda):
parted –a optimal /dev/sda
Setting the GPT label on the disk:
mklabel gpt
Viewing current partition layout:
Removing existing partitions (if the disk has not been formatted):
rm <partition number>
Where <partition number> is the desired partition number.
Defining units to use for partitions (using mebibytes (which are distinct from megabytes)):
unit mib
Creating 2 MB bootloader partition:
mkpart primary 1 3
name 1 Bootloader
set 1 bios_grub on
Creating a 512 MB boot partition:
mkpart primary 3 515
name 2 Boot
Creating root partition on rest of disk:
mkpart primary 515 -1
name 3 Root
Viewing partitions:
Exiting parted:
quit
Ignore the fstab notification for it will be configured later.
Filesystems
Filesystems must be applied to the boot and root partitions to work with directories and locations of files.
Assunptions and choices:
- The boot and root partitions will use the Extended 4 Filesystem (ext4). The boot partition does not necessarily benefit from this choice but for consistency, it will be used.
Applying ext4 filesystems to boot and root partitions:
mkfs.ext4 /dev/sda2
mkfs.ext4 /dev/sda3
Mounting partitions:
mount /dev/sda3 /mnt/gentoo
mkdir /mnt/gentoo/boot
mount /dev/sda2 /mnt/gentoo/boot
Installation Files
The stage3 tarball will be downloaded and installed to establish the Gentoo core operating system.
Viewing time and date:
date
If the time and date is incorrect, change it:
date MMDDhhmmYYYY
Where MMDDhhmmYYYY is the correct time and date (Month, Day, hour, minute, Year).
An incorrectly configured clock can cause issues when updating packages so ensure it is correct.
View the architecture of your CPU:
uname -m
Going to the Gentoo mountpoint where the filesystems were mounted:
cd /mnt/gentoo
Finding a mirror to download the stage3 tarball (we will use links):
Pick a mirror, move to releases/amd64/autobuilds/current-stage3-amd64, highlight the desired stage3 tarball, press D to download.
For example: stage3-amd64-YYYYMMDD.tar.bz2 where YYYYMMDD is the date (Year, Month, Day).
Unpacking the stage3 tarball:
time tar xvjpf stage3-amd64-YYYYMMDD.tar.bz2
Compile Options
Flags can be set in configuration files to optimise how the system compiles scripts.
Assumptions and choices:
- While no assumptions have really been made, the compile options are an extremely subjective component of the Gentoo installation process. Consult the Gentoo handbook for more information and tips.
Opening Portage configuration file:
nano –w /mnt/gentoo/etc/portage/make.conf
Editing CFLAGS variable:
CFLAGS=“-march=<processor architecture> -O2 –pipe”
Where <processor architecture> is the architecture of your CPU.
Some examples of march flags: ivybridge, haswell, k8…
If unsure, use: -march=native.
Make sure the CXXFLAGS variable is the same as the CFLAGS variable:
CXXFLAGS=“${CFLAGS}”
Editing MAKEOPTS variable:
MAKEOPTS=“-j<number of processor cores + 1>”
Where <number of processor cores + 1> is the number of cores in your CPU + 1.
For example, a quad-core processor would use: MAKEOPTS=“-j5”.
A quad-core processor (with Intel hyperthreading) would use: MAKEOPTS=“-j9”.
Saving and exiting the make.conf file:
Press: Ctrl-X > Enter > Enter
Chrooting
Chrooting is the process of moving from the installation medium to your own system.
Define Gentoo mirror and rsync mirror for downloading source code using Portage:
mirrorselect –i –o >> /mnt/gentoo/etc/portage/make.conf
mirrorselect –i –r –o >> /mnt/gentoo/etc/portage/make.conf
Copying DNS information so network will work in chrooted environment:
cp -L /etc/resolv.conf /mnt/gentoo/etc/
Mounting /proc, /sys and /dev:
mount -t proc proc /mnt/gentoo/proc
mount --rbind /dev /mnt/gentoo/dev
mount --rbind /sys /mnt/gentoo/sys
Chrooting from installation medium to initialised partition environment:
chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(chroot) $PS1"
You are now in your own Linux environment.
Portage
Portage is Gentoo’s package management system based on the concept of port trees. You must inform Portage which software can be installed on your system as well as how some aspects of your computer have been configured.
Downloading and installing latest Portage snapshot and updating Portage tree:
emerge-webrsync
emerge --sync
Ignore any news items, for they can be addressed later.
Profiles
A profile in Gentoo specifies many default variables and configurations for your system and locks the system to a range of specific package versions.
Viewing current system profile:
eselect profile list
Changing system profile:
eselect profile set <profile number>
Where <profile number> is the number corresponding to the desired profile (If you were to use KDE you would select the number corresponding to default/linux/amd64/xx.x/desktop/kde where xx.x is the current version.
Preferences
Your desired system preferences will now be set such as your timezone and language as well as some USE variable flags.
Assumptions and choices:
- The USE flags are heavily system dependent.
- If you want to use KDE as your desktop environment, you need to include kde and qt4.
- If you want to use GNOME as your desktop environment, you need to include gnome and gtk.
- It is recommended to check the Gentoo handbook to identify the optimal USE flags to include.
Opening Portage configuration file again (the USE variable would be overwritten after chrooting so it must be set now):
nano –w /etc/portage/make.conf
Changing USE variable (need to identify which flags are appropriate for your system and your preferences):
USE=“acl acpi alsa bindist bluetooth cdinstall cdr cxx dga dri dvd dvdr encode fbcon flac ftp gcj gd gif icu inifile ios ipod java javascript jpeg kde libkms mmx mp3 mp4 mpeg mtp multilib nptl opengl pdf png posix profile python qt4 qt5 scsi sharedmem smp sound sqlite sqlite3 sse sse2 sse3 udev unicode usb vorbis wifi X x264 xa xml xorg”
Viewing available timezones:
ls /usr/share/zoneinfo
Choose a timezone (for example Australia/Melbourne) based on the list of timezones.
Setting timezone preference:
echo “<timezone>” > /etc/timezone
Where <timezone> is the desired timezone.
Reconfiguring timezone preference:
emerge --config sys-libs/timezone-data
Viewing available locales:
nano -w /etc/locale.gen
Specify the desired locale by removing the hash (#) at the beginning of the desired locale.
For example: #en_US .UTF-8 UTF-8 becomes en_US.UTF-8 UTF-8.
Reconfiguring locale preference:
locale-gen
Checking chosen locale:
locale -a
Viewing available languages:
eselect locale list
Setting language preference:
eselect locale set <language number>
Where <language number> is the number corresponding to the desired language.
For example: <language number> en_US.utf8.
Reloading shell environment with updated preferences:
env-update && source /etc/profile
Kernel
The kernel is the layer between the hardware and software in a computer system. It manages input and output requests and converts them into instructions for the components in your computer (like your CPU).
Assumptions and choices:
- A manual kernel configuration guide is not included in this guide.
- Since the kernel must be configured on an individual system basis, it would be too laborious to express the kernel configuration as a step-by-step guide for every system.
- Instead the kernel can be configured automatically using a script provided by Gentoo.
- (A manual kernel configuration is paramount if you want Gentoo to be optimised perfectly for your system. Fortunately the manual kernel configuration is highly documented in the Gentoo handbook.)
Downloading and installing a kernel source:
emerge gentoo-sources
Viewing the kernel source symlink (or in other words, the kernel source version):
ls -l /usr/src/linux
You may need to take note of the kernel version because it might be needed later for the bootloader.
For example: linux-x.y.z-gentoo where x, y and z are the version numbers.
Downloading and installing the automatic kernel configuration script:
emerge genkernel
Running the automatic kernel configuration script:
genkernel all
Since the script compiles a kernel that supports almost all hardware, the compile time is going to be extremely long. Once finished, proceed to the permanent network step.
Or, manually configure the kernel.
Viewing some specifications of system to provide an idea on how to configure the kernel:
emerge pciutils
lspci
lsmod
Downloading the kernel source:
emerge gentoo-sources
Viewing the kernel source symlink (or in other words, the kernel source version):
ls -l /usr/src/linux
Configuring the kernel:
cd /usr/src/linux
make menuconfig
Compiling the kernel:
make -jx && make -jx modules_install
where x is the number of cores in your CPU + 1.
Installing the kernel:
cp arch/x86/boot/bzImage /boot/kernel-x.y.z-gentoo
where kernel-x.y.z-gentoo is the name of your kernel version.
Network (permanent)
The permanent network configuration will be set using configuration files within the Gentoo system.
Assumptions and choices:
- A domain name does not necessarily need to be set.
- The same assumptions from the initial network configuration apply here too.
Setting the host name:
nano -w /etc/conf.d/hostname
hostname=“<host name>”
Where <host name> is the desired host name.
Setting the domain name and automatic IP address:
nano -w /etc/conf.d/net
dns_domain_lo=“<domain name>”
config_<network configuration label =“dhcp”
Where <domain name> is the desired domain name and <network configuration label> is the network configuration label as found in establishing the network for installation (eth0, enp5s0, enp2s1, etc).
Making networking automatically initialise at boot:
cd /etc/init.d
ln -s net.lo net.<network configuration label>
rc-update add net.<network configuration label> default
Where <network configuration label> is the network configuration label.
You may need to exit the init.d environment and chroot back into your partition environment:
Exiting the init.d environment:
quit
Chrooting again:
chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(chroot) $PS1"
Opening hosts configuration file:
nano -w /etc/hosts
Filling in local host information:
127.0.0.1 <host name>.<domain name> <host name> localhost
Where <host name> is the host name and <domain name> is the domain name.
Some wireless cards may be deactivated by default.
Using rfkill to unblock wireless card:
rfkill list
rfkill unlock <index>
System Tools
General system settings like boot configuration, root password and system tools will be configured.
Assumptions and choices:
- The fstab is dependent on your own partition scheme. Every partition must be included, excluding the BIOS boot partition.
- Any number of system tools can be installed and each system tool has a plethora of choices. If you prefer a certain cron daemon or DHCP client, work with what you feel comfortable with. If you require additional system tools, you can use Portage to download and install them.
Creating an fstab:
nano -w /etc/fstab
Edit each line of the fstab configuration file to specify the filesystems that were created. Spaces (whether it be a space or a tab) are what separate each variable in an fstab.
For example:
/dev/sda2 /boot ext4 defaults,noatime 0 2
/dev/sda3 / ext4 noatime 0 1
/dev/cdrom /mnt/cdrom auto noauto,user 0 0
Creating a root password:
passwd
Downloading and installing a system logger:
emerge metalog
rc-update add metalog default
Downloading and installing a cron daemon:
emerge cronie
rc-update add cronie default
Downloading and installing a file indexer:
emerge mlocate
Downloading and installing a DHCP client:
emerge dhcpcd
Downloading and installing a WPA network manager:
emerge wpa_supplicant
Downloading and installing a basic wireless interface configurator:
emerge net-wireless/wireless-tools
Bootloader
The bootloader is the program which initialises your kernel so your software can communicate to your hardware.
Assumptions and choices:
- The GRUB2 bootloader is installed for this guide, but many Linux users prefer other bootloaders. Consult the Gentoo handbook for ideas and tips.
Downloading and installing GRUB2 bootloader (takes some time):
emerge sys-boot/grub
Configuring bootloader:
grub2-install /dev/sda
Generating bootloader configuration file:
grub2-mkconfig -o /boot/grub/grub.cfg
Rebooting
After exiting the configured system and unmounting root filesystems, the machine can be rebooted.
Exit chrooted environment:
exit
Unmount root filesystems:
cd
umount -l /mnt/gentoo/dev{/shm,/pts,}
umount -l /mnt/gentoo{/boot,/proc,}
Reboot machine:
reboot
Clean-up
(Hopefully) you have successfully booted into your Gentoo system. Now the stage3 tarball can be deleted, a non-root user can be added and sound will be enabled.
Assumptions and choices:
- The flags for the new user can be modified to your liking.
- ALSA is used to configure sound.
Deleting stage3 tarball file:
rm /stage3-xxx.tar.bz2
Where xxx is the name of the stage3 tarball used.
Creating non-root user:
useradd -m -G audio,cdrom,games,usb,video,wheel -s /bin/bash xxx
Where xxx is the name of the new user account.
You can also allow the root user to login through the login manager (but this is not recommended).
Allowing root user to login to desktop environment:
nano /usr/share/config/kdm/kdmrc
AllowRootLogin=true
Downloading and installing ALSA:
emerge --ask alsa-utils
Initialising ALSA at boot:
rc-update add alsasound boot
Starting ALSA now:
/etc/init.d/alsasound start
Testing sound (Press Crtl + C to stop sound test):
speaker-test -t wav -c 2
For 5.1 speaker setups:
speaker-test -t wav -c 6 -D surround51
Unmuting sound (if necessary):
alsamixer
Select appropriate channel and press M key to unmute it. Test the sound again to ensure it functions.
Welcome to the Gentoo Linux command line running natively from your system with sound.
Desktop:
Now a graphical user interface will be added to the operating system with support for OpenGL. After this step, you will enter a desktop environment when you reboot into your system.
Assumptions and choices:
- Only open source video drivers will be provided if they exist.
- The mesa package is used for OpenGL support.
- The X window system is used to for display and input devices. You may prefer Wayland.
- KDE is used for the desktop environment. You may prefer GNOME or Xfce.
- The basic KDE package will be installed rather than the complete suite.
Changing video driver:
nano /etc/portage/make.conf
VIDEO_CARDS=”nouveau” (for nVidia cards)
VIDEO_CARDS=”radeon” (for AMD cards)
VIDEO_CARDS=”intel” (for Intel integrated graphics chipsets)
Update system:
emerge --ask --changed-use --deep world
Add OpenGL support (takes very long time to install):
emerge --ask mesa
Install X for display and input devices (takes a very long time to install):
emerge --ask xorg-server
Install KDE for a graphical user interface (takes an extremely long time to install):
emerge --ask kdebase-meta
Set KDM as the default display manager:
nano /etc/conf.d/xdm
DISPLAYMANAGER="kdm"
Initialise display manager on boot:
rc-update add xdm default
Reboot machine (hopefully for the last time from command line):
reboot