Kernel/Upgraden

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

Dit artikel beschrijft de stappen om naar een nieuwe kernel te upgraden.

Het upgraden van een nieuwe kernel vanuit de broncode is vrijwel gelijk aan het bouwen van een kernel vanuit broncode bij het installeren van het gehele systeem. Het verschil is dat de configuratie van de oude kernel kan worden gebruikt voor de configuratie van de nieuwe kernel, wat uiteraard tijd scheelt omdat u niet alle opties opnieuw hoeft te beoordelen (bijvoorbeeld met make menuconfig).

De configuratie van de kernel wordt opgeslagen in een bestand met de naam .config in de map met de kernel broncode. De kernel configuratie bepaalt of een optie of mogelijkheid beschikbaar zal zijn, in de kernel of wellicht in een module, die kan worden geladen wanneer dat noodzakelijk mocht blijken. Een nieuwe kernel heeft mogelijk andere opties en mogelijkheden dan de oude kernel, het configuratiebestand kan dan ook nieuwe regels hebben, maar er kunnen ook regels verwijderd zijn ten opzichte van de configuratie van de oude kernel.

Om hiermee te kunnen omgaan moet de configuratie van de oude kernel worden omgezet naar een configuratie voor de nieuwe kernel. Dit artikel zal dat beschrijven.

Kernel upgrade in Gentoo involves these steps:

  • Step 1: Emerging the new kernel sources.
  • Step 2: Setting the right symlink to the new kernel.
  • Step 3: Moving to the new kernel's folder.
  • Step 4: Adjusting the .config file for the options introduced to, or removed from the new kernel's configuration.
  • Step 5: Building the kernel and the initramfs.
  • Step 6: Updating the bootloader.
  • Step 7: Removing or keeping the old kernel.


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.

Een kernel upgrade is mogelijk een goed idee wanneer nieuwe kernel broncode is geïnstalleerd. Nieuwe kernel broncode wordt soms geïnstalleerd tijdens een systeem update, bijvoorbeeld met de volgende opdracht:

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

Uiteraard kunt u deze ook handmatig installeren met de volgende opdracht (vervang gentoo-sources met de variant die in gebruik is):

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

Het installeren van nieuwe kernelbroncode geeft de gebruiker geen nieuwe kernel, het is slechts een noodzakelijke stap om een nieuwe kernel te bouwen en installeren vanuit de broncode, waarna het systeem opnieuw zal moeten worden opgestart om de nieuwe kernel te gebruiken.

Configuratie

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.

De symbolische link /usr/src/linux zou altijd moeten verwijzen naar de map waarin de kernel broncode staat van de kernel die momenteel gebruikt word. Dit kan op een van de volgende drie manieren gedaan worden:

  1. Installeer de kernel broncode met USE="symlink"
  2. Stel de link in met eselect
  3. De symbolische link handmatig updaten

Stel de link in met 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

De symbolische link handmatig updaten

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

Installeer de kernel broncode met de 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
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.

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:

  • In het procfs bestandssysteem, als de kernel optie Enable access to .config through /proc/config.gz werd geactiveerd in jouw huidige kernel:
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
  • In de map /boot, als de configuratie daar aanwezig is:
root #cp /boot/config-3.14.14-gentoo /usr/src/linux/.config
  • In de kernel map van de huidige kernel die je draait:
root #cp /usr/src/linux-3.14.14-gentoo/.confg /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

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

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

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

And which have been removed:

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.

Bouwen

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.

Voor deze stap, volg je de stappen die vermeld staan in het manueel configureren artikel.

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() {
# 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
}

Externe kernel modules herinstalleren

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

Enige externe kernel modules, zoals bijvoorbeeld binaire kernel modules, dienen opnieuw gebouwd te worden voor elke nieuwe kernel. Als de kernel nog niet gebouwd was, dient deze eerst voorbereid te worden voor het bouwen van externe kernel modules.

root #make modules_prepare

Je kan de pakketten herbouwen met de @module-rebuild verzameling:

root #emerge --ask @module-rebuild

Solving build problems

When experiencing build problems while rebuilding the current kernel, it might help to sanitize the kernel sources. Make sure to backup the .config file first, as the operation will remove it. Make sure not to use a .bak or ~ suffix as backup as make distclean will clean those up as well.

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 built kernel needs to be set up and eventually a bootloader or boot item updated, see Kernel/Configuration#Setup. Users of Grub can use the method below, users of other bootloaders must consult the handbook.

After making 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

Using systemd-boot-gen to update systemd-boot UEFI configuration

Warning
Installing from the cargo, the Rust package manager, should be done at one's own risk. The Gentoo project cannot what is built from it and could contain security risks particularly at the bootloader level. This could mean installing a rootkit if compromised. Proceed with the following section with caution.

Manual installation of systemd-boot-gen:

user $cargo install systemd-boot-gen

Copy the kernel parameters to /etc/default/cmdline, the file should contain:

FILE /etc/default/cmdline
CMDLINE="<kernel command line parameters>"

And run it using root privileges:

user $sudo ~/.cargo/bin/systemd-boot-gen

This will generate the boot configuration in /boot/loader/entries/ for all the available /boot/vmlinuz-* that have a matching /boot/initramfs-*.

Keeping or removing the old kernel

Keeping the old kernel sources

Kernel sources will eventually become unsupported. Some packages require the current sources to build. To protect the new sources from being removed by a depclean, it can be added to the world file (/var/lib/portage/world) by:

root #emerge --noreplace sys-kernel/gentoo-sources:newsource.version.here

Old sources that are no longer supported can be removed from the world file by:

root #emerge --deselect sys-kernel/gentoo-sources:unwanted.version.here

Verwijderen

Zie het kernel verwijderen artikel.

Zie ook

Externe links