Dealing with the kernel image and kernel source code in Sabayon Linux

Some Sabayon Linux users do not know the particulars of the Linux kernel installation or how to upgrade the kernel image. A recent post by a new user in the Sabayon Linux Forums illustrates this (translated from the German):

I’m just setting up my first sabayon box.

In the manual you should see which kernel is selected with:

eselect kernel list

But this is empty for me:

(not found)

When installing one or other packages I also already have a corresponding error message. What am I doing wrong?

The command ‘eselect kernel list‘ lists the versions of kernel source code currently installed (directories such as /usr/src/linux-4.8.17-sabayon/, /usr/src/linux-4.9.38-sabayon/ or whatever) and indicates to which kernel source code directory the symlink /usr/src/linux/ is currently pointing (see Kernel/Configuration – Set symlink in the Gentoo Linux Wiki).

My guess is that this user wanted to rebuild the kernel image. Anyway, the situation in Sabayon Linux he described occurs as a result of either not having installed the kernel source code or not having installed the version of kernel source code corresponding to the version of the installed kernel image.

Before I go into detail on how to do the above, it is essential to understand the basics of the Entropy package management system and how to maintain a sane installation in Sabayon Linux. You should regularly: a) update the local database containing a list of available packages and their versions; b) upgrade installed packages to their latest available version; c) check and fix dependencies and libraries; d) remove any old versions of installed packages:

root # equo update
root # equo upgrade
root # equo conf update
root # equo deptest
root # equo libtest
root # equo upgrade --purge
root # equo cleanup

Do not blindly enter the above commands if you do not know what they do; first read the explanations in the list of equo functions in the Sabayon Linux Wiki.

I have found that sometimes the command ‘equo upgrade --purge‘ does not report all the packages that have to be removed manually. I therefore repeat the command a few times until no more packages are listed for removal.

Right, now let’s look at why the aforementioned Sabayon Linux user was in trouble…

If you happen to have the directory /boot on a separate partition to / (root) and you specified in the file /etc/fstab that /boot should not be mounted automatically when the machine boots, do not forget to mount the boot partition first.

I would see the same message as the aforementioned Sabayon Linux user if the kernel image and source code were not set up correctly in my Sabayon Linux installation:

sabayon fitzcarraldo # eselect kernel list
Available kernel symlink targets:
  (none found)
sabayon fitzcarraldo #

Obviously a kernel image must be present, so first let’s check which version of the kernel image package is installed:

sabayon fitzcarraldo # equo search --installed linux-sabayon
╠  @@ Searching...
╠      @@ Package: sys-kernel/linux-sabayon-4.8.17 branch: 5, [__system__]
╠          Installed:     version: 4.8.17 ~ tag: NoTag ~ revision: 0
╠          Slot:          4.8
╠          Homepage:      https://github.com/Sabayon/kernel
╠          Description:   Official Sabayon Linux Standard
╠                         kernel image
╠          License:       GPL-2 freedist
╠   Keywords:  linux-sabayon
╠   Found:     1 entry
sabayon fitzcarraldo #

As you can see above, Version 4.8.17 of the kernel image package was installed in my case.

Note that the kernel source code is not installed by default in Sabayon Linux, so my guess is that the aforementioned user didn’t have the kernel source code installed. Here’s how to find out which version of the kernel source code package is installed, if any:

sabayon fitzcarraldo # equo search --installed sabayon-sources
╠  @@ Searching...
╠      @@ Package: sys-kernel/sabayon-sources-4.11.10 branch: 5, [__system__]
╠          Installed:     version: 4.11.10 ~ tag: NoTag ~ revision: 0
╠          Slot:          4.11
╠          Homepage:      https://github.com/Sabayon/kernel
╠          Description:   Official Sabayon Linux Standard
╠                         kernel sources
╠          License:       GPL-2 freedist
╠   Keywords:  sabayon-sources
╠   Found:     1 entry
sabayon fitzcarraldo #

As you can see above, in my case I had previously installed Version 4.11.10 of the kernel source code, and it didn’t correspond to the kernel image in use.

If you want to rebuild the kernel, you also need to have the linux kernel headers installed, and those are not installed by default in Sabayon Linux, so let’s check if that package is already installed while we’re at it:

sabayon fitzcarraldo # equo search --installed linux-headers
╠  @@ Searching...
╠      @@ Package: sys-kernel/linux-headers-4.4 branch: 5, [__system__]
╠          Installed:     version: 4.4 ~ tag: NoTag ~ revision: 0
╠          Slot:          0
╠          Homepage:      https://www.kernel.org/
╠                         https://www.gentoo.org/
╠          Description:   Linux system headers
╠          License:       GPL-2
╠   Keywords:  linux-headers
╠   Found:     1 entry
sabayon fitzcarraldo #

As you can see above, in my case I had previously installed Version 4.4 of the linux kernel headers. However, if you don’t already have the package installed, install it:

sabayon fitzcarraldo # equo install linux-headers
╠  @@ Calculating dependencies...
╠  ## [R] [sabayon-weekly] sys-kernel/linux-headers-4.4|0   [4.4|0]
╠  @@ Packages needing to be installed/updated/downgraded: 1
╠  @@ Packages needing to be removed: 0
╠  @@ Download size: 937.6kB
╠  @@ Freed disk space: 0.0b
╠  @@ You need at least: 1.9MB of free space
╠  ::: >>>  (1/1) 1 package
╠    ## Downloading: 1 package
╠    ## ( mirror #1 ) [sys-kernel:linux-headers-4.4.150ec398796671a9b475328e5ae3f180b9b096c3~0.tbz2] @ http://na.mirror.garr.it
╠   ## Aggregated download: 1 item
╠    # [1] na.mirror.garr.it => sys-kernel:linux-headers-4.4.150ec398796671a9b475328e5ae3f180b9b096c3~0.tbz2
╠    ## Checking package checksum...
╠       : [sys-kernel:linux-headers-4.4.150ec398796671a9b475328e5ae3f180b9b096c3~0.tbz2] GPG validated
╠       : SHA1 disabled
╠       : [sys-kernel:linux-headers-4.4.150ec398796671a9b475328e5ae3f180b9b096c3~0.tbz2] SHA256 validated
╠       : SHA512 disabled
╠    ## ( mirror #1 ) [sys-kernel:linux-headers-4.4.150ec398796671a9b475328e5ae3f180b9b096c3~0.tbz2] success @ http://na.mirror.garr.it
╠    ##  Aggregated transfer rate: 1.3MB/second
╠  +++ >>>  (1/1) sys-kernel/linux-headers-4.4
╠    ## Unpacking: sys-kernel:linux-headers-4.4.150ec398796671a9b475328e5ae3f180b9b096c3~0.tbz2
╠    ## Package phase: setup
╠    ## Package phase: preinstall
╠    ## Installing package: sys-kernel/linux-headers-4.4
╠    ## [Linux system headers]
╠    ## Updating installed packages repository: sys-kernel/linux-headers-4.4
╠    ## Cleaning previously installed application data.
╠    ## Package phase: postremove
╠    ## Package phase: postinstall
╠    ## Cleaning: sys-kernel/linux-headers-4.4
╠  @@ Installation complete.
╠  @@ No configuration files to update.
sabayon fitzcarraldo #

To make sure you have the latest versions of the packages sys-kernel/linux-sabayon (the kernel image) and sys-kernel/sabayon-sources (the kernel source code), install the packages as follows:

