Chapter 5. Manually upgrading the kernel

The Red Hat Enterprise Linux kernel is custom-built by the Red Hat Enterprise Linux kernel team to ensure its integrity and compatibility with supported hardware. Before Red Hat releases a kernel, it must first pass a rigorous set of quality assurance tests.

Red Hat Enterprise Linux kernels are packaged in the RPM format so that they are easy to upgrade and verify using the Yum or PackageKit package managers. PackageKit automatically queries the Red Hat Content Delivery Network servers and informs you of packages with available updates, including kernel packages.

This chapter is therefore only useful for users who need to manually update a kernel package using the rpm command instead of yum.

Warning

Whenever possible, use either the Yum or PackageKit package manager to install a new kernel because they always install a new kernel instead of replacing the current one, which could potentially leave your system unable to boot.

Warning

Custom kernels are not supported by Red Hat. However, guidance can be obtained from the knowledgebase document https://access.redhat.com/solutions/25039.

For more information on installing kernel packages with yum, see https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/ch-yum.html#sec-Updating_Packages.

For information on Red Hat Content Delivery Network, see https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/chap-Subscription_and_Support-Registering_a_System_and_Managing_Subscriptions.html.

5.1. Overview of kernel packages

Red Hat Enterprise Linux contains the following kernel packages:

  • kernel — Contains the kernel for single-core, multi-core, and multi-processor systems.
  • kernel-debug — Contains a kernel with numerous debugging options enabled for kernel diagnosis, at the expense of reduced performance.
  • kernel-devel — Contains the kernel headers and makefiles sufficient to build modules against the kernel package.
  • kernel-debug-devel — Contains the development version of the kernel with numerous debugging options enabled for kernel diagnosis, at the expense of reduced performance.
  • kernel-doc — Documentation files from the kernel source. Various portions of the Linux kernel and the device drivers shipped with it are documented in these files. Installation of this package provides a reference to the options that can be passed to Linux kernel modules at load time.

    By default, these files are placed in the /usr/share/doc/kernel-doc-kernel_version/ directory.

  • kernel-headers — Includes the C header files that specify the interface between the Linux kernel and user-space libraries and programs. The header files define structures and constants that are needed for building most standard programs.
  • linux-firmware — Contains all of the firmware files that are required by various devices to operate.
  • perf — This package contains the perf tool, which enables performance monitoring of the Linux kernel.
  • kernel-abi-whitelists — Contains information pertaining to the Red Hat Enterprise Linux kernel ABI, including a lists of kernel symbols that are needed by external Linux kernel modules and a yum plug-in to aid enforcement.
  • kernel-tools — Contains tools for manipulating the Linux kernel and supporting documentation.

5.2. Preparing to upgrade

Before upgrading the kernel, it is recommended that you take some precautionary steps.

First, ensure that working boot media exists for the system in case a problem occurs. If the boot loader is not configured properly to boot the new kernel, you can use this media to boot into Red Hat Enterprise Linux

USB media often comes in the form of flash devices sometimes called pen drives, thumb disks, or keys, or as an externally-connected hard disk device. Almost all media of this type is formatted as a VFAT file system. You can create bootable USB media on media formatted as ext2, ext3, ext4, or VFAT.

You can transfer a distribution image file or a minimal boot media image file to USB media. Make sure that sufficient free space is available on the device. Around 4 GB is required for a distribution DVD image, around 700 MB for a distribution CD image, or around 10 MB for a minimal boot media image.

You must have a copy of the boot.iso file from a Red Hat Enterprise Linux installation DVD, or installation CD-ROM #1, and you need a USB storage device formatted with the VFAT file system and around 16 MB of free space.

For more information on using USB storage devices, review https://access.redhat.com/solutions/624423 How to format a USB key and https://access.redhat.com/solutions/39373 How to manually mount a USB flash drive in a non-graphical environment.

The following procedure does not affect existing files on the USB storage device unless they have the same path names as the files that you copy onto it. To create USB boot media, perform the following commands as the root user:

  1. Install the syslinux package if it is not installed on your system. To do so, as root, run the yum install syslinux command.
  2. Install the SYSLINUX bootloader on the USB storage device:

    # syslinux /dev/sdX1

    …​where sdX is the device name.

  3. Create mount points for boot.iso and the USB storage device:

    # mkdir /mnt/isoboot /mnt/diskboot
  4. Mount boot.iso:

    # mount -o loop boot.iso /mnt/isoboot
  5. Mount the USB storage device:

    # mount /dev/sdX1 /mnt/diskboot
  6. Copy the ISOLINUX files from the boot.iso to the USB storage device:

    # cp /mnt/isoboot/isolinux/* /mnt/diskboot
  7. Use the isolinux.cfg file from boot.iso as the syslinux.cfg file for the USB device:

    # grep -v local /mnt/isoboot/isolinux/isolinux.cfg > /mnt/diskboot/syslinux.cfg
  8. Unmount boot.iso and the USB storage device:

    # umount /mnt/isoboot /mnt/diskboot
  9. Reboot the machine with the boot media and verify that you are able to boot with it before continuing.

