Gentoo setup2 - hpaluch/hpaluch.github.io GitHub Wiki
Gentoo setup2
Here are my terse instructions for Gentoo setup. I plan to install Gentoo onto SATA disk attached via USB to very fast computer Cubi and later boot same disk on my slower computers (ZotacNano or even dual-Opteron machine).
I always use this profile:
- OpenRC (no systemd allowed)
- Desktop X11 with CTWM Window Manager (used on NetBSD - like old fvwm). Why CTWM - because even Xfce and/or LXDE will not start without D-Bus. And why not NetBSD? Because its Hyperivsor is lacking important features when compared to KVM (PCI passthrough, nested virtualizaiton,...).
Generally I follow:
I currently use Desktop+OpenRC. Typically I look to this mirror for Stage3 tarball:
- https://ftp.linux.cz/pub/linux/gentoo/releases/amd64/autobuilds/current-stage3-amd64-desktop-openrc/
So first we have to download install ISO.
- main page: https://www.gentoo.org/downloads/
- testing: https://distfiles.gentoo.org/releases/amd64/autobuilds/20250928T160345Z/install-amd64-minimal-20250928T160345Z.iso
I will start with VM (virt-manager), but I will attach SATA disk via USB
- host device is
/dev/sdb
- when adding disk in
virt-manager
I will simply specify/dev/sdb
as image path (yes, that easy).
I will simply boot from ISO - network should work automatically. However I will set root's password and run sshd so I coudl copy&paste commands...
- simply run
passwd
to set root's password - next start sshd using:
/etc/init.d/sshd
- to get your IP address run
ip -br -4 a
- I usually start log session (on my client PC from whic I will run SSH client) using
script gentoo-install.log
- now you can login to this gentoo server using
ssh root@IP
Now I have to prepare partitions and filesystem. I will use hybrid system:
- GPT with both BIOS and UEFI support (because I plan to use that disk on 3 machines, 2 have UEFI and 1 have BIOS only)
- ensure that fdisk uses
gpt
- so I did:
fdisk /dev/vda # pass-through to USB SATA disk
Here is my final layout:
Disklabel type: gpt
Device Start End Sectors Size Type
/dev/vda1 2048 10239 8192 4M BIOS boot
/dev/vda2 10240 1058815 1048576 512M EFI System
/dev/vda3 1058816 210774015 209715200 100G Linux filesystem
/dev/vda4 210774016 277882879 67108864 32G Linux swap
Note: it is good idea to have EFI System
partition large, because there could be
some unexpected events (some distributions are putting whole /boot
to EFI etc., or
we will have space if ever BIOS boot
will need to larger...)
Now we have to format 3 partitions (with the exception of BIOS boot
...)
# double check device names!!!
mkfs.vfat -n GEN-EFI /dev/vda2
mkfs.btrfs -L gen-rootfs /dev/vda3
mkswap -L gen-swap /dev/vda4
Now we should activate all formatted filesystems so there will be
automatically generated to /etc/fstab
later...
swapon /dev/vda4
# below is trickery to use subvolume for rootfs in case of btrfs:
btrfs su cr /mnt/@rootfs
btrfs su cr /mnt/@home
# now mount subvolume @rootfs as /
mount -o compress,subvol=@rootfs /dev/vda3 /mnt/gentoo
# same for subvol @home on /home
mkdir /mnt/gentoo/home
mount -o subvol=@home /dev/vda3 /mnt/gentoo/home
# and finally efi
mkdir /mnt/gentoo/efi
mount /dev/vda2 /mnt/gentoo/efi
Now it is time to download and unpack stage file:
- following: https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Stage
- point your browser to https://ftp.linux.cz/pub/linux/gentoo/releases/amd64/autobuilds/current-stage3-amd64-desktop-openrc/ to find latest download URL
- in my case I did:
cd /mnt/gentoo
curl -fLO https://ftp.linux.cz/pub/linux/gentoo/releases/amd64/autobuilds/current-stage3-amd64-desktop-openrc/stage3-amd64-desktop-openrc-20250928T160345Z.tar.xz
tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner
Required copies:
cd /mnt/gentoo
mkdir -p etc/portage/repos.conf
cp usr/share/portage/config/repos.conf etc/portage/repos.conf/gentoo.conf
cp -L /etc/resolv.conf etc
Now here is my etc/portage/package.use/custom
common for all deployments
where I plan to use Wayland with Sway:
# /etc/portage/package.use/custom
# Custom USE flags per app
app-text/ghostscript-gpl -dbus
app-arch/cpio -nls
app-editors/vim -X -acl -crypt -sound
And here is common part (for both Azure build host and Target)
of etc/portage/make.conf
# Do NOT use -fno-strict-aliasing - it breaks glibc!
# see https://bugs.gentoo.org/955635
COMMON_FLAGS="-O2 -pipe"
# other flags keep "as is"
MAKEOPTS="-j8"
USE="vaapi vdpau brotli webp -kde -accessibility -openmp -fortran \
-qmanifest -imap -pop3 -qtegrity -tftp compress-zstd zstd \
logrotate kms gles2 vim-syntax lvm lm-sensors contrib \
layers tray wallpapers -bluetooth -joystick alsa"
VIDEO_CARDS="nouveau intel qxl"
ACCEPT_LICENSE="@FREE @BINARY-REDISTRIBUTABLE"
# It is closest mirror for me - you may need to change it
GENTOO_MIRRORS="http://ftp.fi.muni.cz/pub/linux/gentoo/"
# always build binary packages (useful for example if compiler gets corrupted, etc...)
FEATURES="buildpkg"
# which Binary packages to NOT build:
EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --buildpkg-exclude 'acct-*/* sys-kernel/*-sources virtual/*'"
Now we can enter chroot
simply with:
arch-chroot /mnt/gentoo
source /etc/profile
PS1="(chroot) $PS1"
Now fetch portage archives
# inside chroot
emerge-webrsync
Here is complete /etc/portage/make.conf
from Azure build server chroot:
TODO
Verify that we have proper profile:
$ eselect profile list | fgrep '*'
[3] default/linux/amd64/23.0/desktop (stable) *
Now on build-server we can rebuild world using:
# in chroot of build server
# around 50 packages will be rebuild
emerge --ask --verbose --update --deep --newuse @world
# press 'n'
# foudn all packages that will be rebuild 'R' flag and...
NOTE: To avoid costly rebuilds (due USE flags change) I made small
changes - created /etc/portage/package.use/custom
with:
# avoid costly rebuilds
app-portage/portage-utils qmanifest
dev-db/sqlite -icu
sys-devel/gcc fortran openmp
llvm-runtimes/clang-runtime openmp
x11-libs/gtk+ -vim-syntax
dev-qt/qtbase -brotli
And rerun:
emerge --ask --verbose --update --deep --newuse @world
# answer 'y' if OK
# in my case I have to install/build 45 packages
# it took
Merging changes in /etc/
- use for example https://wiki.gentoo.org/wiki/Dispatch-conf
- run command:
dispatch-conf
Now more setup:
# in chroot:
echo Europe/Prague > /etc/timezone
emerge --config sys-libs/timezone-data
Next:
- edit chroot file
/etc/locale.gen
- I uncommented only
en_US.*
- I uncommented only
- inside chroot run
locale-gen
- verify selected locale:
eselect locale list
- I use
C.UTF-8
(should be default - with asterisk*
)
- I use
- refresh environemnt with:
source /etc/profile PS1="(chroot) $PS1"
Install firmware:
emerge -an sys-kernel/linux-firmware sys-firmware/sof-firmware
Before kernel install grub (because package installkernel
will be able to genereate grub config):
# ensure that GRUB_PLATFORM includes: efi-64 pc
emerge -an sys-boot/grub
# install grub (in my case in BIOS mode, so far):
grub-install /dev/vda
Setup and install installkernel:
echo 'sys-kernel/installkernel dracut grub' >> /etc/portage/package.use/custom
emerge -an sys-kernel/installkernel
Installing kernel source:
- many programs need kernel source in
/usr/src
): - TODO: why it installs xemacs(?)
emerge -an sys-kernel/gentoo-sources sys-apps/pciutils sys-kernel/dracut \ sys-fs/btrfs-progs sys-fs/lvm2
- select only kernel source (it will create symbolic link
/usr/src/linux
needed by apps)eselect kernel list eselect kernel set 1
Generate fstab (required for initramfs/grub that will be run on kernel install):
# OUTSIDE chroot run:
genfstab -U /mnt/gentoo >> /mnt/gentoo/etc/fstab
Building kernel - using config from my project:
# again in chroot:
cd /usr/src
curl -fLO https://github.com/hpaluch/gentoo-files/raw/refs/heads/master/kernels/linux-6.6.30-gentoo/lvefi_defconfig
cp lvefi_defconfig linux/arch/x86/configs
cd linux
make lvefi_defconfig
make menuconfig # finetune details
# build kernel, should also create ramdisk (dracut) and grub entry:
make -j`nproc` && make modules_install && make install
Installing various programs:
emerge -an sys-fs/ncdu app-portage/gentoolkit app-editors/vim app-misc/mc app-admin/sudo \
app-misc/tmux app-admin/sysstat sys-apps/smartmontools \
net-misc/dhcpcd app-admin/rsyslog sys-process/cronie app-shells/bash-completion \
sys-process/lsof
On Target chroot remember to at least set root password:
passwd root
Set proper default editor - create script etc/profile.d/editor.sh
with contents:
export EDITOR=/usr/bin/vim
Source it in chroot:
source /etc/profile.d/editor.sh
And do few changes using visudo
in chroot:
- add
Defaults !fqdn
to avoid DNS lookups on each sudo invocation - uncomment
%wheel ALL=(ALL:ALL) NOPASSWD: ALL
- now setup user and add it to
wheel
group:
# all commands run in Target chroot:
u=YOUR_USERNAME
/usr/sbin/useradd -G wheel -m -s /bin/bash $u
passwd $u
In chroot ensure that neede services will start:
# run in Target chroot
rc-update add dhcpcd default
rc-update add rsyslog default
rc-update add sshd default
X-Window install
It is always usefull to have X-Window as fallback (if Wayland does not work) - we can
follow https://wiki.gentoo.org/wiki/Xorg/Guide - I plan to install X-Window + XFCE and
use startx
to start X-Window and sway
to start Wayland.
NOTE this:
- all my real hardware is NVidia or Intel GPU (no AMD/ATI)
- I plan to also use Gentoo as VM - so qxl, VMware or VirtualBox guest support is wanted.
- here are my settings in
etc/portage/make.conf
INPUT_DEVICES="libinput vmmouse" VIDEO_CARDS="intel nouveau qxl i915 nvidia vesa virtualbox vmware" USE=" ... xvfb xa"
WARNING! In case of my old NVidia GT218 there is bad news, looking at
- https://wiki.gentoo.org/wiki/NVIDIA
- last driver that supports that card is 340
- this should help (but not yet tested) - from https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers:
echo '>x11-drivers/nvidia-drivers-340' >> /etc/portage/package.mask/nvidia-gt218
- PROBLEM: As of Dec 2023 - oldest
nvidia-drivers-X
package isx11-drivers/nvidia-drivers-390.157
, but my card is supported by 340 only... In such case the only "solution" is to remove "nvidia" fromVIDEO_CARDS
...
Following: https://wiki.gentoo.org/wiki/Xorg/Guide First we should check if we have correct flags for Driver:
emerge -pv x11-base/xorg-drivers
When it looks reasonable, building with:
emerge -an x11-base/xorg-server
emerge -an x11-wm/ctwm
echo XSESSION=ctwm > /etc/env.d/90xsession
env-update && source /etc/profile
Additionally I plan to use:
emerge -an x11-apps/xinit x11-terms/xterm
To start X-Window few requirements must be met:
- resolvable hostname - ping below must work properly:
ping `hostname`
- otherwise there will be
xauth
related errors
- otherwise there will be
- due required X-Server privileges, the
elogind
must be running in OpenRC environment (my case)rc-update add elogind boot /etc/init.d/elogind start
- you need to logout and login, because there is
elogind
PAM module executed on login - otherwise X-server will report permission error when accessing
/dev/ttyX
When done you can start X-Window usingstartx
command...
- you need to logout and login, because there is
If mouse and keyboard does not work we need to follow
- https://wiki.gentoo.org/wiki/Libinput
- emerge:
emerge -an x11-misc/xdotool x11-misc/wmctrl
- add your user to
input
group:usermod -a -G input USERNAME
- and login again to become member of
input
group
- and login again to become member of
- to detect PS/2 mouse I needed to reboot machine - than it worked:
libinput list-devices | fgrep -A 1 -i ps/2 Device: ImPS/2 Generic Wheel Mouse Kernel: /dev/input/event15
# Your list will be likely different!
# Answer Yes to make these packages sticky:
emerge -an media-fonts/liberation-fonts x11-apps/xrefresh x11-apps/xrandr
# run again:
Finally we should install QEMU guest agent and SPICE/QXL utilities:
- I have to manually change card type from
Virtio
toQXL
invirt-manager
(some functions not yet work properly with Virtio PV card) - install and run QEMU guest agent:
emerge -an app-emulation/qemu-guest-agent rc-update add qemu-guest-agent default
- and SPICE VDA agent:
emerge -an app-emulation/spice-vdagent rc-update add spice-vdagent default
- reboot system to ensure that all changes will be propagated