Kernel/Upgrade

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 49% complete.
Outdated translations are marked like this.

Dieser Artikel beschreibt die Schritte, um auf eine neue Version der Linux Kernel zu aktualisieren.

Einen neuen Kernel aus den neuen Quellen zu bauen ist im Grunde der gleiche Vorgang wie der Bau eines Kernel bei der Installation des Systems. Der einzige Unterschied besteht darin, dass Sie Zeit sparen können, indem Sie die alte Kernelkonfiguration an die Änderungen im neuen Kernel anpassen, anstatt alle Kerneloptionen durchzugehen (Wie es bei der bloßen Verwendung von make menuconfig notwendig wäre.)

Bei einem neuen Kernel können Optionen oder Funktionen seit dem alten Kernel hinzugefügt oder entfernt worden sein. Daher kann die Konfigurationsdatei des neuen Kernels neue Einträge haben, die die Konfigurationsdatei des alten Kernels nicht hat, und sie kann Einträge nicht mehr haben, die in der Konfigurationsdatei des alten Kernels vorhanden sind.

Dieser Artikel ist eine Anleitung, wie mit solchen Änderungen in der Konfigurationsdatei umzugehen ist, indem die alte Konfiguration in eine Konfiguration transformiert wird, die mit dem neuen Kernel verwendet werden kann.

Kernel upgrade in Gentoo involves these steps:

  1. Install the new kernel sources.
  2. Setting the symlink to the (newly installed) kernel sources.
  3. Moving to the new kernel's folder.
  4. Adjusting the .config file for the options introduced to, or removed from, the new kernel's configuration.
  5. Compiling the kernel and the initramfs.
  6. Updating the bootloader.
  7. Removing or keeping the old kernel.
Wichtig
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.

Emergen der neuen Kernelquellen

Ein Kernel Upgrade ist vermutlich eine gute Idee, wenn Kernelquellen installiert werden. Neue Kernelquellen werden manchmal bei der Aktualisierung des Systems durch die Ausführung folgendes Befehls installiert:

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

Die bloße Installation neuer Kernelquellen liefert dem Nutzer keinen neuen Kernel. Es ist darüber hinaus erforderlich einen neuen Kernel auf Grundlage der neuen Quellen zu bauen (make), zu installieren (install) und anschließend das System neu zu starten, um wirklich den neuen Kernel zu verwenden.

Einen Symlink auf die neuen Kernelquellen setzen

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.

Der Symlink /usr/src/linux sollte immer auf das Verzeichnis zeigen das die Kernelquellen des aktuell laufenden Kernel enthält. Dies kann auf eine von drei Arten erfolgen:

  1. Standard: Setzen des Links mit eselect.
  2. Alternative 1: Manuell den symbolischen Link aktualisieren.
  3. Alternative 2: Installation der Kernelquellen mit USE="symlink".

Standard: Den Link mit eselect setzten

Um den Symlink mit eselect zu setzten:

user $eselect kernel list
Available kernel symlink targets:
 [1] linux-3.14.14-gentoo *
 [2] linux-3.16.3-gentoo

Dies gibt die verfügbaren Kernelquellen aus. Der Stern kennzeichnet die ausgewählten Quellen.

Um die Kernelquellen beispielsweise auf den zweiten Eintrag zu ändern, führen Sie folgendes aus:

root #eselect kernel set 2

Alternative 1: Manuell den symbolischen Link aktualisieren

Um den symbolischen Link manuell zu setzten:

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: Installation der Kernelquellen mit dem symlink USE-Flag

Dies führt dazu, dass /usr/src/linux auf die neu installierten Kernelquellen zeigt.

Falls nötig, kann dies später immer noch mit einer der beiden anderen Methoden geändert werden.

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
Hinweis
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

Kopieren der vorigen Kernel-Konfiguration

Die Konfiguration des alten Kernel muss zum neuen kopiert werden. Die alte Konfiguration kann an mehreren Orten gefunden werden:

  • Im procfs Dateisystem, falls die Kernel Option Enable access to .config through /proc/config.gz (CONFIG_IKCONFIG_PROC) im aktuellen Kernel aktiviert worden ist:
root #zcat /proc/config.gz > /usr/src/linux/.config
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
  • Im /boot Verzeichnis, falls die Konfiguration dort installiert worden ist:
root #cp /boot/config-3.14.14-gentoo /usr/src/linux/.config
root #cp /boot/config-3.14.14-gentoo /usr/src/linux/.config
  • Im Kernelverzeichnis des aktuell laufenden Kernels:
root #cp /usr/src/linux-3.14.14-gentoo/.config /usr/src/linux/
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

Aktualisierung der .config-Datei

Hinweis
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.

Ein neuer Kernel erfordert in der Regel eine neue .config-Datei, um neue Kernel-Funktionen zu unterstützen. Die .config-Datei des alten Kernels kann konvertiert werden, um sie mit dem neuen Kernel zu verwenden. Die Konvertierung kann auf mehrere Arten erfolgen, einschließlich der Ausführung von make oldconfig oder make olddefconfig.

make oldconfig

Wichtig
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.

Die folgende Konfiguration ist wie die textbasierte Konfiguration mit make config. Bei neuen Konfigurationsoptionen wird der Benutzer um eine Entscheidung gebeten. Zum Beispiel:

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

Das (NEW) am Ende der Zeile weist diese Option als neu aus. Direkt davor in eckigen Klammern stehen die möglichen Einstellungen: Yes, no, module oder ?, um die Hilfe anzuzeigen. Die empfohlene Einstellung (default) ist groß geschrieben (hier Y). Die Hilfe beschreibt den Treiber oder die Funktion.

Leider zeigt make oldconfig für die einzelne Option neben der Hilfe nur wenig zusätzliche Informationen, z.B. den Kontext, so dass es manchmal schwierig ist, die richtige Auswahl zu treffen. In diesem Fall ist es das Beste, sich den Namen der Option zu merken und die Auswahl später mit Hilfe der grafischen Kernel Konfigurationsprogramme zu treffen. Um neue Optionen aufzulisten und zu erforschen, kann make listnewconfig verwendet werden, bevor make oldconfig ausgeführt wird.

make olddefconfig

Wenn Sie make olddefconfig ausführen, werden alle Optionen aus der alten .config beibehalten und die neuen Optionen auf ihre empfohlenen (d.h. Standard-) Werte gesetzt:

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

make help

Verwenden Sie make help, um andere verfügbare Konvertierungsmethoden zu sehen:

user $make help

Beobachtung des Unterschieds

Mit einem Diff-Tool können Sie die alte und die neue .config-Datei vergleichen, um zu sehen, welche Optionen hinzugefügt wurden:

user $diff <(sort .config) <(sort .config.old) | awk '/^<.*(=|Linux)/ { $1=""; print }'
CONFIG_64BIT_TIME=y
CONFIG_AMD_NB=y
CONFIG_ARCH_CLOCKSOURCE_INIT=y
CONFIG_ARCH_HAS_GIGANTIC_PAGE=y
CONFIG_ARCH_HAS_PTE_DEVMAP=y
CONFIG_ARCH_HAS_SET_DIRECT_MAP=y
CONFIG_ARCH_STACKWALK=y
CONFIG_ARCH_USE_MEMREMAP_PROT=y
CONFIG_BLK_PM=y
CONFIG_CC_CAN_LINK=y
CONFIG_CC_DISABLE_WARN_MAYBE_UNINITIALIZED=y
CONFIG_CC_HAS_ASM_INLINE=y
CONFIG_CC_HAS_KASAN_GENERIC=y
CONFIG_CC_HAS_WARN_MAYBE_UNINITIALIZED=y
CONFIG_CPU_SUP_AMD=y
CONFIG_CPU_SUP_HYGON=y
CONFIG_CPU_SUP_ZHAOXIN=y
CONFIG_CRYPTO_LIB_AES=y
CONFIG_CRYPTO_LIB_ARC4=y
CONFIG_CRYPTO_LIB_DES=y
CONFIG_CRYPTO_LIB_SHA256=y
CONFIG_DEBUG_MISC=y
CONFIG_DRM_I915_FORCE_PROBE=""
CONFIG_DRM_I915_SPIN_REQUEST=5
CONFIG_DRM_I915_USERFAULT_AUTOSUSPEND=250
CONFIG_DYNAMIC_EVENTS=y
CONFIG_EFI_EARLYCON=y
CONFIG_GCC_PLUGINS=y
CONFIG_GENERIC_GETTIMEOFDAY=y
CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE=y
CONFIG_HAVE_ARCH_STACKLEAK=y
CONFIG_HAVE_ASM_MODVERSIONS=y
CONFIG_HAVE_EISA=y
CONFIG_HAVE_FAST_GUP=y
CONFIG_HAVE_FUNCTION_ARG_ACCESS_API=y
CONFIG_HAVE_GENERIC_VDSO=y
CONFIG_HAVE_MOVE_PMD=y
CONFIG_HAVE_PCI=y
CONFIG_INIT_STACK_NONE=y
CONFIG_IO_URING=y
CONFIG_KASAN_STACK=1
CONFIG_LEDS_TRIGGER_AUDIO=y
CONFIG_LSM="lockdown,yama,loadpin,safesetid,integrity"
CONFIG_MMC_SDHCI_IO_ACCESSORS=y
CONFIG_NETFILTER_XT_TARGET_MASQUERADE=m
CONFIG_NET_VENDOR_GOOGLE=y
CONFIG_NET_VENDOR_MICROCHIP=y
CONFIG_NET_VENDOR_PENSANDO=y
CONFIG_NET_VENDOR_XILINX=y
CONFIG_NF_NAT=m
CONFIG_NF_NAT_MASQUERADE=y
CONFIG_NVMEM_SYSFS=y
CONFIG_OPTIMIZE_INLINING=y
CONFIG_POWER_SUPPLY_HWMON=y
CONFIG_PROC_PID_ARCH_STATUS=y
CONFIG_SKB_EXTENSIONS=y
CONFIG_SND_INTEL_NHLT=y
CONFIG_UBSAN_ALIGNMENT=y
CONFIG_UNIX_SCM=y
CONFIG_USB_AUTOSUSPEND_DELAY=2
CONFIG_X86_ACPI_CPUFREQ_CPB=y
CONFIG_X86_MCE_AMD=y
# end of Gentoo Linux
# Linux/x86 5.4.0-gentoo Kernel Configuration

