Noyau/Mise à jour

From Gentoo Wiki
< Kernel
Jump to: navigation, search
This page is a translated version of the page Kernel/Upgrade and the translation is 18% complete.

Outdated translations are marked like this.
Other languages:
Deutsch • ‎English • ‎Nederlands • ‎español • ‎français • ‎italiano • ‎português do Brasil • ‎русский • ‎中文(中国大陆)‎ • ‎日本語 • ‎한국어

Cet article décrit les différentes étapes de la mise à jour vers un nouveau noyau.

Une mise à jour du noyau peut être nécessaire lorsque les nouvelles sources du noyau sont installées suite à une mise à jour du système où lorsque vous installez vous-même les nouvelles sources.

root #emerge --ask --update --deep --with-bdeps=y --newuse @world

Of course, they can be installed directly using the next command (replace gentoo-sources with whatever version of the kernel that is in-use):

root #emerge --ask --update --deep --with-bdeps=y --newuse sys-kernel/gentoo-sources

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 kernel configuration is saved in a file named .config in the directory that holds the kernel sources. A new kernel may have had options or features added or removed since the old kernel. The kernel configuration specifies whether a kernel's features and options will 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.

Backup 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:

root #cd /usr/src/linux
root #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.

Configuration

Set symlink to new kernel sources

Le lien symbolique /usr/src/linux devrait toujours pointer sur les sources du noyau en cours d'utilisation. Il y a trois manières d'arriver à ce résultat :

  1. Installing the kernel sources with USE="symlink"
  2. Setting the link with eselect
  3. Manually updating the symbolic link

Installing the kernel sources with the symlink USE flag

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.

Setting the link with eselect

To set the symlink with eselect:

root #eselect kernel list
Available kernel symlink targets:
 [1] linux-3.14.14-gentoo *
 [2] 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:

root #eselect kernel set 2

Manually updating the symbolic link

To set the symbolic link manually:

root #ln -sf /usr/src/linux-3.16.3-gentoo /usr/src/linux
root #ls -l /usr/src/linux
lrwxrwxrwx 1 root root 19 Oct  4 10:21 /usr/src/linux -> linux-3.16.3-gentoo

Moving to the new folder

Now that the symbolic link has been modified, change the working directory to the new kernel folder.

root #cd /usr/src/linux
Note
This command is still necessary even if the working directory was already /usr/src/linux when the symlink was modified. Until the new symlink is actually followed, the console will still be in the old kernel's directory.

Copy previous kernel configuration

The configuration of the old kernel needs to be copied to the new one. In addition to the backup copy that was saved to /root in an earlier step, the old configuration can be found in several places:

  • Dans le système de fichier procfs, si l'optionEnable access to .config through /proc/config.gz du noyau était activée pour le noyau en service :
  • From the old kernel. This will only work when the old kernel was compiled with CONFIG_IKCONFIG:
root #/usr/src/linux/scripts/extract-ikconfig /path/to/old/kernel >/usr/src/linux/.config
  • Dans le répertoire /boot, si c'est là que vous avez installé le fichier de configuration :
  • Dans le répertoire kernel du noyau actuellement en service :
  • In the /etc/kernels/ directory, if SAVE_CONFIG="yes" is set in /etc/genkernel.conf and genkernel was previously used:
root #cp /etc/kernels/kernel-config-x86_64-3.14.14-gentoo /usr/src/linux/.config

.config file

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.

make silentoldconfig

Important
make silentoldconfig is being removed as of linux version 4.19, it will be replaced by make syncconfig.

The following configuration is like the text based configuration with make config. For new configuration options, the user is asked for a decision. For example:

root #cd /usr/src/linux
root #make silentoldconfig
Anticipatory I/O scheduler (IOSCHED_AS) [Y/n/m/?] (NEW)

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 (i.e. default) answer is capitalized (here Y). The help explains the option or driver.

Unfortunately make silentoldconfig doesn't show a lot more information for each option, such as the context, so 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.

make olddefconfig

If all new configuration options should be set to their recommended (i.e. default) values use make olddefconfig:

root #cd /usr/src/linux
root #make olddefconfig

make help

Use make help to see other conversion methods available:

root #make help

Compilation/construction

Important
When external kernel modules are installed (like nvidia or zfs), it may be necessary to run make modules_prepare as described below before building the kernel. Some modules cannot be installed or prepared before the kernel has been built.
Important
Do not forget to reconfigure the bootloader to account for the new kernel filenames, and rebuild the initramfs if one is used as well.

Pour cette étape, suivez les étapes de l'article configuration manuelle

Automated build and installation

It is possible to automatically build and install the newly emerged kernel using Portage hooks. While other approaches are also possible, the following is based on genkernel and gentoo-sources package. It requires the following prerequisites:

  1. genkernel all is able to build and install the kernel to which the /usr/src/linux symlink points into $BOOTDIR and the bootloader.
  2. The symlink use flag is set for the kernel ebuild.

If those are fulfilled, simply install a post_pkg_postinst Portage hook as shown below.

FILE /etc/portage/env/sys-kernel/gentoo-sourcesAutomated kernel build and installation portage hook
post_pkg_postinst() {
	CURRENT_KV=$(uname -r)
	# Check to see if genkernel has been run previously for the running kernel and use that config
	if [[ -f "${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" ]] ; then
		genkernel --kernel-config="${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" all
	elif [[ -f "${EROOT}/usr/src/linux-${CURRENT_KV}/.config" ]] ; then # Use latest kernel config from current kernel
		genkernel --kernel-config="${EROOT}/usr/src/linux-${CURRENT_KV}/.config" all
	elif [[ -f /proc/config.gz ]] ; then # Use known running good kernel
		zcat /proc/config.gz >> "${EROOT}/tmp/genkernel.config"
		genkernel --kernel-config="${EROOT}/tmp/genkernel.config" all
		rm "${EROOT}/tmp/genkernel.config"
	else # No valid configs known
		genkernel all
	fi
}

Réinstaller les modules externes du noyau

Note
The modules_prepare step is not required if building an entire kernel as this function is done as part of the standard process.

Tout module externe du noyau tel que modules binaires du noyau, doit être recompilé pour chacun des nouveaux noyau. Si le noyau n'a pas encore été recompilé, il doit d'abord être préparé pour la compilation des modules externes :

root #make modules_prepare

Vous pouvez recompiler les paquets en utilisant le jeu @module-rebuild :

root #emerge --ask @module-rebuild

Solving build problems

Si vous rencontrez des problèmes de compilation en recompilant le noyau courant, il peut être utile d'assainir les sources du noyau. Faites une sauvegarde préalable du fichier .config car il sera retiré lors de l'opération.

root #cp .config .config~
root #make distclean
root #mv .config~ .config

Suppression des anciens noyaux

Reportez-vous à l'article Noyau/Suppression

See also

  • Genkernel — un outil créé par Gentoo et utilisé pour automatiser le processus de compilation du noyau et du système de fichiers virtuel de démarrage (initramfs).

Ressources externes