[LINUX kernel rebuild] Version upgrade (4.18.0 → 5.8.8)

Target

Complete the kernel version upgrade (4.18.0 → 5.8.8) installed in AWS EC2 (Red Hat Enterprise Linux 8 (HVM), SSD Volume Type).

Premise

One AWS EC2 server (Red Hat Enterprise Linux 8 (HVM), SSD Volume Type) has been built. In addition, kernel rebuilding will be smoother if you prepare some high system resources (CPU, memory, etc.) at the time of compilation and installation. Also, if you do not have a certain amount of disk space, you may get an error at compile time. In this article, the instance type is m5a.xlarge (0.344USD / hour) and the disk capacity is 50GB. tempsnip.png Also, keep in mind that it can take ** an hour or more ** to compile and install, depending on the specs.

What is kernel rebuilding (from LPIC text)

Compiling and installing the kernel as needed is called "kernel rebuilding". It seems that you should consider rebuilding the kernel in the following patterns.

-The required device driver (kernel module) is not included in the kernel. -I want to use a kernel optimized for the hardware I am using. -I want to use the latest features of the kernel.

You will need the gcc compiler, make utility, kernel source, and kernel headers to rebuild the kernel. Also, when rebuilding the kernel, it is necessary to recompile the kernel module as well.

Workflow

Item number title
1 Prepare the kernel source
2 Kernel settings
3 Compiling kernel and kernel modules
4 Kernel module and kernel installation
5 Confirmed

Reference books and reference sites

Linux textbook LPIC Level 2 Version 4.5 compatible How to rebuild the kernel on CentOS and enable the kernel module I tried compiling and installing the kernel (Linux-4.8.6)

procedure

1. Prepare the kernel source

** ① Installation of development tools ** After OS login, root switch

sudo su -

