This article describes the steps to upgrade to a new kernel.
- 1 Installing and Using a new Kernel
- 2 Make a Backup of the current kernel configuration
- 3 Set symlink to New kernel sources
- 4 Copy previous kernel configuration
- 5 Configure the new kernel
- 6 Build
- 7 Reinstall external kernel modules
- 8 Solving build problems
- 9 Removing old kernels
- 10 External resources
Installing and Using a new Kernel
A kernel upgrade may be a good idea when new kernel sources are installed. New kernel sources are sometimes installed when you update your system by running emerge -a --update --deep --with-bdeps=y --newuse @world --- or you might have them installed yourself.
Installing new kernel sources doesn't provide you with a new kernel. You need to make and install a new kernel from the new sources and then reboot your system to actually run the new kernel.
Making a new kernel from the new sources is basically the same process as making a kernel when installing the system. The difference is that you can use the configuration of the old kernel to create a configuration for the new kernel. Using the old configuration saves you from going through all the kernel options --- as make menuconfig presents you with --- again.
The configuration of the kernel is saved in a file named .config in the directory that holds the kernel sources. A new kernel may have options or features the old kernel does not have, or it might not have a feature or option anymore which the old kernel still has. The kernel configuration specifies whether the features and options of a kernel are to be enabled or not, perhaps built into the kernel, or perhaps built as modules which can be loaded into the running kernel on demand. Hence the configuration file of the new kernel may have new entries the configuration file of the old kernel doesn't have, and it might not have entries anymore which are present in the configuration file of the old kernel.
To deal with such changes of the configuration file, the configuration file of the old kernel needs to be converted to a configuration that can be used with the new kernel. This article shows you how to make a new kernel from new kernel sources with converting the configuration file of the old kernel.
Make a Backup of the current kernel configuration
You probably do not want to lose your kernel configuration --- after all, you probably have spent quite some time to figure out the best configuration for your system. It's easy to make a backup of it:
cp .config ~/
Provided that the symlink to the kernel sources has been set correctly, this copies the configuration of the currently used kernel to the home directory of root. (In case a backup already exists, it will be overwritten.)
The symlink /usr/src/linux should always point to the directory that holds the sources of the kernel which currently runs. This can be done in one of three ways:
- 1. Installing the kernel sources with active symlink USE flag
- This will make the /usr/src/linux point to your newly installed kernel sources. If necessary, it can still be modified later with the following two methods:
- 2. Setting the symlink with eselect
- Available kernel symlink targets:
eselect kernel list
 linux-3.14.14-gentoo *
- This outputs the available kernel sources. The asterisk indicates the chosen sources. To change the kernel sources, e.g. to the second entry, do:
eselect kernel set 2
- 3. Setting the symlink manually
ln -sf /usr/src/linux-3.16.3 /usr/src/linuxlrwxrwxrwx 1 root root 19 Oct 4 10:21 /usr/src/linux -> linux-3.16.3-gentoo
ls -l /usr/src/linux
Copy previous kernel configuration
The configuration of the old kernel needs to be copied to the new one. It can be found in several places:
- In the procfs filesystem, if the kernel option Enable access to .config through /proc/config.gz was activated in your present kernel:
zcat /proc/config.gz > /usr/src/linux/.config
- In the /boot directory, if you installed the config file there:
cp /boot/config-3.14.14-gentoo /usr/src/linux/.config
- In the kernel directory of the currently-running kernel:
cp /usr/src/linux-3.14.14-gentoo/.config /usr/src/linux/
Configure the new kernel
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 oldconfig or make silentoldconfig.
make oldconfig gives you choices, make silentoldconfig does not. Use either, not both.
The following configuration is like the text based configuration with make config. For new configuration options, it gives you a choice. For example:
The string (NEW) at the end of the line marks this option as new. Left to the string in square brackets are the possible answers: Yes, no, module or ? to show the help. The recommend answer is capitalized (here Y). The help explains the option or driver.
Unfortunately make oldconfig doesn't show - next to the help - a lot more information for each option, like the context, so that it is sometimes difficult to give the right answer. In this case the best way to go is to remember the option name and revise it afterwards through one of the graphical kernel configuration tools.
When you can't be bothered with choices, you can use make silentoldconfig:
- In case you have external kernel modules installed (like nvidia or zfs), you may need to run make modules_prepare as described below before bulding the kernel. --- Some modules cannot be installed or prepared before the kernel has been built.
For this step, follow the steps in the manual configuration article.
Do not forget to reconfigure the bootloader to account for the new kernel filenames. You might want to rebuild the initramfs if you're using one, too.
Reinstall external kernel modules
- Someone who knows better, please clarify
- When exactly should make modules_prepare be run? Lee (talk) 13:28, 14 February 2015 (UTC)
Any external kernel modules, such as binary kernel modules, need to be rebuilt for each new kernel. If the kernel hasn't been built yet, it has to first be prepared for the building of the external kernel modules:
You can rebuild the packages using the @module-rebuild set:
emerge --ask @module-rebuild
Solving build problems
If you are experiencing build problems while rebuilding the current kernel, it might help to sanitize the kernel sources. Make sure you backup the .config file first, as the operation will remove it. Make sure not to use a
~ suffix as backup as
make distclean will clean those up as well.
cp .config /usr/src/kernel_config_bk
mv /usr/src/kernel_config_bk .config
Removing old kernels
See the kernel removal article.