Noyau/Mise à jour

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

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

Pour produire un noyau à partir des nouvelles sources, la démarche est la même que celle appliquée lors de la production du noyau pour l'installation initiale du système. La différence est qu'il est possible de configurer le nouveau noyau en adaptant la configuration déjà utilisée plutôt que de passer à nouveau en revue l'intégralité des options (avec make menuconfig par exemple).

Des options et/ou des fonctionnalités ont pu être ajoutées dans le nouveau noyau par rapport au précédent. Il est donc possible que des entrées aient été ajoutées ou supprimées dans le fichier de configuration du nouveau noyau.

Cet article indique comment gérer ces évolutions en convertissant l'ancienne configuration afin de la rendre compatible avec le nouveau noyau.

Les étapes suivantes sont nécessaires pour la mise à jour du noyau dans Gentoo :

  1. Installer des nouvelles sources.
  2. Faire pointer le lien symbolique vers les (nouvelles) sources du noyau.
  3. Se placer dans le répertoire du nouveau noyau.
  4. Modifier le fichier .config pour traiter les options ajoutées ou supprimées de la configuration du nouveau noyau.
  5. Compiler le noyau et l'initramfs.
  6. Mettre à jour le chargeur de démarrage.
  7. Supprimer ou conserver l'ancien noyau.
Important
It is wise to make a backup of the kernel configuration so that the previous configurations are not lost. Many users devote considerable time to figure out the best configuration for the system, and losing that information is definitely not wanted. One of the ways introduced in Copy the previous kernel configuration of this article can be used for making a backup of the configuration file.

Installation des nouvelles sources

Une mise à jour du noyau peut être nécessaire lorsque des nouvelles sources du noyau sont installées. Cette installation peut se produire lors d'une mise à jour du système avec la commande suivante :

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 does not provide the user with a new kernel. It is necessary to build and install a new kernel from the new sources and then reboot the system to actually run the new kernel.

Set symlink to new kernel sources

The kernel configuration is saved in a file named .config in the directory that holds the kernel sources, a symlink is used to point to that directory.

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. Default: Setting the link with eselect.
  2. Alternative 1: Manually updating the symbolic link.
  3. Alternative 2: Installing the kernel sources with USE="symlink".

Default: Setting the link with eselect

To set the symlink with eselect:

user $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

Alternative 1: Manually updating the symbolic link

To set the symbolic link manually:

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

Alternative 2: 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.

Moving to the new kernel folder

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

user $cd /usr/src/linux
Remarque
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.

Adjusting the .config file for the new kernel

Copy the previous kernel configuration

The configuration of the old kernel needs to be copied to the new one. The old configuration can be found in several places:

  • Dans le système de fichier procfs, si l'option Enable access to .config through /proc/config.gz était activée pour le noyau en service :
root #zcat /proc/config.gz > /usr/src/linux/.config
  • 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 :
root #cp /boot/config-3.14.14-gentoo /usr/src/linux/.config
  • Dans le répertoire du noyau actuellement en service :
root #cp /usr/src/linux-3.14.14-gentoo/.config /usr/src/linux/
  • 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

Update the .config file

Remarque
Invoking make oldconfig and make menuconfig can be done automatically via genkernel in the build process by enabling the OLDCONFIG and MENUCONFIG parameters in /etc/genkernel.conf. If OLDCONFIG is enabled in genkernel's configuration or if it's going to be enabled by passing --oldconfig option to genkernel command, jump to the build section in this article.

A new kernel usually requires a new .config file to support new kernel features. The .config from the old kernel can be converted to be used with the new kernel. The conversion can be done several ways including running either make oldconfig or make olddefconfig.

make oldconfig

Important
make syncconfig has become an internal implementation detail; make oldconfig should be used when possible. The make silentoldconfig target has been removed as of Linux version 4.19 and higher.

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 oldconfig
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 oldconfig 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. For listing new options and doing research about them, make listnewconfig can be used before running make oldconfig.

make olddefconfig

Running make olddefconfig will keep all of the options from the old .config and set the new options to their recommended (i.e. default) values:

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

make help

Use make help to see other conversion methods available:

user $make help

Observing the difference

A diff tool can be used to compare the old and new .config files to see what options have been added:

user $comm -2 -3 <(sort .config) <(sort .config.old)
# CONFIG_BATTERY_RT5033 is not set
# Compiler: gcc (Gentoo 12.2.1_p20230428-r1 p2) 12.2.1 20230428
# Linux/x86 4.19.284-gentoo Kernel Configuration
CONFIG_ARCH_USE_MEMREMAP_PROT=y
CONFIG_GCC_VERSION=120201
CONFIG_GENTOO_PRINT_FIRMWARE_INFO=y
CONFIG_INET_TABLE_PERTURB_ORDER=16
CONFIG_PLUGIN_HOSTCC=""
CONFIG_RANDOM_TRUST_BOOTLOADER=y
CONFIG_UNIX_SCM=y
CONFIG_USER_NS=y

