Low Orbit Flux Logo 2 F

Gentoo Install - Quick Notes ( systemd server )

This installation doc is / includes:

NOTE - All disk device names and IP addresses will probably be different on your system. Make sure to check and adjust these for your specific system. Also, the same is true for locale and timezone info.

Install Media and Getting Started

Download the installation media: https://www.gentoo.org/downloads/

Disk Partitioning and Filesystems

Check whether your system uses BIOS or UEFI:



[ -d /sys/firmware/efi ] && echo UEFI || echo BIOS

UEFI / GPT

NOTE - EFI partition could be mounted on either /boot/efi or /efi. We are going with /efi. This seems to be the “default” choice in the docs. There are some advantages to using /boot/efi and I may update these instructions to use that instead in the future. There are potential issues that could pop up and we show you a work around for this further on in the instructions.

Gdisk Type Partition Mount Size FS
EF00 EFI /efi 128MB FAT32
8200 swap ….. 1024MB or more …..
  root / remaining space XFS

Partition disk:



gdisk /dev/sda

With these options:



o, y                                   # new disklabel
n,1,[default],+128M,EF00               # EFI
n,2,[default],+1024MB,8200             # swap
n, 3, [default], [default], [default]  # root
w, y                                   # write

Format disks:



mkfs.vfat -F 32 /dev/sda1
mkswap /dev/sda2 && swapon /dev/sda2
mkfs.xfs /dev/sda3

Mount disks:



mkdir -p /mnt/gentoo
mount /dev/sda3 /mnt/gentoo

mkdir /mnt/gentoo/efi              # EFI only
mount /dev/sda1 /mnt/gentoo/efi    # EFI only

Tarball and Mirrors



cd /mnt/gentoo

Find the most updated Stage3 tarball here: https://www.gentoo.org/downloads/

Download the latest systemd stage3 automatically. Gentoo publishes a pointer file that always names the current tarball, so this command keeps working as new builds come out:



wget https://distfiles.gentoo.org/releases/amd64/autobuilds/$(wget -qO- https://distfiles.gentoo.org/releases/amd64/autobuilds/latest-stage3-amd64-systemd.txt | grep -o '[0-9TZ]*/stage3-amd64-systemd-[0-9TZ]*\.tar\.xz')

Unpack:



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

Find mirrors to use here ( or use the tool below ): https://www.gentoo.org/downloads/mirrors/

Nice tool for selecting mirrors. You probably won’t need to install it. It should already be installed. If it isn’t add the tool with this command before running it.



emerge app-portage/mirrorselect

Select the mirror:



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

Create repo configs:



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 the current DNS server setting before chrooting:



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

Mount Filesystems and Chroot

Mount filesystems and chroot:



cd /mnt/gentoo
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 . /bin/bash
source /etc/profile

For EFI, this partition should still be mounted but if it isn’t you need to make sure that it is re-mounted:



mkdir /efi
mount /dev/sda1 /efi

Update and Portage Setup

Probably won’t need anything changed but here is an example:



nano /etc/portage/make.conf
MAKEOPTS="-j4 -l4"

-j   # jobs
-l    # load average

Default behavior is to set to smaller of these two values:

Install latest snapshot ( repo info ). This command works well behind firewalls and conserves bandwidth:



emerge-webrsync

Show profiles:



eselect profile list

Select a profile. Pick a systemd profile and use the same profile version as the stage tarball. Upgrading a profile version requires special instructions.



eselect profile set 2    # select the systemd profile number

Emerge @world:



emerge -avuDN @world

Users and Important Tools

Set root password:



passwd

Add a user:



useradd -g users -G wheel,portage -m user1
passwd user1

Install VIM:



emerge -vq vim

Fstab

NOTE - You can also identify disks by UUID instead of device name ( ex. sda1 ).

For EFI:



nano /etc/fstab
/dev/sda1   /efi        vfat    defaults              0 2
/dev/sda2   none         swap    sw                   0 0
/dev/sda3   /            xfs    defaults,noatime      0 1

Locale, Timezone, etc

Set locales:



nano /etc/locale.gen
C.UTF8 UTF-8
en_US ISO-8859-1
en_US.UTF-8 UTF-8

Generate and verify locales:



locale-gen  # generate locales
locale -a     # verify

Select locale:



eselect locale list
eselect locale set 3      # choose en_US.UTF-8 UTF-8

Reload env stuff:



env-update && source /etc/profile && export PS1="(chroot) ${PS1}"


Set timezone ( the symlink is the current idiomatic method ):



ln -sf ../usr/share/zoneinfo/America/New_York /etc/localtime

Generate the machine ID ( systemd requires this — run it inside the chroot ):



systemd-machine-id-setup

NOTE - After first boot you can also use the usual systemd tools: localectl, timedatectl, and hostnamectl.

Kernel

Install firmware for NICs, GPUs, and more. Also includes AMD microcode.



emerge --ask sys-kernel/linux-firmware

