Backup READMEv3 - dpopchev/howto-quick-setup-gentoo GitHub Wiki

Wiki in a single file

Following below is the initial notes file

Introduction

Gentoo installation cheat sheet in form of code snippets and hyperlinks.

Main resources:

Configuring the network

Handbook

Applicable if installation using minimal .

Check for summary of methods

  • Gentoo Live CD
    ip addr                     # see interface names
    net-setup ${NET_INTERFACE}  # try auto config
    

Preparing the disks

Handbook

Partitioning

Handbook

Target partitioning

  • GPT table
  • EFI system, FAT32, ~256M
  • Linux swap, ~ available RAM
  • Root and others, ext4

Notes:

List storage devices with their filesystem types.

lsblk -o +fstype,label   

Disable any swap partition that is active.

test $(swapon --summary | head --bytes=1 | wc --bytes) -ne 0 \
  && swapoff $(swapon -s | grep --perl-regexp --only-matching '\/dev\/sd\w+')

Make sure you have booted with a UEFI machine if you choose ‘gpt’.

ls /sys/firmware | grep --perl-regexp --quiet '\befi\b && echo 'Safe to poceed with GPT table'

If the command above does not say it safe, you should reserch more

Set gpt table on target disc.

parted /dev/${TARGET_DISC} mklabel gpt  # 

Subsequent commands will assume sda.

Partition

parted /dev/sda mkpart efi fat32 1MiB 512MiB set 1 esp on
parted /dev/sda mkpart swap linux-swap 512MiB 8GiB
parted /dev/sda mkpart gentoo ext4 8GiB 100%

Create filesystems

Handbook

parted does not create filesystems, only uses the info to optimize parttions. See handbook link above.

mkfs.vfat -F 32 /dev/sda1   # efi
mkfs.ext4 /dev/sda3         # / of gentoo
mkswap /dev/sda2            # swap

Root and swap partition

Handbook

Activate swap

swapon /dev/sda2    

Mount root partition

mkdir --parents /mnt/gentoo && mount /dev/sda3 /mnt/gentoo 

Install stage tarball

Handbook

Update date and time

Handbook

If the live medium is somehow off.

  • Manual
    date 100313162016
    
  • Automatic, assumes Gentoo Live CD
    ntpd -q -g
    

Download tarball

wget ${LINK}

Verify and validate

Unpack tarball

Handbook

  • Gentoo live cd
    tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner -C /mnt/gentoo 
    
  • non Gentoo medium
    tar --numeric-owner --xattrs -xvJpf stage3-*.tar.xz -C /mnt/gentoo 
    

Installing the Gentoo base system

Handbook

Mounting the necessary filesystems

Handbook

/proc

  • Gentoo Live CD
    mount --types proc /proc /mnt/gentoo/proc 
    
  • non Gentoo medium
    mount -o bind /proc /mnt/gentoo/proc
    

/sys

mount --rbind /sys /mnt/gentoo/sys 
mount --make-rslave /mnt/gentoo/sys 

/dev

mount --rbind /dev /mnt/gentoo/dev 
mount --make-rslave /mnt/gentoo/dev 

/dev/shm for non Gentoo Live CD

test -L /dev/shm && rm /dev/shm && mkdir /dev/shm 
mount --types tmpfs --options nosuid,nodev,noexec shm /dev/shm 
chmod 1777 /dev/shm

/dev/shm for Ubuntu live cd note here regarding Python bug for broken sem_open()

mount --rbind /run/shm /mnt/gentoo/run/shm

Copy DNS info

Handbook

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

Entering the new environment

Handbook

  • Gentoo Live CD
    chroot /mnt/gentoo /bin/bash 
    source /etc/profile 
    export PS1="(chroot) ${PS1}"
    
  • non Gentoo Live CD
    chroot /mnt/gentoo /bin/env -i TERM=$TERM /bin/bash 
    env-update 
    source /etc/profile 
    export PS1="(chroot) $PS1" 
    

Mounting partitions to end points

mount /dev/sda1 /boot

NOTE Subsequent commands assume working in the chroot env, if not otherwise said.

Configuring Portage

Handbook

Ebuild repository

Handbook

mkdir --parents /etc/portage/repos.conf
cp /usr/share/portage/config/repos.conf /etc/portage/repos.conf/gentoo.conf

Installing and updating a Gentoo ebuild repository snapshot

Handbook

emerge-webrsync
emerge --sync --quiet

Get faouvorite editor

emerge -av vim

Make conf

Accept keywords

Gentoo wiki

Global unstable keywords

grep -Pi accept_keywords /etc/portage/make.conf
ACCEPT_KEYWORDS="~amd64"

Accept license

Handbook Gentoo wiki

Global unstable keywords

