Gentoo Install

My first Gentoo install.

I like exploring different Linux distributions (distros) because it is a great way to expand my Linux knowledge. For production machines I use Debian for ease of management and stability, but its basic installation doesn’t offer too much of a learning experience because their installer is so good (although creating a bare-bones root file system with debootstrap and building up from there is a good learning experience – another post maybe). Three distros that offer excellent opportunities to expand the depth of your understanding of how a Linux system works are Arch, LFS, and Gentoo. I’ve spent quite a bit of time using Arch and learned a lot from installing and troubleshooting issues with it, and Arch has probably the best wiki with a lot of approachable but in depth information. I’ve also ran through the LFS book a couple of times which builds everything manually, but I’ve never tried building a Gentoo system.

This post is really just notes documenting the first portion of my Gentoo build. After spending a short time going through the Gentoo Handbook, I am impressed with their documentation and the experience thus far.

Created bootable USB flash drive from minimal install ISO using dd.

UEFI booted from USB:

passwd root

Check network:

ping google.com

Start sshd:

/etc/init.d/sshd start

Get IP address:

ip a

From another computer:

ssh root@10.0.1.22

Start a screen session in case ssh connection is interrupted:

screen

List all block devices to determine which device to partition:

lsblk

Recognized /dev/sdb by the way it was partitions from the previous OS install.

parted -a optimal /dev/sdb

Then in parted:

mklabel gpt
unit mib
mkpart primary 1 3
name 1 grub                                                      
set 1 bios_grub on                                               
mkpart primary 3 131
name 2 boot
mkpart primary 131 643
name 3 swap
mkpart primary 643 -1
name 4 rootfs
set 2 boot on
print
quit

Make the file systems. Use fat32 for boot because we are UEFI booting:

mkfs.fat -F 32 /dev/sdb2
mkfs.ext4 /dev/sdb4
mkswap /dev/sdb3
swapon /dev/sdb3

Mount the new root file system.

mount /dev/sdb4 /mnt/gentoo

Check time:

date

Get a multi-lib stage 3 tarball:

cd /mnt/gentoo
wget http://distfiles.gentoo.org/releases/amd64/autobuilds/20191127T214502Z/stage3-amd64-20191127T214502Z.tar.xz
wget http://distfiles.gentoo.org/releases/amd64/autobuilds/20191127T214502Z/stage3-amd64-20191127T214502Z.tar.xz.DIGESTS.asc
gpg --keyserver hkps://hkps.pool.sks-keyservers.net --recv-keys 0xBB572E0E2D182910
gpg --verify stage3-amd64-20191127T214502Z.tar.xz.DIGESTS.asc
grep -A 1 -i sha512 stage3-amd64-20191127T214502Z.tar.xz.DIGESTS.asc
sha512sum stage3-amd64-20191127T214502Z.tar.xz
# then compare outputs to make sure they match

Configure portage. This uses the defaults except adds -march=native to optimize for the native CPU and since I have a quad core, add -j5 to MAKEOPTS:

sed -i 's/^COMMON_FLAGS.*$/COMMON_FLAGS="-march=native -O2 -pipe"/' /mnt/gentoo/etc/portage/make.conf
echo 'MAKEOPTS="-j5"' >> /mnt/gentoo/etc/portage/make.conf
mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf  # chose rsync://rsync.gtlib.gatech.edu/gentoo"
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

Prepare for chroot:

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

Enter chroot:

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

Install base packages:

emerge-webrsync # this failed with a bunch of "snapshot was not found" errors
                # and the  /var/db/repos/gentoo/ dir was empty afterwords
                # should be ok though b/c I did a emerge --sync next
emerge --sync --quiet
eselect news list
eselect news read
eselect profile set default/linux/amd64/17.1/desktop
emerge --ask --verbose --update --deep --newuse @world
# got IMPORTANT: config file '/etc/portage/package.use/zz-autounmask' needs updating.
etc-update # chose -3 to auto-merge; added >=dev-lang/python-2.7.16:2.7 sqlite to zz-automask
# rerun emerge:
emerge --ask --verbose --update --deep --newuse @world # let it run overnight
emerge --depclean # did not find anything, but it was reccomended

