Introduction

The enthusiasm of the Linux kernel to follow up with support for AMD Ryzen™ mobile low-voltage CPUs seems to match the enthusiasm of the few AMD Ryzen™ laptops on the market. While AMD Ryzen™ desktop CPUs have been better supported since Linux 4.11, kernels below 4.17 do not even load properly on their mobile CPUs. At the time of writing (2018.07), most distributions have < 4.17 as their default kernel version, so the few radical Linux distributions that exist are my only options, and Gentoo is one of them.

After going through the Gentoo Handbook, which is much more friendly than the previous one, and with the need to toss it around, I decided to use Gentoo. So my interest in using Gentoo was ignited again 😂, and I have documented a few installation tips in this article.

Installing images with Arch Linux

The official rolling update install image provided by Gentoo does not support UEFI booting. It does provide a UEFI-compatible image from 2016. However, I know that this image will not load properly on my device (the kernel is too old for AMD Ryzen™ mobile platforms), so using the Arch image with the latest kernel seems to be the best option.

You may want to know that Gentoo Handbook has been updated. “As of August 23, 2018 the official Minimal CDs are capable of booting in UEFI mode. Previous versions boot in BIOS (MBR) mode only. Readers looking to make their system UEFI bootable must download the latest ISO.” As it mentions, the latest ISO supports UEFI boot. It is unnecessary to use Arch Linux installation image from now on.

Partitioning and preparing to boot with EFISTUB

My partitioning scheme is to follow the Preparing the disks section of the Handbook, mount the /root partition to /mnt/gentoo and refer to EFI system partition to mount the EFI partition to /mnt/gentoo/esp and then /esp/EFI/Gentoo to /mnt/gentoo/boot.

This way, while keeping the ESP partition tidy, there is no need to manually update the files in /boot after the kernel files have been updated. All you need to do is copy the set of files in /boot to /esp/EFI/Gentoo the old way.

Downloading the Stage3 image

See Network configuration for the network configuration section.

The Handbook recommends using Links to access the mirrors to download the Stage3 image; the Arch Linux image does not come with Links, so you should first install Lynx or Links using pacman to do this. I did this by copying the downloaded Stage3 image to the boot disk and then to the /mnt/gentoo directory when I made the Arch Linux boot disk.

Modify precompilation parameters

You need to add or change some parameters in make.conf to add support for AMD Ryzen™.

Adding znver1 after -march in CFLAGS is a mandatory parameter for AMD Ryzen™ CPUs. If the device uses Vega’s GPU, then the VIDEO_CARDS parameter radeonsi should be added. Laptop users should add Synaptics support. In addition to that, the very fast Tuna 🐟 is chosen for GENTOO_MIRRORS and the MAKEOPTS parameter follows the CPU core count plus one, i.e. -j5 in the case of AMD Ryzen™ 2700U.

The following is an example of a complete make.conf.

1
2
3
4
5
6
7
CFLAGS="-march=znver1 -O2 -pipe"
CXXFLAGS="${CFLAGS}"
MAKEOPTS="-j5"
VIDEO_CARDS="amdgpu radeonsi"
INPUT_DEVICES="evdev synaptics"
LANGUAS="zh_CN"
GENTOO_MIRRORS="https://mirrors.tuna.tsinghua.edu.cn/gentoo"

Information about other options can be found in Configuring compile options

Rsync Mirrors selection

Gentoo allows the address of the rsync mirror server to be specified by editing the configuration file of the portage repository. You can of course choose either the tuna or USTC source.

Curiosity led me to look through the official Gentoo page Gentoo rsync mirrors, but I did not find any mirrors from mainland China, perhaps because the existing mirrors from mainland China, both university and enterprise, do not reach Gentoo. Perhaps because the existing mirrors from mainland China, whether universities or enterprises, do not meet Gentoo’s standards. However, the speed of Taiwan’s sources in mainland China is hard to be complimented. I accidentally found the rsync source provided by KAIST. Although it only supports IPv4, the speed is very satisfactory. This is an unexpected discovery.