grep -Pi accept_license /etc/portage/make.conf
ACCEPT_LICENSE="-* @FREE"

Optimization flags

Flags:

  • -O2

    -O2 controls the overall level of optimization, -O2 is recommended level of optimization unless the system has special needs

  • -pipe

    Incraces compilation process by telling the compiler to use pipes instead of temporary files

  • -march=native

    Enables auto-detection of the CPU's architecture

    Check what GCC "native" know about your CPU:

    gcc -v -E -x c /dev/null -o /dev/null -march=native 2>&1 | grep /cc1
    

End result:

grep -iP flags /etc/portage/make.conf
COMMON_FLAGS="-O2"
COMMON_FLAGS="${COMMON_FLAGS} -pipe"
COMMON_FLAGS="${COMMON_FLAGS} -march=native"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"

CPU feature flags

The CPU_FLAGS_X86 variable informs Portage about the CPU flags (features) permitted by the CPU

emerge --ask --oneshot app-portage/cpuid2cpuflags
perl -ni -e 'print unless /^[:blank:](/dpopchev/howto-quick-setup-gentoo/wiki/:blank:)*CPU_FLAGS_X86/' /etc/portage/make.conf                        # rm if present
cpuid2cpuflags | perl -pe 's/(?<=[:]\ )([\w[:blank:]]+)/"$1"/; s/[:]/\ =/;' >> /etc/portage/make.conf # append detected flags

Portage features

Features:

  • candy

    Enable a special progress indicator when emerge.

  • downgrade-backup

    Create a backup of the installed version before it is unmerged (if a binary package of the same version does not already exist)

  • unmerge-backup

    Create a backup of each package before it is unmerged (if a binary package of the same version does not already exist)

End result:

grep -P FEATURE /etc/make.conf
FEATURE="${FEATURE} candy"
FEATURE="${FEATURE} downgrade-backup"
FEATURE="${FEATURE} unmerge-backup"

NOTE:

Emerge default options

Default options

  • --usepkg=y

    tells emerge to use binary packages (from $PKGDIR) if they are available

  • --binpkg-changed-deps=y

    Tells emerge to ignore binary packages for which the corresponding ebuild dependencies have changed since the packages were built

  • --binpkg-respect-use=y

    Tells emerge to ignore binary packages if their USE flags don't match the current configuration.

  • --quiet=y

    Results may vary, but the general outcome is a reduced or condensed output from portage's displays

  • --verbose=y

    Currently this flag causes emerge to print out GNU info errors, if any, and to show the USE flags that will be used for each package when pretending

  • --keep-going=y

    Continue as much as possible after an error. See also --resume and --skipfirst

  • --jobs=${NPROC} --load-average=${NPROC}

    emerge runs NPROC jobs at a time and try to keep the load average of the system less than ${NPROC}

End result:

grep -P EMERGE_DEFAULT_OPTS /etc/make.conf
EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --usepkg=y"
EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --binpkg-changed-deps=y"
EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --binpkg-respect-use=y"
EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --quiet=y"
EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --verbose=y"
EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --keep-going=y"
EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --jobs=${NPROC} --load-average=${NPROC}"

Makeopts

Parallel build:

  • MAKEOPTS

    defines how many parallel compilations should occur when installing a package

End result:

grep -P MAKEOPTS /etc/make.conf
MAKEOPTS="--jobs=${NPROC} --load-average=${NPROC}"

Mirrors

emerge --oneshot mirrorselect
mirrorselect -s5 -b100 -D # find top 5 fastes

Localization

Timezone

Handbook

OpenRC:

ls /usr/share/zoneinfo
echo "Europe/Sofia" > /etc/timezone
emerge --config sys-libs/timezone-data

Locale generation

See supported locales

less  /usr/share/i18n/SUPPORTED

Add target locales

grep -iP 'en_US|bg_BG' /usr/share/i18n/SUPPORTED >> /etc/locale.gen

Generate

locale-gen

Select

eselect locale list
eselect locale set 4
eselect locale show
env-update
source /etc/profile
export PS1="(chroot) ${PS1}

Use L10N in to specify extra localization support, commonly used for downloads of additional language packs by packages. Gentoo wiki

Use

Handbook

General tools

emerge -av app-portage/gentoolkit app-portage/eix app-portage/elogv app-portage/genlop app-portage/portage-utils

Profile

Handbook

A profile is a building block for any Gentoo system. Not only does it specify default values for USE, CFLAGS, and other important variables, it also locks the system to a certain range of package versions

eselect profile list
eselect profile set 5 # generic desktop
eselect profile show

Pre kernel config

Handbook

Better update world set after setting profile.

Play with euse or others to fine tune default USE flags and similar, e.g.

euse -D gnome kde plasma # drop support for main DE if they will not be used
emerge --ask --verbose --update --deep --newuse @world