Gentoo Quick Installation Guide
Disclaimer: This is not an official guide to installing Gentoo. This is a short guide made for those who want a quick install and have knowledge about how Gentoo works.
Introduction
This is a guide I would use for installing Gentoo with systemd (merged-usr) as the init system of choice to the amd64 architecture (uefi).
If you've stumbled upon this and you really want support and precise help, you should probably join Gentoo's IRC channel or Discord
Chapter One: Partitioning.
If you're not a complete beginner to linux, you should know how to partition your drives, so I'll make it quick.
I will be using btrfs for this guide, feel free to use whatever you feel like.
parted -a optimal /dev/sdX
Where X is the letter of your drive.
mklabel gpt
mkpart esp fat32 0% 513
mkpart swap linux-swap 513 16896
mkpart rootfs btrfs 16896 100%
Now that we are done with making the partitions, we just need to create the filesystems.
mkfs.fat -F32 /dev/sdX1
mkswap /dev/sdX2
mkfs.btrfs /dev/sdX3
Now we mount the filesystem to the recommended mount point as per the handbook
mount /dev/sdX3 /mnt/gentoo
You can, of course, change the mountpoint to whatever you like. I'm only doing this for:
- Consistency's sake
- Easier to copy commands from the handbook
Now I'll create the subvolumes for the btrfs drive.
btrfs su cr /mnt/gentoo/@
btrfs su cr /mnt/gentoo/@home
btrfs su cr /mnt/gentoo/@.snapshots
The only things left are unmounting the drive, and then mounting on the appropriate subvolumes.
umount /mnt/gentoo
mount -o subvol=@ /dev/sdX3 /mnt/gentoo
mkdir /mnt/gentoo/{home,efi,.snapshots}
mount -o compress=zstd,subvol=@home /dev/sdX3 /mnt/gentoo/home
mount -o compress=zstd,subvol=@.snapshots /dev/sdX3 /mnt/gentoo/.snapshots
mount /dev/sdX1 /mnt/gentoo/efi
Chapter Two: Stage3 and Chrooting.
Since we're done with partitioning, the "hardest" part is over. I guess. All of them are easy, though.
cd /mnt/gentoo
wget https://bouncer.gentoo.org/fetch/root/all/releases/amd64/autobuilds/20221114T111652Z/stage3-amd64-desktop-systemd-20221114T111652Z.tar.xz
Note that as of writing this, there wasn't a desktop merged-usr systemd stage3 available for download so we're going to do this manually.
The link for the tarball will change. You should go to the download section on Gentoo's website and grab the latest desktop systemd stage3.
If you want to know what a stage3 is, refer to Gentoo's wiki.
tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner
After this process, congratulations, you have a somewhat very minimal Gentoo install.
You are know advised to change some default compiler options on /etc/portage/make.conf
vi /mnt/gentoo/etc/portage/make.conf
I would add something like this, probably:
COMMON_FLAGS="-march=native -O2 -pipe"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"
MAKEOPTS="-j8"
ACCEPT_LICENSE="*"
GRUB_PLATFORMS="efi-64"
EMERGE_DEFAULT_OPTS="--with-bdeps y --complete-graph y --fail-clean y --quiet-build --keep-going"
CPU_FLAGS_X86="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt rdrand sse sse2 sse3 sse4_1 sse4_2 ssse3"
USE="zstd"
Ok, this is a lot to take in. Most of these settings are already set. So you don't have to worry about them.
CPU_FLAGS_X86 is something you have to add according to this.
Set MAKEOPTS for now to the result of the command nproc, e.g -j8
The rest are easily googable. Good luck.
mkdir -p /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
Above we're creating the location where Portage will look for the gentoo repository configuration file, copying the default, and getting our dns resolvers from the liveiso (or whatever media you're using to install it).
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
chroot /mnt/gentoo /bin/bash --login
We're finally chrooted! Wasn't that hard.. was it?
Chapter Three: Setting up the install
Now we're going to be setting up basic systemd things and portage stuff.
emerge-webrsync
This will sync the repositories with the latest snapshot of the repositories, it is recommended for some use cases, for general use, it is better to use something like eix-sync
tool from the eix package.
For this part of the install, we will use emerge-webrsync
because that's what recommended.
Now we will be emerging the script that will manually merge our /bin and stuff to /usr/bin to remove all that / bloat :P
ACCEPT_KEYWORDS="~amd64" emerge -1 merge-usr
merge-usr
eselect profile set 13
Right here I'm emerging the script, then running it, then selecting the 13th profile. For the sake of continuity, while the number may change, the name won't, so you should run eselect profile list
and select the one which is called default/linux/amd64/17.1/desktop/systemd/merged-usr.
Don't worry about running a world update right now, for the sake of doing the quickest usable install possible, we won't be doing the world update right away.
It is also maybe good practice to not actually run it right now, since if the install fails after you spent hours updating world set... I wouldn't want to redo it, to say the least.
ln -sf /usr/share/zoneinfo/Europe/Brussels /etc/localtime
nano /etc/locale.gen
locale-gen
eselect locale list
eselect locale set X
You should uncomment the locales you want in /etc/locale.gen, generate and then select it, where X would be the number of the locale (presented my eselect locale list)
emerge -av btrfs-progs linux-firmware gentoo-kernel-bin
We need btrfs-progs so that we can boot with our btrfs drives later, remember to add zstd to USE flags, since it is the compression we're using.
I'm choosing the bin kernel here so that you don't have problems later down the line that are simply caused by kernel misconfiguration. It happens, a lot.
emerge -1 genfstab
genfstab -U / >> /etc/fstab
The genfstab command is mostly to grab all UUID's easily.
Edit the options so that they match the below.
UUID=847df035-e726-45e9-9cff-fb46aa97ae6e / btrfs defaults,compress=zstd,subvolid=256,subvol=@ 0 0
UUID=847df035-e726-45e9-9cff-fb46aa97ae6e /home btrfs defaults,compress=zstd,subvolid=257,subvol=@home 0 0
UUID=847df035-e726-45e9-9cff-fb46aa97ae6e /.snapshots btrfs defaults,compress=zstd,subvolid=258,subvol=@.snapshots 0 0
UUID=e30fbe93-d09e-4ea9-a1c7-d18d5c5c95fb none swap sw 0 0
UUID=7F8B-5EF0 /efi vfat noauto,defaults 0 2
emerge -a dhcpcd
I'm only using dhcpcd for now because it is faster to emerge than NetworkManager, you can change later to nm.
Remember to change your root password.
passwd
Now to setup systemd:
systemd-firstboot --prompt --setup-machine-id
systemctl preset-all
systemctl enable dhcpcd
systemctl enable sshd
Now to setup bootloader, I'll be using grub.
emerge -av grub
grub-install --efi-directory=/efi
grub-mkconfig -o /boot/grub/grub.cfg
Now I'm going to create an user called larry with the appropriate groups and then change its password
useradd -m -G users,wheel,audio,portage,video -s /bin/bash larry
passwd larry
Remember to remove the tarball after the installation.
rm /stage3-*.tar.*
Now it's time for some post-installation advices.
You can now exit and reboot and you should have a working gentoo system.
After you've booted in, if you are also looking at the handbook, you should see that I didn't update the world set.
You can now update the world set, it will take some time, I must warn.
Portage also recommends --newuse
sometimes and not --changed-use
, but I personally only use -U
because it avoids unecessary rebuilds.
Remember to read the handbook in case you found something here hard or didn't understand.