Configure timezone and locale:

echo "America/Chicago" > /etc/timezone
emerge --config sys-libs/timezone-data
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
eselect locale set en_US.utf8
env-update && source /etc/profile && export PS1="(chroot) ${PS1}"

Configue kernel

emerge --ask sys-kernel/gentoo-sources
emerge --ask sys-apps/pciutils
cd /usr/src/linux
make menuconfig  # see below for what was enabled/changed/verified
make -j5
make modules_install
make install
emerge --ask sys-kernel/linux-firmware
etc-update  # told it to update /etc/portage/package.license

Enabled/Changed:

GENERIC_CPU to MCORE2
USB_XHCI_HCD
EFI_STUB
EFI_MIXED

Did not enable:

MEI_*
FIREWIRE_OHCI

Verified:

EXT4_FS
EXT4_USE_FOR_EXT2
VFAT_FS
PROC_FS
TMPFS
BLK_DEV_SD
E1000E
SMP
X86_MCE_INTEL
DEVTMPFS
DEVTMPFS_MNT
I2C_SMBUS
SATA_AHCI
HID_GENERIC
USB_HID
USB_SUPPORT
USB_EHCI_HCD
USB_OHCI_HCD
SND_HDA_INTEL
IA32_EMULATION
PARTITION_ADVANCED
EFI_PARTITION
EFI_VARS
EFI
FW_LOADER

fstab:

echo "PARTUUID=a82e87fd-b5ef-41e8-84bf-c6102fdee042 /boot vfat defaults,noatime 0 2" >> /etc/fstab
echo "PARTUUID=a8be4fc3-d7e0-4a57-9d59-0be3dc937109 none swap sw 0 0" >> /etc/fstab
echo "PARTUUID=d4ae1cdb-1882-40d0-ad63-691c690d700f / ext4 defaults,noatime,discard 0 1" >> /etc/fstab

Configure networking:

sed -i 's/localhost/myhost/' /etc/conf.d/hostname
echo 'dns_domain_lo="example.com"' > /etc/conf.d/net
emerge --ask --noreplace net-misc/netifrc # already installed but added to world favorites
echo 'config_eno1="dhcp"' >> /etc/conf.d/net
cd /etc/init.d
ln -s net.lo net.eno1
rc-update add net.eno1 default
sed -i 's/^127.0.0.1.*$/127.0.0.1 myhost.example.com myhost localhost/' /etc/hosts
sed -i 's/^::1.*$/::1 myhost.example.com myhost localhost/' /etc/hosts

Configure/install misc tools:

passwd
emerge --ask app-admin/sysklogd
rc-update add sysklogd default
emerge --ask sys-process/cronie
rc-update add cronie default
emerge --ask sys-apps/mlocate
rc-update add sshd default
emerge --ask sys-fs/dosfstools
emerge --ask net-misc/dhcpcd

Configure/install bootloader:

emerge --ask --verbose sys-boot/grub:2
grub-install --target=x86_64-efi --efi-directory=/boot --removable
grub-mkconfig -o /boot/grub/grub.cfg
# below two lines are necessary to work around my motherboard bug
mkdir -p /boot/EFI/Microsoft/Boot
cp /boot/EFI/BOOT/BOOTX64.EFI /boot/EFI/Microsoft/Boot/bootmgfw.efi

Prepare for reboot into new system:

exit # exit chroot
cd
umount -l /mnt/gentoo/dev{/shm,/pts,}
umount -R /mnt/gentoo
exit # exit screen
exit # end ssh session

Configure new system:

useradd -m -G users,wheel,audio -s /bin/bash myuser
passwd myuser
rm /stage3*
emerge --ask app-misc/tmux
emerge --ask net-irc/weechat

TODO