Skip to content

Instantly share code, notes, and snippets.

@lelegard
Last active February 1, 2024 22:13
Show Gist options
  • Save lelegard/ed398da5979777dc866e88d99787fc1c to your computer and use it in GitHub Desktop.
Save lelegard/ed398da5979777dc866e88d99787fc1c to your computer and use it in GitHub Desktop.
My Gentoo Linux Installation

My Gentoo Linux Installation

As the title implies, this is "my" experience of Gentoo Linux Installation on a virtual machine. There are too many ways to install Gentoo. This Gist is only designed as a reminder if I need to do this again...

Target configuration:

  • English language, French keyboard, located in France.
  • Init system: openrc, old but default one on Gentoo.
  • Desktop: Gnome.

Installation guides

Get base installation media

Virtual machine configuration

  • CPU: 2
  • Memory: 4 GB
  • Disk: 80 GB
  • USB: 3.1
  • CD: installation image
  • No nested virtualization
  • No UEFI, use legacy BIOS

Installation

Boot on install CD => prompt boot:

Press return. Be ready for the keyboard mapping selection. Do not wait without typing or it will boot with US keyboard. Type "18" for "fr" (unless new mappings were added in the meantime) => prompt livecd ~ #

Network: list adapters, verify DHCP-allocated address:

# ip link
# ip addr

Set a temporary root password and start SSH server.

# vi /etc/security/passwdqc.conf
min=1,1,1,1,1
# passwd
# rc-service sshd start

If the interface must be manually configured, assign the expected address first. For instance:

# ip address add 192.168.56.16/24 dev enp0s8

From a terminal of the host system, login to the Gentoo live CD system. Thus, it will be easier to copy/paste commands, easier than typing command on the Gentoo VM console.

# ssh root@X.X.X.X

List disks, partition the disk (assuming /dev/sda): 4 GB swap, root file system for the rest of the disk.

# fdisk -l
# fdisk /dev/sda
o  <-- create a new empty DOS partition table
p  <-- print the partition table
F  <-- list free unpartitioned space
n  <-- add a new partition
   p    <-- primary
   1    <-- partition number
        <-- first sector, use default
   +4G  <-- last sector (4GB after first sector)
t  <-- change a partition type
   82   <-- type: Linux swap
n  <-- add a new partition
   p    <-- primary
   2    <-- partition number
        <-- first sector, use default
        <-- last sector, use default (end of disk)
a  <-- toggle a bootable flag
   2    <-- partition number
p  <-- print the partition table
v  <-- verify the partition table
w  <-- write table to disk and exit

Format swap and root, mount them:

# mkswap /dev/sda1
# mkfs.ext4 /dev/sda2
# swapon /dev/sda1
# mount /dev/sda2 /mnt/gentoo

Or same command block with easier copy/paste:

mkswap /dev/sda1; mkfs.ext4 /dev/sda2
swapon /dev/sda1; mount /dev/sda2 /mnt/gentoo

Get stage3 archive (see sample URL above) and extract it:

# cd /mnt/gentoo
# wget https://bouncer.gentoo.org/fetch/root/all/releases/amd64/autobuilds/20211212T170613Z/stage3-amd64-desktop-openrc-20211212T170613Z.tar.xz
# tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner

Edit compilation flags in Portage config and add the MAKEOPTS line:

# vi etc/portage/make.conf
MAKEOPTS="-j2"

Preparation of base system installation:

# 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
# cp --dereference /etc/resolv.conf /mnt/gentoo/etc/
# 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

Or same command block with easier copy/paste:

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
cp --dereference /etc/resolv.conf /mnt/gentoo/etc/
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

Change root into the new system:

# chroot /mnt/gentoo /bin/bash
# source /etc/profile
# export PS1="(chroot) ${PS1}"

Or same command block with easier copy/paste:

chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(chroot) ${PS1}"

Synchronize Portage:

# emerge-webrsync
# emerge --sync
....
 * IMPORTANT: 10 news items need reading for repository 'gentoo'.
 * Use eselect news read to view new items.

# eselect news list
# eselect news read
# eselect profile list
  ........
  [6]   default/linux/amd64/17.1/desktop/gnome (stable)
  ........
# eselect profile set 6

Install packages (this is where you have to wait a looooooooong time):

# emerge --ask --verbose --update --deep --newuse @world
# emerge --ask --newuse --deep \
      app-editors/vim sys-boot/grub sys-kernel/gentoo-sources \
      gnome-base/gnome gnome-extra/gnome-shell-extension-dash-to-panel x11-base/xorg-drivers \
      dev-vcs/git app-admin/sudo net-misc/dhcpcd sys-fs/e2fsprogs sys-fs/dosfstools \
      app-portage/gentoolkit app-portage/eix
# echo "Europe/Paris" >/etc/timezone
# emerge --config sys-libs/timezone-data
# vi /etc/locale.gen
C.UTF8 UTF-8
en_US.UTF-8 UTF-8
# locale-gen
# eselect locale list
Available targets for the LANG variable:
  [1]   C
  [2]   C.utf8
  [3]   POSIX
  [4]   en_US.utf8
  [5]   C.UTF8 *
  [ ]   (free form)
# eselect locale set 4
# env-update && source /etc/profile && export PS1="(chroot) ${PS1}"

Kernel configuration

# eselect kernel list
Available kernel symlink targets:
  [1]   linux-5.10.76-gentoo-r1
# eselect kernel set 1
# emerge --ask sys-kernel/installkernel sys-kernel/gentoo-kernel-bin

Generate fstab:

# vi /etc/fstab
/dev/sda1   none  swap   sw         0 0
/dev/sda2   /     ext4   noatime    0 1

Network configuration:

# echo 'hostname="vmgentoo"' >/etc/conf.d/hostname
# rc-update add dhcpcd default
# rc-update add sshd default
# cd /etc/init.d
# ln -s net.lo net.enp0s6
# vi /etc/conf.d/net
config_enp0s6="n.n.n.n netmask 255.255.255.0"
# /etc/init.d/net.enp0s6 stop
# /etc/init.d/net.enp0s6 start
# rc-update add net.enp0s6 default

Root password, keyboard, more tools.

# vi /etc/security/passwdqc.conf
min=1,1,1,1,1
# passwd
# vi /etc/conf.d/keymaps
keymap="fr"

Grub bootloader

# grub-install /dev/sda
# grub-mkconfig -o /boot/grub/grub.cfg

Exit the chroot environment and reboot.

# exit
# cd
# umount /mnt/gentoo
# reboot

Create user:

# groupadd _NAME_
# useradd _NAME_ -m -d /home/_NAME_ -g _NAME_
# passwd _NAME_
# echo "_NAME_ ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/_NAME_

Enabling Gnome:

# vi /etc/conf.d/display-manager
DISPLAYMANAGER="gdm"
# rc-update add dbus default
# rc-update add display-manager default
# rc-update add openrc-settingsd default
# rc-update add elogind boot
# gpasswd -a _USERNAME_ plugdev
# gpasswd -a _USERNAME_ video

Enabling French keyboard with Gnome:

user $ dbus-run-session gsettings set org.gnome.desktop.input-sources sources "[('xkb', 'fr')]"
user $ gsettings get org.gnome.desktop.input-sources sources
user $ sudo -i
# su -s /bin/bash gdm
gdm $ dbus-run-session gsettings set org.gnome.desktop.input-sources sources "[('xkb', 'fr')]"
gdm $ gsettings get org.gnome.desktop.input-sources sources

Selected Gentoo admin commands

  • List installed packages:
    • qlist -I
    • equery list '*'
  • List all available packages:
    • equery list -po '*'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment