HOWTO: Upgrade kernel using genkernel

From Sabayon Wiki
Jump to: navigation, search
i18n: en es pl
This how-to is for the Portage package manager. Please use the Entropy package manager if you are not familiar with Portage.

Before actually performing any of the commands listed below, read through the entire article and WARNING No. 1 at the end, as it may alter what commands you use.

Install prerequisites

A fresh installation of Sabayon won't have some required commands (like "git", "layman") so install them. Add sabayon-distro overlay (You may want to read about Layman).

Open a Konsole/Terminal window and use the su command to log in as the root user (and enter the root password):

$ su root
# equo install git
# equo i layman
# layman -L
# layman -a sabayon-distro

If you have a separate boot partition, make sure it is mounted onto /boot before proceeding. For example, if the boot partition is /dev/sda3 then:

# mount /dev/sda3 /boot

Update portage and genkernel first, then install the newest kernel source code:

# emerge --sync && layman -S
# emerge -av genkernel
Note 1: There's no need to merge genkernel if the latest version is already installed.

Setup sources

Check your current kernel version:

# uname -r

Install sources:

# USE="sources_standalone" emerge sabayon-sources
 * This package will overwrite one or more files that may belong to other
 * packages (see list below). You can use a command such as `portageq
 * owners / <filename>` to identify the installed package that owns a
 * file. If portageq reports that only one package owns a file then do
 * NOT file a bug report. A bug report is only useful if it identifies at
 * least two or more packages that are known to install the same file(s).
 * If a collision occurs and you can not explain where the file came from
 * then you should simply ignore the collision since there is not enough
 * information to determine if a real problem exists. Please do NOT file
 * a bug report at unless you report exactly
 * which two packages install the same file(s). See
 * for tips on how
 * to solve the problem. And once again, please do NOT file a bug report
 * unless you have completely understood the above message.
 * Detected file collision(s):
 *      /usr/src/linux-4.11.0-sabayon/.config
 *      /usr/src/linux-4.11.0-sabayon/Makefile
 * Searching all installed packages for file collisions...
 * Press Ctrl-C to Stop
 * sys-kernel/linux-sabayon-4.11.3-r1:4.11::sabayon-distro
 *      /usr/src/linux-4.11.0-sabayon/.config
 *      /usr/src/linux-4.11.0-sabayon/Makefile
 * Package 'sys-kernel/sabayon-sources-4.11.4' NOT merged due to file
 * collisions. If necessary, refer to your elog messages for the whole
 * content of the above message.

>>> Failed to install sys-kernel/sabayon-sources-4.11.4, Log file:

>>>  '/var/tmp/portage/sys-kernel/sabayon-sources-4.11.4/temp/build.log'

You can resolve this conflict with -collision-protect:

FEATURES="-collision-protect" USE="sources_standalone" emerge sabayon-sources

Configure /usr/src/linux symlink:

# eselect kernel list

Note which kernel in the list you want to install. It has a number like this next to it: [x]. More than likely x = 2 [2]. Now use this number in the following command, in order to set the symlink to the new version of the kernel:

# eselect kernel set x 

You can check symlink value with commands file /usr/src/linux or readlink /usr/src/linux

WARNING No. 1: Think carefully about what you are trying to achieve here, i.e. do you want to upgrade to a newer version of the kernel or do you want to rebuild the same version of the kernel you are currently using (perhaps, optionally, making some manual changes to the kernel configuration)?

Unsupported kernels

For other unsupported kernels, please have a look at the unsupported software section at the Gentoo forums.

Most unsupported kernels are in the custom-kernels overlay which is accessible with Layman.

# layman -a custom-kernels

Edit genkernel configuration file

"The actual behavior of genkernel depends on a large variety of options, the majority of which can be set/unset in the /etc/genkernel.conf file" (see genkernel page, and do actually read comments in the /etc/genkernel.conf file itself)

Prepare kernel sources configuration file

# zcat /proc/config.gz > /usr/src/config 

see below, why not /usr/src/linux/.config, also read output of ls -1 /etc/kernels/

Note 2: If you are just making some changes to the same version of kernel and rebuilding it then using the zcat command is probably appropriate. However if you are upgrading or downgrading to a different version of kernel then the zcat command is probably not appropriate.

Note that the zcat command mentioned above creates a configuration file based on the currently-running kernel. However, the configuration of the current kernel may not be suitable for the new version of the kernel sources you just merged (downloaded). It could be that you want or need to use a configuration file for the new version of kernel you have just merged. To give a hypothetical example in order to try and illustrate the distinction, let's suppose you are currently running the 2.6.22 kernel but now want to build the 2.6.25 kernel. In which case you would not need to bother with the zcat command as some of the configuration parameters in the 2.6.22 kernel do not exist in the 2.6.25 kernel (and vice versa), so instead of using a file /usr/src/config you could create using zcat, you would instead use the .config file (notice the dot) in the directory /usr/src/linux-2.6.25-sabayon/ created when you merged linux-sabayon-2.6.25 earlier, which is different from the .config file (and config file created by zcat) for the 2.6.22 kernel.

Notice the difference between "--kernel-config=/usr/src/config" ( the file "config" would be created by using the zcat command) and "--kernel-config=/usr/src/linux-2.6.25-sabayon/.config" (the file ".config" would be created when you merge linux-sabayon-2.6.25).

