Пересборка ядра linux gentoo

Kernel/Upgrade

This article describes the steps to upgrade to a newer version of the Linux kernel.

Making a new kernel from the new sources is basically the same process as making a kernel when installing the system. The only difference is that one can save time by adjusting the old kernel configuration for the changes made in the new kernel instead of going through all the kernel options (like make menuconfig ) again.

A new kernel may have had options or features added or removed since the old kernel. 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 which are present in the configuration file of the old kernel anymore.

This article is a guide on how to deal with such changes of the configuration file by converting the old configuration to a configuration that can be used with the new kernel.

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.

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.

  • 1 Emerging the new kernel sources
  • 2 Set symlink to new kernel sources
    • 2.1 Default: Setting the link with eselect
    • 2.2 Alternative 1: Manually updating the symbolic link
    • 2.3 Alternative 2: Installing the kernel sources with the symlink USE flag
    • 4.1 Copy the previous kernel configuration
    • 4.2 Update the .config file
      • 4.2.1 make oldconfig
      • 4.2.2 make olddefconfig
      • 4.2.3 make help
      • 4.2.4 Observing the difference
      • 4.2.5 make menuconfig
      • 5.1 Automated build and installation
      • 5.2 Reinstalling external kernel modules
      • 5.3 Solving build problems
      • 6.1 Using grub-mkconfig
      • 6.2 Using systemd-boot-gen to update systemd-boot UEFI configuration
      • 7.1 Keeping the old kernel sources
      • 7.2 Removing the old kernel

      Emerging the new kernel sources

      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 the following command:

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

      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.

      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.

      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:

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

      To set the symlink with eselect :

      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:

      Alternative 1: Manually updating the symbolic link

      To set the symbolic link manually:

      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.

      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 the procfs filesystem, if the kernel option Enable access to .config through /proc/config.gz (CONFIG_IKCONFIG_PROC) was activated in the present kernel:
      • In the /etc/kernels/ directory, if SAVE_CONFIG=»yes» is set in /etc/genkernel.conf and genkernel was previously used:

      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:

      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:

      make help

      Use make help to see other conversion methods available:

      Observing the difference

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

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

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

      make menuconfig

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

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

      Build

      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 said external modules. 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.

      For this step, follow the steps in the manual configuration article.

      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-sources Automated 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 --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 > 

      Reinstalling external kernel modules

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

      Any external kernel modules, such as binary kernel modules, need to be rebuilt for each new kernel. If the kernel has not been built yet, it has to first be prepared for the building of the external kernel modules:

      Packages containing kernel modules can be rebuilt using the @module-rebuild set:

      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.

      Update the bootloader

      The upgraded and built kernel needs to be set up and eventually a bootloader or boot item updated, see Kernel/Configuration. 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:

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

      Warning
      Installing from cargo , the Rust package manager, should be done at one's own risk. The Gentoo project cannot verify 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 :

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

      And run it using root privileges:

      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:

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

      Removing the old kernel

      See also

      • Genkernel — a tool created by Gentoo used to automate the build process of the kernel and initramfs.
      • Dracut — an initramfs infrastructure and aims to have as little as possible hard-coded into the initramfs.
      • Kernel/Configuration
      • Updating GRUB to a new kernel

      External resources

      Источник

      Читайте также:  Виндовс на линукс ядре
Оцените статью
Adblock
detector