Summary of detailed methods for replacing the Linux kernel in the Ubuntu system

1. Write in front

  Recently, when reproducing Linux kernel vulnerabilities, it is often necessary to replace the Linux kernel version of the Ubuntu system, but the information on the Internet is uneven. In order to facilitate everyone to replace the Linux kernel version of the Ubuntu system, I wrote this blog to share with you. This blog provides two detailed methods for changing the Linux kernel version in the Ubuntu system. The first method is to download the Linux kernel source code for manual compilation and installation. This method is more complicated, but the flexibility is relatively high. You can configure the Linux kernel by yourself. Various settings, the second method is to automatically download and install the Linux kernel configured on the Linux official website. This method is relatively simple, but the flexibility is low, because you cannot configure various settings of the Linux kernel by yourself. The specific content of this blog is introduced here. For the specific two methods of replacing the Linux kernel version of the Ubuntu system, please refer to the following


2. Method 1 (Manually download, compile and install the Linux kernel and replace it)

  1. It should be noted in advance that in this method, the version of the Ubuntu system I use is 18.04.5 LTS (Desktop), but there is no additional requirement for the version of the Ubuntu system, any version of the Ubuntu system can use this method The replacement of the Linux kernel (indicating my own Ubuntu system version is entirely because I have obsessive-compulsive disorder ==!). We first check the version of the Linux kernel in the current Ubuntu system:
$ sudo uname -r
  1. It can be found that the Linux kernel version of the current system is 5.4.0-42-generic:
    Please add a picture description
  2. Then go to the root directory of the system, download the 5.5.0 version of the Linux kernel source code compression package and decompress it (of course, you can also use other versions of the Linux kernel, you can download the source code of each version of the Linux kernel from Tsinghua source ):
$ cd /
$ sudo wget https://mirrors.tuna.tsinghua.edu.cn/kernel/v5.x/linux-5.5.tar.gz
$ sudo tar -zxf linux-5.5.tar.gz
  1. Next, you can start preparing to compile and install the Linux kernel, but before officially compiling and installing the kernel, we need to do some preparatory work, that is, download and install some required software:
$ sudo apt-get update
$ sudo apt-get install g++
$ sudo apt-get install gcc
$ sudo apt-get install make
$ sudo apt-get install build-essential libncurses-dev bison flex libssl-dev
  1. Then we can officially start compiling and installing the Linux kernel. We enter the decompressed Linux kernel source code directory to clean up and configure compilation options:
$ cd linux-5.5/
$ sudo make distclean O=build
$ sudo make menuconfig
  1. After the following interface appears, select "Save" and press "Enter":
    insert image description here
  2. Then the following interface will appear, select "Ok" and press "Enter":
    insert image description here
  3. Then the following interface will appear, select "Exit" and press "Enter":
    insert image description here
  4. Then the following interface will appear, select "Exit" and press "Enter":
    insert image description here
  5. Then you will come to the command line interface. You only need to execute the following commands in order to complete the compilation and installation of the Linux 5.5.0 kernel and the installation of the kernel module:
$ sudo make -j4
$ sudo make -j4 modules_install
$ sudo make -j4 install
  1. Then use the following command to update the GRUB bootloader and reboot the system:
$ sudo update-grub
$ sudo reboot
  1. When the computer restarts, press the "Shift" key continuously until the following picture appears, select "Ubuntu Advanced Options" and press "Enter":
    insert image description here
  2. After selecting the red box, press the "Enter" key:
    insert image description here
  3. After entering the user name and password, you can enter the system:
    insert image description here
  4. After restarting the system, use the following command to view the Linux kernel version of the current system:
$ sudo uname -r
  1. It can be found that the current Linux kernel version has been successfully changed to 5.5.0:
    insert image description here

3. Method 2 (automatically download and install the Linux kernel and replace it)

  1. In this method, the Ubuntu system version we use is 16.04.1 LTS (Desktop). We first use the following command to check the Linux kernel version:
$ sudo uname -r
  1. It can be found that the Linux kernel version in the current system is 4.4.0-31-generic:
    insert image description here
  2. Then use the following command to view the kernel version that can be installed in the current Ubuntu version:
$ sudo apt-cache search linux | grep linux-image
  1. Executing the above command will show a lot of Linux kernels that we can download and install. We choose the 4.11.0-13-generic version of the Linux kernel to download and install:
    insert image description here
  2. Execute the following command to download the installed version of the kernel. For downloading and installing other versions of the Linux kernel, you only need to replace the version numbers in the following two commands:
$ sudo apt-get install linux-image-4.8.0-58-generic
$ sudo apt-get install linux-headers-4.8.0-58-generic
  1. After the installation is complete, execute the following command to restart the system:
$ reboot
  1. When the system restarts, press the "Esc" key until the following interface appears, select the red box and press "Enter":
    insert image description here
  2. Then the following interface will appear, select the red box and press "Enter":
    insert image description here
  3. Then enter the user name and password to enter the system:
    insert image description here
  4. After entering the system, use the following command to view the version of the Linux kernel in the current system:
$ sudo uname -r
  1. It can be found that the version of the Linux kernel in the current system has been successfully updated to 4.11.0-13-generic:
    insert image description here

4. Final summary

  The above is the whole content of this blog. I have introduced two methods to replace the Linux kernel version of the Ubuntu system. Each method is introduced very carefully. Readers will be able to successfully replace the Ubuntu system by following the process I introduced. Linux kernel version. This blog is over here, see you in the next blog!

Guess you like

Origin blog.csdn.net/IronmanJay/article/details/132395150