Gentoo

Download the latest installation ISO and boot into it. Get networking working.

Partition

parted --script /dev/sda \
    mklabel gpt \
    mkpart primary fat32 1MiB 512MiB set 1 esp on \
    mkpart primary linux-swap 512MiB 4608MiB \
    mkpart primary ext4 4608MiB 100%

Format

mkfs.fat -F 32 /dev/sda1
mkswap /dev/sda2; swapon /dev/sda2
mkfs.ext4 /dev/sda3

Mount

mount /dev/sda3 /mnt/gentoo
mkdir /mnt/gentoo/efi
mount /dev/sda1 /mnt/gentoo/efi
cd /mnt/gentoo

Base setup

Download the latest stage 3 archive. Hit the down arrow until you reach ‘Stage 3 no multilib | systemd’ option, then hit the right arrow to download

links https://www.gentoo.org/downloads/#amd64-advanced

Extract the archive

tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner

Setup some basics

Add the “-march=native” flag to make.conf

sed -i s'|COMMON_FLAGS="-O2 -pipe"|COMMON_FLAGS="-march=native -O2 -pipe"|' etc/portage/make.conf

Set the CPU flags for compile optimizations

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

Copy resolv.conf

cat /etc/resolv.conf | grep -v ^# > etc/resolv.conf

chroot into the new environment

arch-chroot /mnt/gentoo

Update environment variables

source /etc/profile; export PS1="(chroot) ${PS1}"

Sync the portage database

emerge --sync

Set the hostname

echo "gentoo" > /etc/hostname

Set your timezone

ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime

Set your locale

echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
locale-gen
eselect locale set en_US.utf8

Update the environment again

source /etc/profile; export PS1="(chroot) ${PS1}"

Set your system-wide USE flags

echo 'USE="-X"' >> /etc/portage/make.conf

Set the systemd USE flags (to enable systemd-boot) and recompile systemd

echo "sys-apps/systemd boot" > /etc/portage/package.use/systemd
emerge sys-apps/systemd

Install the bootloader (this can be done before the kernel install)

bootctl install

Enable systemd-boot and dracut use flags for installkernel

echo "sys-kernel/installkernel dracut systemd-boot" > /etc/portage/package.use/installkernel

Set some ACCEPT_KEYWORD flags so you can get the latest kernel

echo "sys-kernel/gentoo-kernel-bin ~amd64" > /etc/portage/package.accept_keywords/kernel
echo "virtual/dist-kernel ~amd64" >> /etc/portage/package.accept_keywords/kernel

Set your kernel command line parameters

echo -e "root=/dev/sda3\nnet.ifnames=0" > /etc/kernel/cmdline

Install the kernel

emerge sys-kernel/gentoo-kernel-bin

Create your fstab file. We’re going to leave some room so eix can run on a ramdisk

cat << EOF > /etc/fstab
/dev/sda1   /efi              vfat    rw,fmask=0137,dmask=0027    0 2
/dev/sda2   swap              swap    sw                          0 0
/dev/sda3   /                 ext4    noatime                     0 1
none        /var/cache/eix    tmpfs   size=64m                    0 0
EOF

Create the machine-id

systemd-machine-id-setup

Create your eth0 config file

echo -e "[Match]\nName=eth0\n\n[Network]\nDHCP=yes" > /etc/systemd/network/eth0.network

Allow root logins - or not

echo "PermitRootLogin yes" > /etc/ssh/sshd_config.d/01-permit-root.conf

Enable sshd and systemd-networkd

systemctl enable sshd systemd-networkd

Set the root password

passwd

Exit the chroot, reboot into the new system

exit; reboot

Speed up emerge

Install git to grab the portage database

emerge dev-vcs/git

Install the eselect utility to select repositories

emerge app-eselect/eselect-repository

Remove the portage database we pulled in earlier

rm -rf /var/db/repos/gentoo

Enable the gentoo git repository

eselect repository enable gentoo

Synchronize the portage database again, this time it will happen through git

emerge --sync

Install EIX

EIX is a utility for searching and diffing ebuild repositories. And it’s FAST!

Install EIX

emerge -a app-portage/eix

Configure EIX

mkdir /etc/portage/env /etc/portage/package.env /etc/portage/postsync.d

cat << EOF > /etc/portage/env/eix-extra-econf.conf
EXTRA_ECONF="--enable-security
--enable-new-dialect
--enable-strong-optimization"
EOF

echo "app-portage/eix eix-extra-econf.conf" > /etc/portage/package.env/eix
eix-update

Run an EIX diff every time you ‘emerge –sync’

cat << EOF > /etc/portage/postsync.d/eix
#!/usr/bin/env bash
if [[ -e /var/cache/eix/portage.eix ]]; then
    rsync -ca /var/cache/eix/portage.eix /var/cache/eix/previous.eix;
fi
eix-update
if [[ -e /var/cache/eix/previous.eix ]]; then
    eix-diff;
fi
EOF

chmod +x /etc/portage/postsync.d/eix

Run a deep emerge to recompile programs with updated USE and CPU flags

emerge -auDNv @world

Add some of my favorites

emerge -a app-editors/neovim app-shells/zsh app-portage/gentoolkit app-misc/tmux

Use nvim as your ‘vi’ and ‘EDITOR’ alternatives

eselect vi set nvim
eselect editor set nvim