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 while updating the system by running emerge -a --update --deep --with-bdeps=y --newuse @world, or of course when installed directly.
Installing new kernel sources doesn't provide the user with a new kernel. It is necessary to make and install a new kernel from the new sources and then reboot the 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 one can use the configuration of the old kernel to create a configuration for the new kernel. Using the old configuration saves the user from going through all the kernel options (like make menuconfig) 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 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
It is wise to make a backup of the kernel configuration so that the previous configurations are not lost. After all, many users devote considerable time to figure out the best configuration for the system, and losing that information is definitely not wanted.
It is easy to make a backup of the current kernel configuration:
cp .config ~/kernel-config-`uname -r`
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, renaming the configuration to kernel-config- followed by the version of the current running Linux kernel.
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:
- Installing the kernel sources with
- Setting the link with eselect
- Manually updating the symbolic link
This will make the /usr/src/linux point to the newly installed kernel sources.
If necessary, it can still be modified later with one of the other two methods.
To set the symlink with eselect:
eselect kernel list
Available kernel symlink targets:  linux-3.14.14-gentoo *  linux-3.16.3-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
To set the symbolic link manually:
ln -sf /usr/src/linux-3.16.3 /usr/src/linux
ls -l /usr/src/linux
lrwxrwxrwx 1 root root 19 Oct 4 10:21 /usr/src/linux -> linux-3.16.3-gentoo
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 the present kernel:
zcat /