Gentoo Installation
Installing gentoo isn’t as hard as people describe. People get very elitist about what distro they use, what init system, if they use a tiling window manager and so on but the truth is I don’t think anyone cares. There is a place for everything so use what is right for you. Gentoo is a source-based distribution so expect a lot of time spent compiling programs especially if you are using a desktop like GNOME.
Below I am going through a gentoo installation (for UEFI) in a VM (KVM/QEMU) using the documentation available on their website. Read the documentation to install the way you want to such as if you want different kernel modules, installing GPU and network card drivers, if you want to whitelist installation of programs with licenses you specified and whatever else you want done differently.
Download
I went to the downloads page. I downloaded the amd64 minimal installation CD. cd ~/Downloads && wget https://bouncer.gentoo.org/fetch/root/all/releases/amd64/autobuilds/20230326T170209Z/install-amd64-minimal-20230326T170209Z.iso
. I decided to avoid going with the gentoo liveGUI because it didn’t seem neccesary.
Verification is not required but it is a good idea to. Going here, I downloaded the relevant .asc file.
#importing keys
wget -O - https://qa-reports.gentoo.org/output/service-keys.gpg | gpg --import
#verifying media
gpg --verify ~/Downloads/install-amd64-minimal-20230326T170209Z.iso.asc
#in the output, you should find this
gpg: Good signature from "Gentoo Linux Release Engineering (Automated Weekly Release Key) <releng@gentoo.org>" [unknown]
#To make sure the key is valid, check the fingerprint (currently 13EB BDBE DE7A 1277 5DFD B1BA BB57 2E0E 2D18 2910) at this address https://www.gentoo.org/downloads/signatures/ .
Attaching ISO + Booting
At this point you would burn the ISO to a flash drive or CD but I am installing in a VM so I select the ISO going through the setup process in my VM manager. Gentoo doesn’t need a lot of storage so I generously allocated 20 GB for the qcow2 disk.
Starting up the VM, I reach the GRUB menu. I will select the Boot LiveCD (kernel: gentoo)
option. When it is finally up, I see livecd ~ #
ready to type in commands. Select keyboard number when option shows. I use 42 (uk).
Network
I should already have an internet connection as I already enabled and set to NAT during setup of my VM. It is best to test. ping -c 3 www.gentoo.org
.
I decided to set a DNS too.
nano -w /etc/resolv.conf
**
nameserver 9.9.9.9
nameserver 89.233.43.71
**
Partitioning + Filesystem
There is a lot of different configurations you can go with when it comes to this but I will make mine simple.
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 346.1M 1 loop /mnt/livecd
sr0 11:0 1 388M 0 rom /mnt/cdrom
vda 253:0 0 20G 0 disk
The disk I am installing on is vda (/dev/vda/). Looking at the documentation, you can see what each statement below does.
fdisk /dev/vda
p
g
n
1
2048
+256M
t
1
1
t
n
2
526336
+4G
t
2
19
n
3
#Clicking enter and enter again
p
#p should show you the setup you have designed for size, start and end location and type.
w
Setting the filesystem is simple enough. Make it the way you want like always following the documentation.
mkfs.vfat -F 32 /dev/vda1
mkfs.ext4 /dev/vda3
mkswap /dev/vda2
swapon /dev/vda2
Mounting + Installing Tarball
mount /dev/vda3 /mnt/gentoo/
#checking date is important. If it is too far off, you may not be able to download due to the security certificates for Gentoo's web based services. Mine was fine but you should change yours if it is off.
date
#I am going with systemd amd64 stage 3 archive.
cd /mnt/gentoo
wget https://bouncer.gentoo.org/fetch/root/all/releases/amd64/autobuilds/20230326T170209Z/stage3-amd64-systemd-20230326T170209Z.tar.xz
#I want to verify the file too
wget https://mirror.bytemark.co.uk/gentoo//releases/amd64/autobuilds/current-stage3-amd64-openrc/stage3-amd64-systemd-20230326T170209Z.tar.xz.asc
wget -O - https://qa-reports.gentoo.org/output/service-keys.gpg | gpg --import
gpg --verify stage3-amd64-openrc/stage3-amd64-systemd-20230326T170209Z.tar.xz.asc
#should have output good signature. Double check the fingerprint is the same as on the release media signatures page again.
#remove any other files in our current directory other than the .tar.xz
#unpack
tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner
Compile Options
nano -w /mnt/gentoo/etc/portage/make.conf
#only made one change adding into common flags. There are many options you can set here but the defaults are generally good.
**
-march=native
**
Mirror Server Selection + DNS
You may want to select a mirror nearby for faster speeds to download packages faster. I selected two UK HTTPS servers.
mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf
Now setting for gentoo ebuild repository
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
I configured a DNS before so I am copying this over
cp --dereference /etc/resolv.conf /mnt/gentoo/etc/
Mounting + Chroot
Now we mount needed filesystems.
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
Enter new environment + mount boot partition.
chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(chroot) ${PS1}"
mount /dev/vda1 /boot
Configuring Portage
#Installing a Gentoo ebuild repository snapshot from the web
emerge-webrsync
#Updating the Gentoo ebuild repository
emerge --sync
#Set profile. See current.
eselect profile list
#Mine is already on the correct one (22) so I don't need to select a different one with eselect profile set 22.
#Updating the world set
emerge --ask --verbose --update --deep --newuse @world
#USE flags is a big part of gentoo and you can see its importance in the documentation. I won't mess with it too much for this install since I am not even setting up with a GUI.
nano /etc/portage/make.conf
**
USE="-gtk -gnome -qt5 -kde"
**
#for CPU_FLAGS_*
emerge --ask app-portage/cpuid2cpuflags
echo "*/* $(cpuid2cpuflags)" > /etc/portage/package.use/00cpu-flags
#Configure the ACCEPT_LICENSE variable.
nano /etc/portage/make.conf
**
ACCEPT_LICENSE="-* -@EULA @FREE @BINARY-REDISTRIBUTABLE"
**
Timezone + Locales
#Timezone for London (this is for systemd)
ln -sf ../usr/share/zoneinfo/Europe/London /etc/localtime
#Locale
nano -w /etc/locale.gen
**
en_GB.UTF-8 UTF-8
en_GB ISO-8859-1
**
locale-gen
eselect locale list
eselect locale set 6
#Reloading environment
env-update && source /etc/profile && export PS1="(chroot) ${PS1}"
Kernel
Before installing the kernel, a lot of you will need to install linux-firmware and may want to setup for microcode updates too. I will not in this example. I will be using the distribution kernels but you can choose to go genkernel or entirely manual way too.
#as I am going to use GRUB
emerge --ask sys-kernel/installkernel-gentoo
#installing a binary instead of compiling myself because I want to save some time.
emerge --ask sys-kernel/gentoo-kernel-bin
#clean up stale packages
emerge --depclean
Fstab
This part is very easy to mess up so read the documentation carefully.
#get UUID for this from blkid
UUID=31B7-FB06 /boot vfat defaults 0 2
UUID=09120ae9-0ac7-4574-b3d5-97e9a59eb6c8 / ext4 noatime 0 1
Network
#hostname
echo diyargentoo > /etc/hostname
#DHCP
emerge --ask net-misc/dhcpcd
systemctl enable --now dhcpcd
#hosts file
nano /etc/hosts
**
#comment out previous
127.0.0.1 diyargentoo.homenetwork diyargentoo localhost
**
System Operation + File Indexing
#root password
passwd
Enter new password: password1*
#init and boot conifg
systemd-firstboot --prompt --setup-machine-id
#prompted for keymapping
uk
systemctl preset-all --preset-mode=enable-only
systemctl preset-all
#enable file indexing
emerge --ask sys-apps/mlocate
Time Synchronization + Filesystem Tools
systemctl enable systemd-timesyncd.service
emerge --ask sys-fs/e2fsprogs sys-fs/dosfstools
Boot Loader
I’m going with GRUB because it’s what I know.
echo 'GRUB_PLATFORMS="efi-64"' >> /etc/portage/make.conf
emerge --ask sys-boot/grub
#install grub
grub-install --target=x86_64-efi --efi-directory=/boot
grub-mkconfig -o /boot/grub/grub.cfg
Reboot
exit
cd
umount -l /mnt/gentoo/dev{/shm,/pts,}
umount -R /mnt/gentoo
reboot
#select first option in GRUB, username root, password1*
Create User
Creating and using normal user.
useradd -m -G users,wheel,audio -s /bin/bash diyar
passwd diyar
Password: password1*
Re-enter password: password1*
#You may also want to setup sudo or doas so this user can run commands as root without having to login to user root to execute such a command.
emerge --ask app-admin/doas
nano /etc/doas.conf
**
permit :wheel
**
#When setup, I can switch to user with su - diyar and execute commands as the root user with doas.
Cleanup
The stage3 is still in the root directory. Remove it with rm /stage3-*.tar.*
Start Networking + Neofetch
#Enable and start dhcpcd
systemctl enable --now dhcpcd
systemctl start dhcpcd
#install neofetch
emerge --ask app-misc/neofetch
Conclusion
Now it is installed. It brings some pain with installing but the only thing I find annoying is the time it takes. There is still a lot to learn about gentoo and how to use this system so go to the gentoo wiki and learn more.