sabayon fitzcarraldo # equo install linux-sabayon sabayon-sources
╠  @@ Calculating dependencies...
╠  ## [N] [sabayon-weekly] sys-kernel/linux-sabayon-4.11.10|0
╠  ## [R] [sabayon-weekly] sys-kernel/sabayon-sources-4.11.10|0   [4.11.10|0]
╠  @@ Packages needing to be installed/updated/downgraded: 2
╠  @@ Packages needing to be removed: 0
╠  @@ Download size: 198.9MB
╠  @@ Used disk space: 211.3MB
╠  @@ You need at least: 609.1MB of free space
╠  ::: >>>  (1/1) 2 packages
╠    ## Downloading: 2 packages
╠    ## ( mirror #1 ) [sys-kernel:linux-sabayon-4.11.10.1f22c24cc709872f47d62d3c9e44af879fe18888~0.tbz2] @ http://na.mirror.garr.it
╠    ## ( mirror #1 ) [sys-kernel:sabayon-sources-4.11.10.bd94789f59b1e0b33118e122a23a0164c7205b8a~0.tbz2] @ http://na.mirror.garr.it
╠   ## Aggregated download: 2 items
╠    # [1] na.mirror.garr.it => sys-kernel:linux-sabayon-4.11.10.1f22c24cc709872f47d62d3c9e44af879fe18888~0.tbz2
╠    # [2] na.mirror.garr.it => sys-kernel:sabayon-sources-4.11.10.bd94789f59b1e0b33118e122a23a0164c7205b8a~0.tbz2
╠    ## Checking package checksum...
╠       : [sys-kernel:linux-sabayon-4.11.10.1f22c24cc709872f47d62d3c9e44af879fe18888~0.tbz2] GPG validated
╠       : SHA1 disabled
╠       : [sys-kernel:linux-sabayon-4.11.10.1f22c24cc709872f47d62d3c9e44af879fe18888~0.tbz2] SHA256 validated
╠       : SHA512 disabled
╠    ## Checking package checksum...
╠       : [sys-kernel:sabayon-sources-4.11.10.bd94789f59b1e0b33118e122a23a0164c7205b8a~0.tbz2] GPG validated
╠       : SHA1 disabled
╠       : [sys-kernel:sabayon-sources-4.11.10.bd94789f59b1e0b33118e122a23a0164c7205b8a~0.tbz2] SHA256 validated
╠       : SHA512 disabled
╠    ## ( mirror #1 ) [sys-kernel:linux-sabayon-4.11.10.1f22c24cc709872f47d62d3c9e44af879fe18888~0.tbz2] success @ http://na.mirror.garr.it
╠    ## ( mirror #1 ) [sys-kernel:sabayon-sources-4.11.10.bd94789f59b1e0b33118e122a23a0164c7205b8a~0.tbz2] success @ http://na.mirror.garr.it
╠    ##  Aggregated transfer rate: 3.7MB/second
╠  +++ >>>  (1/2) sys-kernel/linux-sabayon-4.11.10
╠    ## Unpacking: sys-kernel:linux-sabayon-4.11.10.1f22c24cc709872f47d62d3c9e44af879fe18888~0.tbz2
╠    ## Package phase: setup
 * To avoid automounting and auto(un)installing with /boot,
 * just export the DONT_MOUNT_BOOT variable.

 * Your boot partition was detected as being mounted at /boot.
 * Files will be installed there for linux-sabayon to function correctly.
 * Preparing kernel and its modules
╠    ## Package phase: preinstall

 * Your boot partition was detected as being mounted at /boot.
 * Files will be installed there for linux-sabayon to function correctly.
╠    ## Installing package: sys-kernel/linux-sabayon-4.11.10
╠    ## [Official Sabayon Linux Standard kernel image]
╠    ## Updating installed packages repository: sys-kernel/linux-sabayon-4.11.10
╠    ## Package phase: postinstall
 * Removing extents option for ext4 drives from /etc/fstab
Generating grub configuration file ...
Found background: /boot/grub/default-splash.png
Found linux image: /boot/kernel-genkernel-x86_64-4.11.0-sabayon
Found initrd image: /boot/initramfs-genkernel-x86_64-4.11.0-sabayon
Found linux image: /boot/kernel-genkernel-x86_64-4.8.0-sabayon
Found initrd image: /boot/initramfs-genkernel-x86_64-4.8.0-sabayon
done

 * You are currently booting with kernel:
 * kernel-genkernel-x86_64-4.8.0-sabayon
 *
 * Use 'eselect bzimage' in order to switch between the available ones


 * If you are upgrading from a previous kernel, you may be interested
 * in the following document:
 *   - General upgrade guide: https://wiki.gentoo.org/wiki/Kernel/Upgrade

 * Updating module dependencies for 4.11.0-sabayon ...
depmod: WARNING: Ignored deprecated option -r                                                                                                                                                                                               [ ok ]
 * Please report kernel bugs at:
 * http://bugs.sabayon.org
 * The source code of this kernel is located at
 * =sys-kernel/sabayon-sources-4.11.10.
 * Sabayon Linux recommends that portage users install
 * sys-kernel/sabayon-sources-4.11.10 if you want
 * to build any packages that install kernel modules
 * (such as ati-drivers, nvidia-drivers, virtualbox, etc...).