🎉 Congratulations to Tsinghua University for being the only available rsync mirror in mainland China, now that’s a better choice (2019.01).

About –make-rslave

Mounting the necessary filesystems, it is mentioned that enabling Systemd support requires -mount followed by the -make-rslave argument. The man page of the mount command indicates that this will recursively give the directory the propagation type of slave, i.e. the directory, including all its subdirectories, will follow master changes without notifying itself when it changes and does not notify master of changes when it changes itself.

If you are not using Systemd, you can also add this parameter so that you cannot use umount -R to forcibly unmount the partition.

Selecting a Profile

When using eselect to select a profile, it is important to keep an eye on the kernel version. For Gentoo, at the time of writing (2018.07) the 4.17 version of the Linux kernel is still an experimental kernel, so the options are at the bottom of the list.

If, like me, you intend to install Gentoo minimally, you should choose the option with the fewest additional installation items (i.e., the shortest text). In particular, avoid the option with the desktop environment, even if you need it later, and it is not recommended to place this task in the installation process to avoid overloading the CPU with work for a short period of time. People don’t want their laptops to personally cook their hands into ironclad dog paws.

Configuration of USE Flags

USE Flags is the beauty of Gentoo, it offers the possibility to streamline the system, helping to keep it simple and maximize efficiency. But its configuration is not a quick fix. I tend to set fewer global USE Flags, and local USE Flags for each package.

This is a result of a certain amount of maintenance time, but at the beginning you can also configure -qt4 -qt5 -kde to avoid some unnecessary dependencies. In addition, the USE Flags page in the Handbook is a good place to get a deeper understanding.

Manually compiling the kernel

Choosing genkernel is a relatively painless way to compile the kernel, but it means that the kernel will not be able to turn on AMD Ryzen™ related parameters. A conservative approach would be to genkernel all and then add the relevant kernel parameters and recompile the kernel once more. The disadvantage of this approach is that it is time and resource consuming, and the compiled kernel is not small and elegant.

Start by installing the AMD Zen microcode via emerge linux-firmware.

1
emerge --ask sys-kernel/linux-firmware

Don’t forget to install AMD GPUs drivers.

1
emerge --ask x11-drivers/xf86-video-amdgpu

Use menuconfig to enable several options mentioned below to provide support for AMD Ryzen™ CPU and AMD GPUs, as well as kernel options related with EFI stub kernel.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
Processor type and features --->
    [*] Symmetric multi-processing support
    [*] AMD ACPI2Platform devices support
    [*] /dev/cpu/microcode - microcode support
    [*] AMD microcode patch loading support
    [*] MTRR (Memory Type Range Register) support

    Processor family (Opteron/Athlon64/Hammer/K8) --->
        (X) Opteron/Athlon64/Hammer/K8

    [*] Supported processor vendors --->
        [*] Support AMD processors (NEW)

    [*] SMT (Hyperthreading) scheduler support
    [*] Multi-core scheduler support
    [*] Machine Check / overheating reporting
    [*] AMD MCE features

Processor family (MZEN) --->
(X) AMD Zen

Performance monitoring --->
<*> AMD Processor Power Reporting Mechanism

    [*] AMD microcode loading support

    [*] EFI runtime service support
    [*] EFI stub support
    [ ] EFI mixed-mode support

    [*] Built-in kernel command line
    (root=PARTUUID=)

Power management and ACPI options --->
    CPU Frequency scaling --->
        <*> AMD Opteron/Athlon64 PowerNow!
        <*> AMD frequency sensitivity feedback powersave bias

