The experiment of distributed and cloud computing course requires that I compile and install the latest version of the Linux kernel respectively in the Linux environment and Windows environment, during which I went through a lot of pits, so I record the correct and simple steps here, for convenience of reference and readers later.
I. Environmental description
Linux kernel 5.5.9 (latest stable as of March 17, 2020) was compiled using Centos7.8.
Decompress the kernel
1. Upload the kernel file downloaded from the official website to Linux, as shown in the figure.
2. Decompress the decompression package to the /usr/src/kernels directory
3. Configure compilation parameters
If you do not upgrade GCC, you need to upgrade GCC, otherwise it cannot meet the compilation requirements of the new version of the kernel. During the upgrade process, you can refer to the three commands to upgrade GCC under Centos7 or refer to the relevant information.
1. There are many kernel compilation parameters and many configuration methods. In order to keep compatible with the current system, I choose to configure the kernel compilation parameters on the basis of existing ones. Copy the compiled configuration of the existing kernel:
2. Configure on the basis of the existing kernel:
The.config command is used to specify only the items that are not in the.config file. After you type this command, you will be presented with one option after another to choose from. Just press enter and the default Settings will be used. Hit enter for about two or three minutes, and then the configuration is done, and it generates a.config file in the source code root directory, and that’s the configuration for this compilation, and the.config file that I copied from it becomes.config.old.
Compile the source code
There may be some errors here, just install the required dependency packages as required
Where, “make all” is to compile all selected modules, “-j4” is an optional parameter to allow four tasks to run simultaneously, which is faster, and 4 is the number of CPU cores in my machine. This process is usually slow, depending on which project you choose to build, and hardware performance. I used 4 cores, and it ended up taking 2 hours.
Install the kernel
Compilation simply turns the source code into executable files, but so far, these executables are not placed in the appropriate directory, and the new kernel is not registered with the bootloader. Installation module:
After executing this command, the kernel module’s executable file will be copied to /lib/modules/. If you go to this directory, you can find a folder named 5.5.9, which is the kernel module’s executable file. Register a startup:
This command registers the kernel with the boot program. When booting, the boot program will call the registered kernel to boot the system. If there are multiple kernels, the user can choose which kernel to boot from.
Check the current system default kernel version:
6. Set the new kernel version as the default boot kernel
1. Modify the startup file
Copy the bzImage file for the new kernel to the /boot directory
Copy the System. Map file of the new kernel to the /boot directory
Delete the original System default system. map file and make a soft connection to the system. map-5.5.9 file that was just copied to /boot and name it system. map instead of the deleted system. map file. Generate the corresponding init file in the /boot directory.
0 indicates the first menuentry segment in the /boot/grub2/grub. CFG file. In this case, the new kernel is entered by default.
After the restart, a new kernel option is displayed on the startup screen. If you do not select the default system, the newly installed Linux kernel 5.5.9 is displayed.
Looking at the system kernel version, you can see that updates have taken place at this point. Kernel upgrade successful!
How to compile and install the Linux kernel under Windows