This guide provides a step-by-step process for installing Gentoo Linux using a modern systemd profile and a Unified Kernel Image (UKI) with systemd-boot.
# Unmount all partitions if mounted, suppressing errors
umount /dev/vda1 2>/dev/null
umount /dev/vda2 2>/dev/null
# Setup internet connection
# Follow the prompts to configure your network interface (e.g., eth0)
net-setup
# Enable SSH to manage installation remotely (optional)
/etc/init.d/sshd start
passwd # Set a temporary root password for the live environment
# Synchronize system clock
chronyd -q
# Add a reliable DNS server
echo 'nameserver 1.1.1.3' > /etc/resolv.conf
# Partition the disk (e.g., /dev/vda)
# This creates a 1GB EFI System Partition (ESP) and uses the rest for the root partition.
sgdisk --zap-all \
--set-alignment=2048 \
--new=1:0:+1G --typecode=1:ef00 --change-name=1:"ESP" \
--new=2:0:0 --typecode=2:8300 --change-name=2:"ROOT" \
/dev/vda
# Format the partitions
partprobe /dev/vda
mkfs.vfat -F32 /dev/vda1
mkfs.ext4 /dev/vda2
# Mount the root partition
mkdir -p /mnt/gentoo
mount /dev/vda2 /mnt/gentoo# Navigate to the mount point
cd /mnt/gentoo
# Dynamically find and download the latest systemd stage3 tarball
MIRROR="https://distfiles.gentoo.org/releases/amd64/autobuilds"
STAGE3=$(curl -s "${MIRROR}/latest-stage3-amd64-systemd.txt" | grep -v '^#' | grep '\.tar\.xz' | awk '{print $1}')
wget "${MIRROR}/${STAGE3}"
# Extract the stage3 tarball
tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-ownerNote: It's crucial to use the systemd stage3 for this guide, as the selected profile relies on it.
# Configure Portage make.conf
# IMPORTANT: Adjust these settings for your specific hardware.
# -jX: Set X to the number of CPU threads you have.
# VIDEO_CARDS: Set to "intel", "amdgpu", "nvidia", etc.
cat > /mnt/gentoo/etc/portage/make.conf << EOF
COMMON_FLAGS="-march=native -O2 -pipe"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"
MAKEOPTS="-j8 -l9"
RUSTFLAGS="${RUSTFLAGS} -C target-cpu=native"
ACCEPT_LICENSE="*"
FEATURES="${FEATURES} binpkg-request-signature getbinpkg"
USE="modules-sign dist-kernel"
# NOTE: This stage was built with the bindist USE flag enabled
# This sets the language of build output to English.
# Please keep this setting intact when reporting bugs.
LC_MESSAGES=C.utf8
EOF
# Copy repository configuration from the stage3 default
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
# Copy DNS info into the new environment
cp --dereference /etc/resolv.conf /mnt/gentoo/etc/# Mount necessary pseudo-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 new environment
chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(chroot) ${PS1}"
# Mount the EFI partition
mkdir -p /efi
mount /dev/vda1 /efi# Update mirrors
emerge -av app-portage/mirrorselect
mirrorselect -i -o 2>/dev/null >> /etc/portage/make.conf
# Use binary packages
sudo sed -i 's/priority = 1/priority = 9999/' /etc/portage/binrepos.conf/gentoobinhost.conf
# Sync the Portage tree
emerge-webrsync
# Explicitly set profile (systemd stage3 comes with a systemd profile, but you can switch variants here)
# Example: default systemd profile or systemd + KDE Plasma
eselect profile list
eselect profile set default/linux/amd64/23.0/systemd
# Install the 'getuto' script to configure the binary package host
getuto
# Install freetype before world
USE="-harfbuzz" emerge --oneshot media-libs/freetype
# Update the @world set to match the new profile, using binary packages where available
# [Use dispatch-conf if config issues arises]
emerge --verbose --update --deep --newuse --getbinpkg @world
# Remove any obsolete packages
emerge --verbose --depclean# Set timezone (example: Asia/Kolkata)
ln -sf /usr/share/zoneinfo/Asia/Kolkata /etc/localtime
# Configure locale
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
eselect locale set en_US.utf8
# Reload the environment to apply locale changes
env-update && source /etc/profile && export PS1="(chroot) ${PS1}"# Install firmware and CPU microcode
emerge --verbose sys-kernel/linux-firmware sys-firmware/intel-microcode
# Configure USE flags for UKI support
cat > /etc/portage/package.use/systemd-uki << EOF
sys-apps/systemd boot ukify
sys-kernel/installkernel dracut uki systemd-boot
sys-kernel/dracut uefi
EOF
# Configure dracut to build the UKI
# We use blkid to get the partition UUID for a more robust boot process.
ROOT_UUID=$(blkid -s UUID -o value /dev/vda2)
ESP_UUID=$(blkid -s UUID -o value /dev/vda1)
mkdir -p /etc/dracut.conf.d
cat > /etc/dracut.conf.d/uki.conf << EOF
uefi="yes"
uefi_stub="/usr/lib/systemd/boot/efi/linuxx64.efi.stub"
kernel_cmdline="root=UUID=${ROOT_UUID} rw"
EOF
# Install the kernel (this will automatically trigger dracut to generate the UKI)
emerge --verbose sys-kernel/gentoo-kernel-bin# Create fstab using UUIDs for reliability
cat > /etc/fstab << EOF
UUID=${ESP_UUID} /efi vfat defaults,noatime 0 2
UUID=${ROOT_UUID} / ext4 noatime 0 1
EOF# Set hostname
echo "hostname" > /etc/hostname
# Configure hosts file
cat >> /etc/hosts << EOF
127.0.0.1 localhost
::1 localhost
127.0.1.1 hostname.localdomain hostname
EOF
# Set the root user password for the new system
passwd
# Install a networking client and enable it
emerge --verbose net-misc/dhcpcd
systemctl enable dhcpcd
# Generate the machine-id
systemd-machine-id-setup
# Enable default systemd services
systemctl preset-all --preset-mode=enable-only# Install necessary filesystem tools for the ESP
emerge --verbose sys-fs/dosfstools
# I/O scheduler rules
emerge --verbose sys-block/io-scheduler-udev-rules
# Text editor
emerge --verbose app-editors/nano# Install systemd-boot to the ESP
bootctl install
# Configure the loader
cat > /efi/loader/loader.conf << EOF
default @saved
timeout 3
console-mode max
editor no
EOF
# Verify the UKI was created and installed
ls -lh /efi/EFI/Linux/Note: UKIs are automatically detected by systemd-boot, so no manual boot entries are required.
# Emerge the KDE Plasma desktop meta-package
emerge --verbose kde-plasma/plasma-meta
# Enable the SDDM display manager
systemctl enable sddm# Create a new user and add them to important groups
useradd -m -G users,wheel,audio,video,usb -s /bin/bash username
passwd username
# Allow users in the 'wheel' group to use sudo
emerge --verbose app-admin/sudo
echo "%wheel ALL=(ALL:ALL) ALL" > /etc/sudoers# Exit the chroot environment
exit
# Unmount all filesystems cleanly
cd
umount -l /mnt/gentoo/dev{/shm,/pts,}
umount -R /mnt/gentoo
# Reboot into your new Gentoo system
rebootIf the system doesn't boot:
- Boot back into the live environment.
- Mount your partitions:
mount /dev/vda2 /mnt/gentoo mount /dev/vda1 /mnt/gentoo/efi
- Chroot back into your system using the commands from Step 4.
- Inside the chroot, find your installed kernel version:
# Look for a directory like '6.1.57-gentoo' ls /lib/modules - Manually regenerate the UKI, replacing
<kernel-version>with the version from the previous step:dracut --force --uefi --kver <kernel-version>
- Alternatively, simply reinstalling the kernel package will also trigger a rebuild:
emerge --verbose --oneshot sys-kernel/gentoo-kernel-bin
- Verify the UKI file exists and has been updated:
ls -lh /efi/EFI/Linux/ - Exit the chroot, unmount, and reboot.