Alternatively, on systems with a floppy drive, you can create a boot diskette by installing the mkbootdisk package and running the mkbootdisk command as root. See man mkbootdisk man page after installing the package for usage information.

To determine which kernel packages are installed, execute the command yum list installed "kernel-*" at a shell prompt. The output comprises some or all of the following packages, depending on the system’s architecture, and the version numbers might differ:

# yum list installed "kernel-*"
kernel.x86_64                   3.10.0-54.0.1.el7           @rhel7/7.0
kernel-devel.x86_64             3.10.0-54.0.1.el7           @rhel7
kernel-headers.x86_64           3.10.0-54.0.1.el7           @rhel7/7.0

From the output, determine which packages need to be downloaded for the kernel upgrade. For a single processor system, the only required package is the kernel package. See Section 5.1, “Overview of kernel packages” for descriptions of the different packages.

5.3. Downloading the upgraded kernel

There are several ways to determine if an updated kernel is available for the system.

If yum was used to download and install the updated kernel from the Red Hat Network, follow the instructions in Section 5.5, “Verifying the initial RAM file system image” and Section 5.6, “Verifying the boot loader” only, do not change the kernel to boot by default. Red Hat Network automatically changes the default kernel to the latest version. To install the kernel manually, continue to Section 5.4, “Performing the upgrade”.

5.4. Performing the upgrade

After retrieving all of the necessary packages, it is time to upgrade the existing kernel.

Important

It is strongly recommended that you keep the old kernel in case there are problems with the new kernel.

At a shell prompt, change to the directory that contains the kernel RPM packages. Use -i argument with the rpm command to keep the old kernel. Do not use the -U option, since it overwrites the currently installed kernel, which creates boot loader problems. For example:

# rpm -ivh kernel-kernel_version.arch.rpm

The next step is to verify that the initial RAM file system image has been created. See Section 5.5, “Verifying the initial RAM file system image” for details.

5.5. Verifying the initial RAM file system image

The job of the initial RAM file system image is to preload the block device modules, such as for IDE, SCSI or RAID, so that the root file system, on which those modules normally reside, can then be accessed and mounted. On Red Hat Enterprise Linux 7 systems, whenever a new kernel is installed using either the Yum, PackageKit, or RPM package manager, the Dracut utility is always called by the installation scripts to create an initramfs (initial RAM file system image).

If you make changes to the kernel attributes by modifying the /etc/sysctl.conf file or another sysctl configuration file, and if the changed settings are used early in the boot process, then rebuilding the Initial RAM File System Image by running the dracut -f command might be necessary. An example is if you have made changes related to networking and are booting from network-attached storage.

On all architectures other than IBM eServer System i (see the section called “Verifying the initial RAM file system image and kernel on IBM eServer System i”), you can create an initramfs by running the dracut command. However, you usually do not need to create an initramfs manually: this step is automatically performed if the kernel and its associated packages are installed or upgraded from RPM packages distributed by Red Hat.

You can verify that an initramfs corresponding to your current kernel version exists and is specified correctly in the grub.cfg configuration file by following this procedure:

Verifying the initial RAM file system image

  1. As root, list the contents in the /boot directory and find the kernel (vmlinuz-kernel_version) and initramfs-kernel_version with the latest (most recent) version number:

    Example 5.1. Ensuring that the kernel and initramfs versions match

    # ls /boot
    config-3.10.0-67.el7.x86_64
    config-3.10.0-78.el7.x86_64
    efi
    grub
    grub2
    initramfs-0-rescue-07f43f20a54c4ce8ada8b70d33fd001c.img
    initramfs-3.10.0-67.el7.x86_64.img
    initramfs-3.10.0-67.el7.x86_64kdump.img
    initramfs-3.10.0-78.el7.x86_64.img
    initramfs-3.10.0-78.el7.x86_64kdump.img
    initrd-plymouth.img
    symvers-3.10.0-67.el7.x86_64.gz
    symvers-3.10.0-78.el7.x86_64.gz
    System.map-3.10.0-67.el7.x86_64
    System.map-3.10.0-78.el7.x86_64
    vmlinuz-0-rescue-07f43f20a54c4ce8ada8b70d33fd001c
    vmlinuz-3.10.0-67.el7.x86_64
    vmlinuz-3.10.0-78.el7.x86_64

    Example 5.1, “Ensuring that the kernel and initramfs versions match” shows that:

    • we have three kernels installed (or, more correctly, three kernel files are present in the /boot directory),
    • the latest kernel is vmlinuz-3.10.0-78.el7.x86_64, and
    • an initramfs file matching our kernel version, initramfs-3.10.0-78.el7.x86_64kdump.img, also exists.

      Important

      In the /boot directory you might find several initramfs-kernel_versionkdump.img files. These are special files created by the Kdump mechanism for kernel debugging purposes, are not used to boot the system, and can safely be ignored. For more information on kdump, see the Red Hat Enterprise Linux 7 Kernel Crash Dump Guide.

  2. If your initramfs-kernel_version file does not match the version of the latest kernel in the /boot directory, or, in certain other situations, you might need to generate an initramfs file with the Dracut utility. Simply invoking dracut as root without options causes it to generate an initramfs file in /boot for the latest kernel present in that directory:

    # dracut

    You must use the -f, --force option if you want dracut to overwrite an existing initramfs (for example, if your initramfs has become corrupt). Otherwise dracut refuses to overwrite the existing initramfs file:

    # dracut
              Does not override existing initramfs (/boot/initramfs-3.10.0-78.el7.x86_64.img) without --force

    You can create an initramfs in the current directory by calling dracut initramfs_name kernel_version :

    # dracut "initramfs-$(uname -r).img" $(uname -r)

    If you need to specify specific kernel modules to be preloaded, add the names of those modules (minus any file name suffixes such as .ko) inside the parentheses of the add_dracutmodules+="module more_modules " directive of the /etc/dracut.conf configuration file. You can list the file contents of an initramfs image file created by dracut by using the lsinitrd initramfs_file command:

    # lsinitrd /boot/initramfs-3.10.0-78.el7.x86_64.img
    Image: /boot/initramfs-3.10.0-78.el7.x86_64.img: 11M
    ========================================================================
    dracut-033-68.el7
    ========================================================================
    
    drwxr-xr-x  12 root     root            0 Feb  5 06:35 .
    drwxr-xr-x   2 root     root            0 Feb  5 06:35 proc
    lrwxrwxrwx   1 root     root           24 Feb  5 06:35 init -> /usr/lib/systemd/systemd
    drwxr-xr-x  10 root     root            0 Feb  5 06:35 etc
    drwxr-xr-x   2 root     root            0 Feb  5 06:35 usr/lib/modprobe.d
    [output truncated]

    See man dracut and man dracut.conf for more information on options and usage.

  3. Examine the /boot/grub2/grub.cfg configuration file to ensure that an initramfs-kernel_version.img file exists for the kernel version you are booting. For example:

    # grep initramfs /boot/grub2/grub.cfg
    initrd16 /initramfs-3.10.0-123.el7.x86_64.img
    initrd16 /initramfs-0-rescue-6d547dbfd01c46f6a4c1baa8c4743f57.img

    See Section 5.6, “Verifying the boot loader” for more information.

Verifying the initial RAM file system image and kernel on IBM eServer System i

On IBM eServer System i machines, the initial RAM file system and kernel files are combined into a single file, which is created with the addRamDisk command. This step is performed automatically if the kernel and its associated packages are installed or upgraded from the RPM packages distributed by Red Hat thus, it does not need to be executed manually. To verify that it was created, run the following command as root to make sure the /boot/vmlinitrd-kernel_version file already exists:

# ls -l /boot/

The kernel_version needs to match the version of the kernel just installed.

Reversing the changes made to the initial RAM file system image

In some cases, for example, if you misconfigure the system and it no longer boots, you need to reverse the changes made to the Initial RAM File System Image by following this procedure:

Reversing Changes Made to the Initial RAM File System Image

  1. Reboot the system choosing the rescue kernel in the GRUB menu.
  2. Change the incorrect setting that caused the initramfs to malfunction.
  3. Recreate the initramfs with the correct settings by running the following command as root:

    # dracut --kver kernel_version --force

The above procedure might be useful if, for example, you incorrectly set the vm.nr_hugepages in the sysctl.conf file. Because the sysctl.conf file is included in initramfs, the new vm.nr_hugepages setting gets applied in initramfs and causes rebuilding of the initramfs. However, because the setting is incorrect, the new initramfs is broken and the newly built kernel does not boot, which necessitates correcting the setting using the above procedure.

Listing the contents of the initial RAM file system image

To list the files that are included in the initramfs, run the following command as root:

# lsinitrd

To only list files in the /etc directory, use the following command:

# lsinitrd | grep etc/

To output the contents of a specific file stored in the initramfs for the current kernel, use the -f option:

# lsinitrd -f filename

For example, to output the contents of sysctl.conf, use the following command:

# lsinitrd -f /etc/sysctl.conf

To specify a kernel version, use the --kver option:

# lsinitrd --kver kernel_version -f /etc/sysctl.conf

For example, to list the information about kernel version 3.10.0-327.10.1.el7.x86_64, use the following command:

# lsinitrd --kver 3.10.0-327.10.1.el7.x86_64 -f /etc/sysctl.conf

5.6. Verifying the boot loader

You can install a kernel either with the yum command or with the rpm command.

When you install a kernel using rpm, the kernel package creates an entry in the boot loader configuration file for that new kernel.

Note that both commands configure the new kernel to boot as the default kernel only when you include the following setting in the /etc/sysconfig/kernel configuration file:

DEFAULTKERNEL=kernel
UPDATEDEFAULT=yes

The DEFAULTKERNEL option specifies the default kernel package type. The UPDATEDEFAULT option specifies whether the new kernel package makes the new kernels the default.