And which have been removed:

user $comm -1 -3 <(sort .config) <(sort .config.old)
# CONFIG_GCC_PLUGINS is not set
# CONFIG_NVM is not set
# CONFIG_RANDOM_TRUST_CPU is not set
# CONFIG_USER_NS is not set
# Compiler: gcc (Gentoo 10.2.0-r5 p6) 10.2.0
# Linux/x86 4.19.184-gentoo Kernel Configuration
CONFIG_GCC_VERSION=100200
CONFIG_PLUGIN_HOSTCC="g++"

Alternatively, the kernel provides a script to cleanly compare two config files even if the options have moved in the file itself:

user $/usr/src/linux/scripts/diffconfig .config.old .config

make menuconfig

The options can then be researched and changed if necessary by running:

root #make menuconfig

The menuconfig target is helpful because it safely handles kernel symbol dependency resolution.

Compilation/Installation

Manual build and installation

Having configured the new kernel as described in the previous sections, if external kernel modules are installed (like nvidia or zfs), it may be necessary to prepare them before building the new kernel, and then to rebuild the modules with the newly built kernel:

root #make modules_prepare
root #make
root #emerge --ask @module-rebuild
Remarque
Using the -jN option with make (where N is the number of parallel jobs) can speed up the compilation process on multi-threaded systems. For example, make -j5 on a system with four logical cores.

Having built both the kernel and the modules, both should be installed:

root #make modules_install
root #make install

Finally, the bootloader must be reconfigured to account for the new kernel filenames, as described below. initramfs must be rebuilt if one is used as well.

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. Keep in mind this calls genkernel with --no-module-rebuild, since using module-rebuild would run emerge in emerge, and result in a deadlock waiting on the lock file. Remember to run emerge @module-rebuild after any update that includes a kernel upgrade.

FILE /etc/portage/env/sys-kernel/gentoo-sourcesAutomated kernel build and installation portage hook
post_pkg_postinst() {
# Eselect the new kernel or genkernel will build the current one
	eselect kernel set linux-"${KV}"
	CURRENT_KV=$(uname -r)
# Check 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 --no-module-rebuild --kernel-config="${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" all
# Use latest kernel config from current kernel
	elif [[ -f "${EROOT}/usr/src/linux-${CURRENT_KV}/.config" ]] ; then
		genkernel --no-module-rebuild --kernel-config="${EROOT}/usr/src/linux-${CURRENT_KV}/.config" all
# Use known running good kernel
	elif [[ -f /proc/config.gz ]] ; then
		zcat /proc/config.gz >> "${EROOT}/tmp/genkernel.config"
		genkernel --no-module-rebuild --kernel-config="${EROOT}/tmp/genkernel.config" all
		rm "${EROOT}/tmp/genkernel.config"
# No valid configs known, compile a clean one
	else
		genkernel --no-module-rebuild all
	fi
}

Solving build problems

Si vous rencontrez des problèmes de compilation en recompilant le noyau, il peut être utile de nettoyer les sources du noyau. Faites une sauvegarde préalable du fichier .config car il sera retiré lors de l'opération. make distclean supprime les fichiers avec les extensions .bak et ~, il ne faut donc pas les utiliser pour votre sauvegarde.

root #cp .config /usr/src/kernel_config_bk
root #make distclean
root #mv /usr/src/kernel_config_bk .config

Update the bootloader

The upgraded and installed kernel must be registered with the bootloader or directly with the UEFI firmware, see Kernel/Configuration. Users of GRUB can use the method below, users of other bootloaders must consult the Handbook.

Make sure /boot partition is mounted.

Using grub-mkconfig

The following command can be executed for updating GRUB's configuration file:

root #grub-mkconfig -o /boot/grub/grub.cfg
Attention !
If GRUB itself was upgraded (besides the kernel), for instance as part of a world set upgrade, it is necessary to also re-install GRUB, otherwise it may not boot. See GRUB#GRUB Bootloader Installation for details.
Conseil
By enabling the grub USE flag on sys-kernel/installkernel grub-mkconfig will be regenerated automatically every time a new kernel is installed.

Systemd-boot

A systemd-boot configuration file for the new kernel is generated automatically when the kernel is installed. No manual action is required.

Suppression des anciens noyaux

Reportez-vous à l'article kernel removal.

Voir aussi

Ressources externes