╠    ## Cleaning: sys-kernel/linux-sabayon-4.11.10
╠  +++ >>>  (2/2) sys-kernel/sabayon-sources-4.11.10
╠    ## Unpacking: sys-kernel:sabayon-sources-4.11.10.bd94789f59b1e0b33118e122a23a0164c7205b8a~0.tbz2
╠    ## Package phase: setup
 * To avoid automounting and auto(un)installing with /boot,
 * just export the DONT_MOUNT_BOOT variable.

 * Your boot partition was detected as being mounted at /boot.
 * Files will be installed there for sabayon-sources to function correctly.
 * Preparing kernel and its modules
╠    ## Package phase: preinstall
╠    ## Installing package: sys-kernel/sabayon-sources-4.11.10
╠    ## [Official Sabayon Linux Standard kernel sources]
╠    ## Updating installed packages repository: sys-kernel/sabayon-sources-4.11.10
╠    ## Package phase: preremove
╠    ## Cleaning previously installed application data.
╠    ## Package phase: postremove
╠    ## Package phase: postinstall

 * If you are upgrading from a previous kernel, you may be interested
 * in the following document:
 *   - General upgrade guide: https://wiki.gentoo.org/wiki/Kernel/Upgrade

╠    ## Cleaning: sys-kernel/sabayon-sources-4.11.10
╠  @@ Installation complete.
╠  @@ No configuration files to update.
sabayon fitzcarraldo #

Now upgrade the OS installation to the latest kernel image and reboot the machine so that the new kernel image is loaded:

sabayon fitzcarraldo # kernel-switcher switch linux-sabayon-4.11.10
sabayon fitzcarraldo # reboot

Check that the new kernel version is running:

sabayon fitzcarraldo # uname -a
Linux sabayon.local 4.11.0-sabayon #1 SMP Sat Jul 15 09:33:23 UTC 2017 x86_64 Intel(R) Pentium(R) CPU G2030 @ 3.00GHz GenuineIntel GNU/Linux
sabayon fitzcarraldo #

The minor in the version number reported by the uname command does not necessarily correspond to the minor in the version number of the kernel image package. This is not an error: see Misunderstandings about the kernel in the Sabayon Wiki regarding this apparent discrepancy.

The symlink to the kernel source code will now exist:

sabayon fitzcarraldo # eselect kernel list
Available kernel symlink targets:
  [1]   linux-4.11.0-sabayon *
sabayon fitzcarraldo #

If everything works correctly, you can uninstall the earlier version(s) of the kernel image package:

sabayon fitzcarraldo # equo search --installed linux-sabayon
sabayon fitzcarraldo # equo remove linux-sabayon-4.8.17

In my case an earlier version of the kernel source code package was not installed, but if one had been then I would have uninstalled that package too:

sabayon fitzcarraldo # equo search --installed sabayon-sources
sabayon fitzcarraldo # equo remove sabayon-sources-4.8.17

You can also remove old kernel image files manually from the /boot directory if they were not removed automatically:

sabayon fitzcarraldo # ls /boot
sabayon fitzcarraldo # rm -i /boot/*genkernel-x86_64-4.8.0-sabayon

Regenerate the file grub.cfg so that the GRUB 2 menu at boot only lists the kernel images actually present in the /boot directory:

sabayon fitzcarraldo # grub-mkconfig -o /boot/grub/grub.cfg

If you’re running Sabayon Linux inside a VirtualBox virtual machine, you’ll also need to install in the guest installation the correct version of the VirtualBox Guest Additions for the new version of the kernel you just installed in the guest installation. Uninstall the old version if it has not already been uninstalled automatically, then search for the version that corresponds to the kernel you installed in the guest installation:

sabayon fitzcarraldo # equo remove virtualbox-guest-additions
sabayon fitzcarraldo # equo search virtualbox-guest-additions
sabayon fitzcarraldo # equo install virtualbox-guest-additions-5.1.22#4.11.0-sabayon