Check the current kernel version with ʻuname -r`

#Current kernel version is 4.18.0
[[email protected] ~]# uname -r
4.18.0-193.el8.x86_64

Install the tools required to rebuild the kernel (*). There were an unusually large number of tools that weren't installed, but I don't care. ..


#Install based on the reference site
yum groupinstall "Development Tools"
yum install kernel-devel
yum install rpm-build redhat-rpm-config unifdef
yum install ncurses ncurses-devel

#After that, additional installation is performed based on the error that actually occurred during make (compile).
yum install elfutils-libelf-devel
yum install openssl-devel
yum install bc

** ② Download kernel source ** Install the wget command (download the file by specifying the URL).

yum install wget

Select the kernel source from https://www.kernel.org/ and download it. This time, get the kernel version 5.8.8 (09-Sep-2020).

wget https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.8.8.tar.xz

Unzip and unpack.

tar Jxvf linux-5.8.8.tar.xz

Move to the directory of the extracted kernel source

cd linux-5.8.8

2. Kernel settings

** ① Update the existing configuration file with make old config ** Copy the config file used by the current kernel to .config (kernel config file) to avoid creating a kernel config file from scratch.

cp -p /boot/config-4.18.0-193.el8.x86_64 .config

Update the kernel configuration. By using make oldconfig, you can inquire only about the functions added in the new kernel. It is possible to use the existing settings as they are for the existing settings.

In this article, all new items are set to the default settings (just press Enter without typing y or n). For the "Kernel compression mode" that needs to be set, this time it was set to "1. Gzip (KERNEL_GZIP)".

make oldconfig
#Output example of make old config
[[email protected] linux-5.8.8]# make oldconfig
scripts/kconfig/conf  --oldconfig Kconfig
.config:1089:warning: symbol value 'm' invalid for NF_CT_PROTO_GRE
.config:2949:warning: symbol value 'm' invalid for ISDN_CAPI
*
* Restart config...
*
*
* General setup
*

#Items that have existed in the past are automatically diverted as they are
Compile also drivers which will not load (COMPILE_TEST) [N/y/?] n          
Local version - append to kernel release (LOCALVERSION) []
Automatically append version information to the version string (LOCALVERSION_AUTO) [N/y/?] n

# (NEW)Inquire here only for new items that are described as
Build ID Salt (BUILD_SALT) [](NEW)
Kernel compression mode
> 1. Gzip (KERNEL_GZIP)
  2. Bzip2 (KERNEL_BZIP2)
  3. LZMA (KERNEL_LZMA)
  4. XZ (KERNEL_XZ)
  5. LZO (KERNEL_LZO)
  6. LZ4 (KERNEL_LZ4)
choice[1-6?]: 1
(abridgement)

** ② Fine-tune kernel settings using make menuconfig ** Furthermore, by using make menuconfig, it is possible to make adjustments with the selection formula of each setting item of the kernel. This time, use make menuconfig to correct (*) the kernel settings that caused the compilation error in the verification stage.

According to the reference site, the kernel setting that causes the error is an item called CONFIG_SYSTEM_TRUSTED_KEYS (If you copy the existing kernel configuration file under / boot, this item seems to cause a compile error unless you correct it to an empty string)

[[email protected] linux-5.8.8]# cat .config | grep "CONFIG_SYSTEM_TRUSTED_KEYS"
CONFIG_SYSTEM_TRUSTED_KEYS="certs/rhel.pem"

Start modifying the kernel settings.

make menuconfig

When the following console appears, you can use the cursor to set the kernel configuration. Move the cursor to the red frame part of the image below and press Enter to select it. tempsnip.png tempsnip.png tempsnip.png Erase the string listed by default, empty it and Enter tempsnip.png Finally save to .config tempsnip.png キャプチャ.PNG

Check the contents of .config to see if the changes are reflected

[[email protected] linux-5.8.8]# cat .config | grep "CONFIG_SYSTEM_TRUSTED_KEYS"
CONFIG_SYSTEM_TRUSTED_KEYS=""

3. Compile kernel and kernel modules

Compile the kernel and kernel modules with make. It can be executed without arguments, but this compilation process takes a considerable amount of time, so use the -j option to change the number of parallel processes to shorten the compilation time (*). With the configuration in this article, it took less than an hour to compile.

#Start the optimum number of processes according to the number of CPU cores
JOBS=$[$(grep cpu.cores /proc/cpuinfo | sort -u | sed 's/[^0-9]//g') + 1]
make -j${JOBS}

#The following error occurs during make
BTF: .tmp_vmlinux.btf: pahole (pahole) is not available
Failed to generate BTF for vmlinux
Try to disable CONFIG_DEBUG_INFO_BTF

#As told, CONFIG_DEBUG_INFO_Disable BTF
[[email protected] linux-5.8.8]# cat .config | grep CONFIG_DEBUG_INFO_BTF
CONFIG_DEBUG_INFO_BTF=n

4. Kernel module and kernel installation

** ① Kernel module installation **

#Complete without any errors
make modules_install

It is OK if the / lib / modules / kernel version directory is configured as shown below.

[[email protected] linux-5.8.8]# ls -l /lib/modules/5.8.8/
total 3440
lrwxrwxrwx.  1 root root     17 Sep 10 09:46 build -> /root/linux-5.8.8
drwxr-xr-x. 13 root root    141 Sep 10 09:47 kernel
-rw-r--r--.  1 root root 873761 Sep 10 09:47 modules.alias
-rw-r--r--.  1 root root 837562 Sep 10 09:47 modules.alias.bin
-rw-r--r--.  1 root root   8171 Sep 10 09:46 modules.builtin
-rw-r--r--.  1 root root  10467 Sep 10 09:47 modules.builtin.bin
-rw-r--r--.  1 root root  62064 Sep 10 09:46 modules.builtin.modinfo
-rw-r--r--.  1 root root 278819 Sep 10 09:47 modules.dep
-rw-r--r--.  1 root root 389096 Sep 10 09:47 modules.dep.bin
-rw-r--r--.  1 root root    405 Sep 10 09:47 modules.devname
-rw-r--r--.  1 root root  99497 Sep 10 09:46 modules.order
-rw-r--r--.  1 root root    521 Sep 10 09:47 modules.softdep
-rw-r--r--.  1 root root 422378 Sep 10 09:47 modules.symbols
-rw-r--r--.  1 root root 510059 Sep 10 09:47 modules.symbols.bin
lrwxrwxrwx.  1 root root     17 Sep 10 09:46 source -> /root/linux-5.8.8

** ② Kernel installation **


#Complete without any error (Be sure to check that it ends without any error. I restarted with an error and the server did not start.)
make install -j${JOBS}

It is OK if the kernel image / boot / vmlinuz-kernel version exists in / boot as shown below.

[[email protected] ~]# ls -l /boot/vmlinuz*
lrwxrwxrwx. 1 root root      19 Sep 10 09:47 /boot/vmlinuz -> /boot/vmlinuz-5.8.8
-rwxr-xr-x. 1 root root 8913760 Apr 23 05:16 /boot/vmlinuz-0-rescue-bb64a14c7512444f9744c3076505b65f
-rwxr-xr-x. 1 root root 8920432 Sep 10 08:05 /boot/vmlinuz-0-rescue-ec211058807a3398326019a9b3f9e8bf
-rwxr-xr-x. 1 root root 8920432 Aug 26 19:47 /boot/vmlinuz-4.18.0-193.19.1.el8_2.x86_64
-rwxr-xr-x. 1 root root 8913760 Mar 27 14:48 /boot/vmlinuz-4.18.0-193.el8.x86_64
-rw-r--r--. 1 root root 8613632 Sep 10 09:47 /boot/vmlinuz-5.8.8

5. Confirmation of completion

After rebooting, it is OK if the kernel version is changed as follows.

[[email protected] ~]# uname -r
5.8.8

Recommended Posts

[LINUX kernel rebuild] Version upgrade (4.18.0 → 5.8.8)
Check Linux kernel version
Get the latest Linux kernel version with Arch Linux
Solus Linux upgrade problem
About Linux kernel parameters
Linux kernel release 5.x (2/4)
Linux kernel release 5.x (3/4)
Linux kernel build time
Linux kernel release 5.x (4/4)
Linux kernel release 5.x (1/4)
Linux Kernel Build for DE10nano
Self-build linux kernel with clang
What is the Linux kernel?
Rebuild kernel on Ubuntu 20.04 (on Azure)
Version upgrade of python Anaconda
Linux kernel memory model related documentation
Linux kernel, its 29-year history report
Try the Linux kernel lockdown mechanism
Bitnami Redmine (Linux version) recovery procedure
[Linux] [kernel module] Create kthread in kernel module
linux (kernel) source analysis: system call call
How to check Linux OS version
Linux non-volatile memory (NVDIMM) support (2020 version)