Und welche entfernt worden sind:

user $diff <(sort .config) <(sort .config.old) | awk '/^>.*(=|Linux)/ { $1=""; print }'
CONFIG_ANON_INODES=y
CONFIG_ARCH_DISCARD_MEMBLOCK=y
CONFIG_ARCH_HAS_SG_CHAIN=y
CONFIG_ARCH_HAS_ZONE_DEVICE=y
CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING=y
CONFIG_ARM_GIC_MAX_NR=1
CONFIG_AUDIT_TREE=y
CONFIG_AUDIT_WATCH=y
CONFIG_BACKLIGHT_LCD_SUPPORT=y
CONFIG_CRYPTO_WORKQUEUE=y
CONFIG_DEFAULT_CFQ=y
CONFIG_DEFAULT_IO_DELAY_TYPE=0
CONFIG_DEFAULT_IOSCHED="cfq"
CONFIG_DEFAULT_SECURITY=""
CONFIG_DMA_DIRECT_OPS=y
CONFIG_FB_BACKLIGHT=y
CONFIG_GENERIC_HWEIGHT=y
CONFIG_HAVE_DEBUG_STACKOVERFLOW=y
CONFIG_HAVE_GENERIC_GUP=y
CONFIG_HAVE_MEMBLOCK=y
CONFIG_IA32_AOUT=y
CONFIG_INET6_XFRM_MODE_BEET=y
CONFIG_INET6_XFRM_MODE_TRANSPORT=y
CONFIG_INET6_XFRM_MODE_TUNNEL=y
CONFIG_INET_XFRM_MODE_TRANSPORT=y
CONFIG_INET_XFRM_MODE_TUNNEL=y
CONFIG_IO_DELAY_TYPE_0X80=0
CONFIG_IO_DELAY_TYPE_0XED=1
CONFIG_IO_DELAY_TYPE_NONE=3
CONFIG_IO_DELAY_TYPE_UDELAY=2
CONFIG_IOSCHED_CFQ=y
CONFIG_IOSCHED_NOOP=y
CONFIG_MAY_USE_DEVLINK=y
CONFIG_NO_BOOTMEM=y
CONFIG_RWSEM_XCHGADD_ALGORITHM=y
CONFIG_X86_DEV_DMA_OPS=y
# Linux/x86 4.19.86-gentoo Kernel Configuration

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.

Kompilieren

Wichtig
Wenn externe Kernelmodule installiert sind (wie nvidia oder zfs), kann es notwendig sein vor dem Kompilieren besagter Module make modules_prepare auszuführen, wie unterhalb beschrieben. Einige Module können nicht installiert oder vorbereitet werden, bevor der Kernel kompiliert ist.

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
Hinweis
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.

Automatisierte Erstellung und 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.

DATEI /etc/portage/env/sys-kernel/gentoo-sourcesAutomatisierter Kernel-Build und Installationsportage-Hook
post_pkg_postinst() {
# Eselect the new kernel or genkernel will build the current one
	eselect kernel set linux-"${PV}"-gentoo
	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 --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 --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 --kernel-config="${EROOT}/tmp/genkernel.config" all
		rm "${EROOT}/tmp/genkernel.config"
# No valid configs known, compile a clean one
	else
		genkernel all
	fi
}

Lösung von Bauproblemen

Falls Probleme beim Neukompilieren des aktuellen Kernels auftreten, kann es helfen die Kernelquellen zu bereinigen. Stellen Sie zunächst sicher, die .config-Datei zu sichern, da diese dabei gelöscht wird. Achten Sie darauf hierzu keinen .bak oder ~ Suffix zu verwenden, da make distclean solche Dateien ebenfalls entfernt.

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

Aktualisierung des Bootloaders

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.

Nachdem Sie sichergestellt haben, dass die Partition /boot eingehängt ist,

Verwendung von grub-mkconfig

Der folgende Befehl kann ausgeführt werden, um die Konfigurationsdatei von Grub zu aktualisieren:

root #grub-mkconfig -o /boot/grub/grub.cfg
Warnung
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.
Tipp
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.

Entfernen des alten Kernels

Siehe Artikel zur Kernel Deinstallation.

Siehe auch

Externe Ressourcen