Note also that the file /usr/src/linux-2.6.25-sabayon/.config would be the same as the file /usr/portage/local/layman/sabayon/sys-kernel/linux-sabayon/files/linux-sabayon-2.6.25-x86.config if you merged linux-sabayon-2.6.25 for the x86 edition of Sabayon Linux, or the file /usr/portage/local/layman/sabayon/sys-kernel/linux-sabayon/files/linux-sabayon-2.6.25-amd64.config if you merged linux-sabayon-2.6.25 for the x86_64 edition of Sabayon Linux. Thus, if you run one of the above commands and an error message is displayed to the effect that /usr/src/linux-2.6.25-sabayon/.config cannot be opened, then try using --kernel-config=/usr/portage/local/layman/sabayon/sys-kernel/linux-sabayon/files/linux-sabayon-2.6.25-x86.config (or /usr/portage/local/layman/sabayon/sys-kernel/linux-sabayon/files/linux-sabayon-2.6.25-amd64.config if you have the 64-bit edition of SL installed). Note also that the default location of the Portage overlay sources has been changed from directory /usr/portage/local/layman/ to directory /usr/local/portage/layman/ in the latest version of SL (and Gentoo), so modify the aforementioned command accordingly if you are using SL 4.0 and onwards. For example, in the case of the 2.6.31 kernel the switch would be the following for the x86 edition:


and the following for the x86_64 edition:


Note 8: In SL 5.2 and onwards (Layman 1.3.0 and onwards), replace "/usr/local/portage/layman/" with "/var/lib/layman/" in the text above.

Note 9: Use "/usr/portage/distfiles/sabayon-2.6.34-amd64.config" instead of "/var/lib/layman/sabayon/sys-kernel/linux-sabayon/files/linux-sabayon-2.6.34-amd64.config" (replace "amd64" with "x86" for x86) for kernel 2.6.34 and onwards.

Note 10: The location of the .config file changed again for kernel 3.0.0 (and possibly earlier). Rather than adding notes here ad infinitum, please use the locate command (install mlocate if not already installed) to find the .config file.

Configure installation

Do the following if you manually edited your partitions:

# genkernel --kernel-config=/usr/src/config --menuconfig --splash=sabayon --disklabel --luks all

Do the following if you used anaconda's automatic diskdruid or created a lvm:

# genkernel --kernel-config=/usr/src/config --menuconfig  --splash=sabayon --disklabel --lvm --luks all

Note 3: If you get an error about an expected integer expression on line 96 of, you will most likely need to update your config files. I used etc-update and selected the second option (-5).

Note 4: If you have an older version of genkernel, for example 3.4.7-x, replace "--lvm" with "--lvm2" and "--splash" with "--gensplash".

Note 5: If you want to be able to use a UUID for real_root in grub.conf then include "--disklabel". Otherwise you can omit the "--disklabel" (which I normally do).

Note 6: "--disklabel" is needed if, after you have built the kernel and reboot, mounting of the root partition fails and you see an error message "blkid: not found". See Gentoo Bugzilla Report No. 229847 for more details. Alternatively, edit grub.conf and make real_root point to the file name of the root partition (/dev/sda5 or whatever) rather than to the root partition's UUID.

Note 7: "--luks" is only needed if you want LUKS support for disk encryption.

Build kernel and modules

Launch genkernel script:

# genkernel --kernel-config=/usr/src/linux-2.6.25-sabayon/.config --menuconfig --bootloader=grub --splash=sabayon --disklabel all


# genkernel --kernel-config=/usr/src/linux-2.6.25-sabayon/.config --menuconfig --bootloader=grub --splash=sabayon --disklabel --lvm all 

if you used anaconda's automatic diskdruid or created a lvm.)

When you get into the linux kernel menu where you can go and edit all sorts of linux kernel variables (and it's very tempting to mess with), unless you are very, VERY well versed in understanding what it is you are doing, the default settings are good and reliable to start with and will create a kernel that actually WORKS.

SO, you can simply exit and save without changing anything, this way your kernel will compile and you can actually boot into it.

Then we need to rebuild our modules and such to make sure everything works with the new kernel. So do:

# module-rebuild rebuild

Rebuild other drivers if necessary

Sometimes this will fail if old modules are still around, so you might need to re-emerge your video drivers

I had to re-emerge my nvidia drivers because the old drivers were no longer in the portage tree:

# emerge nvidia-drivers

OR, if you have an ATI GPU:

# emerge ati-drivers

and if it says that ati-drivers-<version> is unavailable, try:

# module-rebuild del ati-drivers-<version> 

If you still have problems, you can clean-out and renew your moduledb first like this:

# rm /var/lib/module-rebuild/moduledb
# module-rebuild populate
# module-rebuild rebuild

Note that the latest kernel has built-in wireless stuff, causing the wireless modules to fail the module-rebuild. The trick is to make sure the wireless stuff is enabled during the kernel compile.

Configure bootloader

Currently genkernel only knows about Grub Legacy, so you will need to regenerate the Grub2 grub.cfg file after completing the above, using the following command:

# grub2-mkconfig -o /boot/grub/grub.cfg

Any questions/problems/comments can be posted on the forums.

Now, reboot.

Choose to boot into your freshly compiled kernel, the old reliable one will still be there and may be a nice backup for safe keeping so, don't worry about getting rid of it.

Test boot with qemu (optionally)

# qemu-system-x86_64 -enable-kvm -drive file=/dev/sda,if=virtio,readonly,index=0,cache=none

(change /dev/sda to your actual drive name)

Do the reboot

There you have it. It will take some time, but it's good. Read also about [url= ksplice] and kexec