Device Drivers --->
    Generic Driver Options --->
        (amd-ucode/microcode_amd_fam17h.bin) External firmware blobs to build into the kernel binary
        (/lib/firmware) Firware blobs root directory

    Graphics support --->
        <*/M> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) --->
            [*] Enable legacy fbdev support for your modesetting driver
        <> ATI Radeon
         AMD GPU
            [ /*] Enable amdgpu support for SI parts
                (only needed for Southern Islands GPUs with the amdgpu driver)
            [ /*] Enable amdgpu support for CIK parts 
                (only needed for Sea Islands GPUs with the amdgpu driver)
            [*] Enable AMD powerplay component
            
            ACP (Audio CoProcessor) Configuration --->
            [*] Enable AMD Audio CoProcessor IP support (CONFIG_DRM_AMD_ACP)

            Display Engine Configuration --->
                [*] AMD DC - Enable new display engine
                [ /*] DC support for Polaris and older ASICs
                    (only needed for Polaris, Carrizo, Tonga, Bonaire, Hawaii)
                [ /*] AMD FBC - Enable Frame Buffer Compression
                [ /*] DCN 1.0 Raven family
                    (only needed for Vega RX as part of Raven Ridge APUs)
        <*/M> HSA kernel driver for AMD GPU devices
        
    <*/M> Sound card support --->
        <*/M> Advanced Linux Sound Architecture --->
            [*] PCI sound devices --->
                HD-Audio --->
                    <*> HD Audio PCI
                    [*] Support initialization patch loading for HD-audio
                    <*> whatever audio codec your soundcard needs
                    <*> Build HDMI/DisplayPort HD-audio codec support
                (2048) Pre-allocated buffer size for HD-audio driver

Firmware Drivers --->
    EFI (Extensible Firmware Interface) Support --->
        <*> EFI Variable Support via sysfs

[*] IOMMU Hardware Support --->
    [*] AMD IOMMU support
    <*> AMD IOMMU Version 2 driver

-*- Enable the block layer --->
    Partition Types --->
        [*] Advanced partition selection
        [*] EFI GUID Partition support

Built-in kernel command line in Processor type and features needs to be filled in with paths to /root and initrd, like

1
root=/dev/nvme0n1p3 rw initrd=/EFI/Gentoo/initramfs-linux.img

About Ryzen, AMDGPU and AMD_microcode of the chapters in the Handbook provide a great deal of help for working on the content of this section.

Creating fstab file

If following configuration for EFISTUB above, state the binding mounts on the EFI partition in fstab file. Here is an example:

1
2
3
4
/dev/nvme0n1p1   /esp   vfat    defaults,noatime    0   0
/esp/EFI/Gentoo  /boot  none    defaults,bind       0   0
/dev/nvme0n1p2   none   swap    sw                  0   0
/dev/nvme0n1p3   /      btrfs   ssd,noatime         0   1

It is recommended to use blkid to get the respective UUID of the file system to replace its partition or device name, remembering to add the UUID= prefix. If the SSD supports TRIM commands, you can add the mount parameter discard to improve its read/write performance. If you are using Btrfs as a file system, you can add the mount parameter ssd, but according to the Btrfs Wiki on [optimization for SSD](https://btrfs.wiki.kernel.org/index.php/FAQ#Is_Btrfs_ optimized_for_SSD.3F), adding the ssd parameter will not support TRIM/discard, and the official recommendation is to use ssd for better compatibility.

Add UEFI boot portal

For the UEFI boot portal, the recommendation of the Gentoo Handbook and other distribution wikis is to use efibootmgr to manage it. efibootmgr is really simple and convenient, but it does not recognize nvme device partition information, e.g. /dev/nvme0n1p1 is an illegal disk parameter. Since efibootmgr has a fondness for sda, I added the entry manually using the Shell according to the section UEFI Shell.

After configuring the network according to the Handbook, don’t forget to install the wireless network related packages, it won’t be elegant to look around for a network cable and crouch by the router 😎.

1
emerge --ask net-wireless/iw net-wireless/wpa_supplicant

Conclusion

That said, I probably wouldn’t have gotten on board with Gentoo if AMD Ryzen™ hadn’t given me a good reason to do so. Either way, thanks for the wonderful experience. Stay tuned for the next few months 💗