/home/ /tech/ /links/ /other/

Preramble

READ THIS BEFORE YOU COMPLAIN!

This guide is probably wrong in many ways, but this is how I install Gentoo for myself.
Don’t blindly follow this guide, some thinking is required. You’re dealing with Gentoo after all.
Even though this guide should be simple to follow, Gentoo isn’t for beginners. Only try installing Gentoo if you’ve got some experience with other distros.
This guide assumes you’re smart enough to already have a Gentoo live USB ready to boot into.
This guide also assumes you know how to partition drives using cfdisk/fdisk.
This guide is for UEFI x86-64 only.
From my experience, you must have a slightly bigger EFI partition if you’re dualbooting. 100MB isn’t enough, mine is 500MB and it works. There’s probably a better way of doing it without needing to resize your EFI, but i’m too lazy to check. If you’re planning to dualboot with Windows, you have to mess around in cmd while installing it to resize the EFI partition. I’ll do a small article for that later. Here it is.
Don’t be afraid to stray away from the instructions a little! By experimenting you learn, and learning is fun, right? :)
I’ll probably also make a guide on what to do after installing the base system, but that’s for later.

The guide

Open up cfdisk, create a boot EFI partition and a normal partition for everything else (this will be the LUKS container) DUALBOOT NOTE: If you’re dualbooting and there’s already an EFI partition, you don’t have to create it again, just the main LUKS container will do.

cfdisk

Obviously also format them
DUALBOOT NOTE: DO NOT FORMAT THE EFI PARTITION IF YOU’RE DUALBOOTING WINDOWS!

mkfs.vfat -F32 /dev/sda1
cryptsetup luksFormat /dev/sda2

Open up the encrypted partition

cryptsetup luksOpen /dev/sda2 gentoolvm

Create partitions inside of the encrypted partition
NOTE: Obviously create different partitions to suit your needs, this is just an example.

lvm pvcreate /dev/mapper/gentoolvm
vgcreate vg0 /dev/mapper/gentoolvm
lvcreate -L 2G -n swap vg0
lvcreate -l 100%FREE -n root vg0

Make filesystems for the partitions

mkfs.ext4 /dev/mapper/vg0-root
mkswap /dev/mapper/vg0-swap

Mount the partitions

swapon /dev/mapper/vg0-swap
mount /dev/mapper/vg0-root /mnt/gentoo
cd /mnt/gentoo

Download the stage 3 desktop tarball and unpack it

links https://www.gentoo.org/downloads/
tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner

Configure make.conf
add “-march=native” to COMMON_FLAGS
add “MAKEOPTS="-jX”" somewhere in the file, where X is the amount of cores you have

nano -w /mnt/gentoo/etc/portage/make.conf

Select mirrors
Select the mirrors that are somewhat close to you (I usually choose some german ones, they’re the most reliable from my experience)

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

Configure the repo

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

Copy DNS info

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

Mount the necessary 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 the chroot

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

Mount the boot partition

mount /dev/sda1 /boot

Install an ebuild repo snapshot

emerge-webrsync
emerge --sync

Choose a profile (usually the desktop one)

eselect profile list
eselect profile set 5

Update @world
NOTE: This will take a while, so go get some coffee or something.

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

Configure the USE variable
add “USE=“cryptsetup crypt”” to /etc/portage/make.conf

nano -w /etc/portage/make.conf

Set up your CPU flags

emerge --ask app-portage/cpuid2cpuflags
echo "*/* $(cpuid2cpuflags)" > /etc/portage/package.use/00cpu-flags

Configure the timezone. Obviously replace Region/City.

echo "Region/City" > /etc/timezone
emerge --config sys-libs/timezone-data

Configure the locales
Uncomment your preferred language in /etc/locale.gen
X is the number of the UTF8 locale of your preferred language.

nano -w /etc/locale.gen
locale-gen
eselect locale list
eselect locale set X
env-update && source /etc/profile && export PS1="(chroot) ${PS1}"

Install firmware microcode
NOTE: Only install intel-microcode if you have an intel CPU (duh)

echo "sys-kernel/linux-firmware @BINARY-REDISTRIBUTABLE" >> /etc/portage/package.license
echo "sys-firmware/intel-microcode @BINARY-REDISTRIBUTABLE" >> /etc/portage/package.license
emerge --ask sys-kernel/linux-firmware sys-firmware/intel-microcode

Set up USE flags for lvm and GRUB
NOTE: I’m pretty sure you can throw out mount if you aren’t dualbooting, not sure and I’m too lazy to actually check.

nano /etc/portage/package.use/encryption
sys-fs/lvm2 lvm
sys-boot/grub device-mapper mount

Install cryptsetup and lvm

emerge -a sys-fs/cryptsetup sys-fs/lvm2
rc-update add lvm default

Install the kernel
I’m lazy so I just compile a distribution kernel, but you can do this part however you want, go wild.

emerge -a sys-kernel/gentoo-kernel

Configure fstab

blkid
nano /etc/fstab

/* example fstab config */
UUID=[UUID of the boot partition]                           /boot   vfat    noauto,noatime  1   2
UUID=[UUID of the root partition IN the LUKS container]     /       ext4    defaults        0   1
UUID=[UUID of the swap partition IN the luks container]     none    swap    sw              0   0

Set a hostname

echo illyria > /etc/hostname

Set up keymaps

nano /etc/conf.d/keymaps

Install NetworkManager for networking (or just use dhcpcd if you plan on using only ethernet I guess)

emerge -a net-misc/networkmanager
rc-update add networkmanager default

OR

emerge -a net-misc/dhcpcd
rc-update add dhcpcd default

Install sysklogd for logging

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

Install chrony for time sync

emerge --ask net-misc/chrony
rc-update add chronyd default

Set a root password

passwd

Install GRUB

echo 'GRUB_PLATFORMS="efi-64"' >> /etc/portage/make.conf
emerge --ask sys-boot/grub

add this to GRUB_CMDLINE_LINUX in /etc/default/grub:

GRUB_CMDLINE_LINUX="rd.lvm.vg=vg0 rd.luks.uuid=[UUID of the luks container] quiet" 

Install GRUB for real this time

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

Reboot! the installation is complete.

Sources :
My experience from installing this mess, and also
https://wiki.gentoo.org/wiki/Handbook:AMD64/Full/Installation
https://wiki.gentoo.org/wiki/Full_Disk_Encryption_From_Scratch_Simplified