Install Intel microcode ( optional on AMD systems ).



emerge --ask sys-firmware/intel-microcode

Distribution kernels ( dist kernels )

Dist kernels build most drivers ( including filesystem and storage drivers ) as modules, so an initramfs is required to boot. Setting these USE flags on sys-kernel/installkernel pulls in dracut to generate the initramfs and runs grub-mkconfig automatically every time a kernel is installed:



mkdir -p /etc/portage/package.use
echo "sys-kernel/installkernel dracut grub" > /etc/portage/package.use/installkernel

Install kernel install framework ( this package was previously named sys-kernel/installkernel-gentoo, which no longer exists ):



emerge --ask sys-kernel/installkernel

Install distribution kernel ( this builds the kernel and generates the initramfs and GRUB config via the flags above ):



emerge --ask sys-kernel/gentoo-kernel

Install kernel sources:



emerge -av sys-kernel/gentoo-sources

Show and set which kernel sources are linked:



eselect kernel list
eselect kernel set 1  # only change if needed
ls -l /usr/src/linux

Bootloader

Install GRUB Package

EFI:



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

Install GRUB to Disk

EFI:



grub-install --target=x86_64-efi --efi-directory=/efi

EFI - Alternative

Specifying “–removable” will install the boot loader into the default location instead of a specific directory (/boot/efi/EFI/BOOT/BOOTX64.EFI). This is good for installing on removable media or systems with a broken/messed up UEFI. If you do this it won’t rely on the EFI variables stored in NVRAM/EEPROM. A potential side effect could be that it might not show as a boot option presented by the firmware.

If you mounted your EFI partition on /efi and not on /boot/efi then you will need to create the link below. If you mounted it on /boot/efi then you don’t need to create the link.



cd /boot
ln -s /efi efi
grub-install --target=x86_64-efi --removable

GRUB Configs

Generate GRUB configs:



grub-mkconfig -o /boot/grub/grub.cfg

Network

Set hostname:



echo test1 > /etc/hostname

systemd-networkd

systemd ships with its own network manager, so nothing extra needs to be installed. Check your interface name first ( systemd uses predictable names like enp1s0, not eth0 ):



ip link

DHCP configuration:



nano /etc/systemd/network/50-wired.network

[Match]
Name=enp1s0

[Network]
DHCP=yes

OR static IP configuration:



nano /etc/systemd/network/50-wired.network

[Match]
Name=enp1s0

[Network]
Address=192.168.0.2/24
Gateway=192.168.0.1
DNS=8.8.8.8

Enable networkd and resolved ( works from inside the chroot — services start on first boot ):



systemctl enable systemd-networkd
systemctl enable systemd-resolved
ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf

Finish Install

Exit chroot environment and reboot:



exit
cd
umount -l /mnt/gentoo/dev{/shm,/pts,}
umount -R /mnt/gentoo
reboot

Remove tarballs:



rm /stage3-*.tar.*

Basic Standard Components

These are standard, normal components that I would generally expect to be present on most systems. These are usually a good idea to install. You could also install these before restarting the host if you like.

Remote access:

Enable SSHD ( works from inside the chroot — starts on first boot ):



systemctl enable sshd

Serial console ( instead of editing /etc/inittab like OpenRC ):



systemctl enable serial-getty@ttyS0.service

PCI Utils

Nice to have:



emerge -av pciutils

Logging

systemd includes journald, so no separate syslog daemon is needed. View logs with:



journalctl -b        # logs from current boot
journalctl -u sshd   # logs for one service

Cron Replacement - systemd Timers

systemd timers replace cron. List them with:



systemctl list-timers

To schedule your own job, create a service unit and a matching timer unit, then enable the timer:



nano /etc/systemd/system/mytask.service

[Unit]
Description=My task

[Service]
Type=oneshot
ExecStart=/usr/local/bin/mytask.sh



nano /etc/systemd/system/mytask.timer

[Unit]
Description=Run my task daily

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target



systemctl enable mytask.timer

File Indexing

File indexing with plocate ( the modern replacement for mlocate — faster and with a smaller index ):



emerge --ask sys-apps/plocate

Shell Completion

Shell completion for bash ( includes Gentoo specific commands and others ):



emerge --ask app-shells/bash-completion

Time Sync

systemd includes systemd-timesyncd for time keeping:



systemctl enable systemd-timesyncd

FS Tools

XFS sys-fs/xfsprogs
ext4 sys-fs/e2fsprogs
VFAT (FAT32, …) sys-fs/dosfstools
Btrfs sys-fs/btrfs-progs
ZFS sys-fs/zfs
JFS sys-fs/jfsutils


emerge sys-fs/xfsprogs sys-fs/e2fsprogs sys-fs/dosfstools sys-fs/btrfs-progs sys-fs/zfs sys-fs/jfsutils

Extra Device Stuff

Important for scheduler behavior with nvme drives (???):



emerge --ask sys-block/io-scheduler-udev-rules

References