Today I’m going to document how I built and installed kernel 4.20.1 a Gentoo laptop, Dell XPS 15 9570.

This blog post is not intended to be a tutorial or even a guide. I’m very new to Gentoo, and have been spoiled by Ubuntu and Fedora for not needing to compile my own kernel. :)

Anyhow, it’s very likely that I’ll need to compile the kernel again on Gentoo, and therefore I think having some sorts of documents is better than nothing at all.

First, let’s backup the current kernel configuration:

#cp /usr/src/linux/.config ~/kernel-config-`uname -r`
# eix gentoo-sources
[I] sys-kernel/gentoo-sources
     Available versions:  
     (4.4.164) 4.4.164^bs
     (4.4.165) ~4.4.165^bs
     (4.4.166) ~4.4.166^bs
     (4.4.167) ~4.4.167^bs
     (4.4.168) ~4.4.168^bs
     (4.4.169) ~4.4.169^bs
     (4.9.140) 4.9.140^bs
     (4.9.143) ~4.9.143^bs
     (4.9.144) ~4.9.144^bs
     (4.9.146) ~4.9.146^bs
     (4.9.147) ~4.9.147^bs
     (4.9.148) ~4.9.148^bs
     (4.9.149) ~4.9.149^bs
     (4.14.83) 4.14.83^bs
     (4.14.87) ~4.14.87^bs
     (4.14.88) ~4.14.88^bs
     (4.14.89) ~4.14.89^bs
     (4.14.90) ~4.14.90^bs
     (4.14.91) ~4.14.91^bs
     (4.14.92) ~4.14.92^bs
     (4.19.14) ~4.19.14^bs
     (4.20.0) ~4.20.0^bs
     (4.20.1) ~4.20.1^bs
       {build experimental symlink}
     Installed versions:  4.14.83(4.14.83)^bs(03:11:54 01/14/19)(symlink -build -experimental)
     Homepage:            https://dev.gentoo.org/~mpagano/genpatches
     Description:         Full sources including the Gentoo patchset for the 4.20 kernel tree

According to the eix’s output, the version of the installed kernel is: 4.14.83 with symlink flag enabled.

 # emerge -av =sys-kernel/gentoo-sources-4.20.1

 * IMPORTANT: 15 news items need reading for repository 'gentoo'.
 * Use eselect news read to view new items.


These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  NS   ~] sys-kernel/gentoo-sources-4.20.1:4.20.1::gentoo [4.14.83:4.14.83::gentoo] USE="symlink -build -experimental" 101874 KiB

Total: 1 package (1 in new slot), Size of downloads: 101874 KiB

The following keyword changes are necessary to proceed:
 (see "package.accept_keywords" in the portage(5) man page for more details)
# required by =sys-kernel/gentoo-sources-4.20.1 (argument)
=sys-kernel/gentoo-sources-4.20.1 ~amd64

Would you like to add these changes to your config files? [Yes/No] 

Autounmask changes successfully written.

 * IMPORTANT: config file '/etc/portage/package.accept_keywords/zz_accept_keywords' needs updating.
 * See the CONFIGURATION FILES and CONFIGURATION FILES UPDATE TOOLS
 * sections of the emerge man page to learn how to update config files.

What’s this zz_accept_keywords? This is an empty file resides

Let’s see the content of zz_accept_keywords:

# cat /etc/portage/package.accept_keywords/._cfg0000_zz_accept_keywords 
# required by =sys-kernel/gentoo-sources-4.20.1 (argument)
=sys-kernel/gentoo-sources-4.20.1 ~amd64

I need to move /etc/portage/package.accept_keywords/._cfg0000_zz_accept_keywords to /etc/portage/package.accept_keywords/gentoo-sources.

# mv /etc/portage/package.accept_keywords/{._cfg0000_zz_accept_keywords,gentoo-sources}
# emerge -av =sys-kernel/gentoo-sources-4.20.1

 * IMPORTANT: 15 news items need reading for repository 'gentoo'.
 * Use eselect news read to view new items.


These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  NS   ~] sys-kernel/gentoo-sources-4.20.1:4.20.1::gentoo [4.14.83:4.14.83::gentoo] USE="symlink -build -experimental" 101874 KiB

Total: 1 package (1 in new slot), Size of downloads: 101874 KiB

Would you like to merge these packages? [Yes/No] 

Confirm that new installed kernel is selected, if not run eselect set NUMBER:

# eselect kernel list
Available kernel symlink targets:
  [1]   linux-4.14.83-gentoo
  [2]   linux-4.20.1-gentoo *

# ls -l /usr/src/linux
lrwxrwxrwx 1 root root 19 Jan 14 20:27 /usr/src/linux -> linux-4.20.1-gentoo

(Note, I thought the [1] should have been selected. I’m not quite sure why the new kernel is automatically selected.)

Copy old config:

# cp /etc/kernels/kernel-config-x86_64-4.14.83-gentoo /usr/src/linux/.config

To use the configuration of the old kernel with the new kernel, it needs to be converted. The conversion can be done by running either make silentoldconfig or make olddefconfig. Use either, not both. In my case, I use make olddefconfig:

# cd /usr/src/linux
# make olddefconfig
  HOSTCC  scripts/kconfig/conf.o
  YACC    scripts/kconfig/zconf.tab.c
  LEX     scripts/kconfig/zconf.lex.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf  --olddefconfig Kconfig
#
# configuration written to .config
#

For kernel 4.14.83, I need to set CONFIG_DRM_I915_ALPHA_SUPPORT=y to get the Intel i965 to work for this Dell XPS 15 9570.

# grep ALPHA .config
CONFIG_DRM_I915_ALPHA_SUPPORT=y

This is no longer needed for kernel 4.20 and newer, and should be removed. Next, I can start building the kernel:

# time genkernel --luks --lvm --save-config all
...
...
*         >> Finalizing cpio...
*         >> Compressing cpio data (.xz)...
* 
* Kernel compiled successfully!
* 
* Required Kernel Parameters:
*     root=/dev/$ROOT
* 
*     Where $ROOT is the device node for your root partition as the
*     one specified in /etc/fstab
* 
* If you require Genkernel's hardware detection features; you MUST
* tell your bootloader to use the provided INITRAMFS file.

* WARNING... WARNING... WARNING...
* Additional kernel cmdline arguments that *may* be required to boot properly...
* add "dolvm" for lvm support
* With support for several ext* filesystems available, it may be needed to
* add "rootfstype=ext3" or "rootfstype=ext4" to the list of boot parameters.

* Do NOT report kernel bugs as genkernel bugs unless your bug
* is about the default genkernel configuration...
* 
* Make sure you have the latest ~arch genkernel before reporting bugs.

real	15m58.129s
user	28m21.560s
sys	3m38.887s

The last step is to generate the grub menu to include the new built kernel.

# grub-mkconfig -o /boot/grub/grub.cfg 
Generating grub configuration file ...
Found linux image: /boot/kernel-genkernel-x86_64-4.20.1-gentoo
Found initrd image: /boot/initramfs-genkernel-x86_64-4.20.1-gentoo
Found linux image: /boot/kernel-genkernel-x86_64-4.14.83-gentoo
Found initrd image: /boot/initramfs-genkernel-x86_64-4.14.83-gentoo
done

Ref: