This is the fourth day of my participation in the More text Challenge. For details, see more text Challenge

Introduction to the kernel

# core

The kernel is the core of an operating system. It is responsible for the management of the system process, memory, device drivers, files and network system, determines the performance and stability of the system.

# open source

An important feature of Linux is that it is open source, and any software engineer around the world can add code that he or she thinks is good.

On the plus side, with the kernel’s source code, we can understand how the system works. Second, we can tailor the system to fit the bytes in our situation, which requires recompiling the kernel. Third, we can modify the kernel to suit our own needs, which is the equivalent of developing an operating system, although most of the work has already been done.

Why recompile the kernel

Linux as a free software, under the support of the vast number of enthusiasts, the kernel version is constantly updated. The new kernel fixes bugs in the old kernel and adds many new features. If users want to use these new features, or customize a more efficient and stable kernel for their system, they will need to recompile the kernel.

In general, newer kernels support more hardware, have better process management capabilities, are faster, more stable, and generally fix many of the vulnerabilities found in older versions. In order to properly set up the kernel compilation configuration options so that only the required functions are compiled, there are four main considerations:

  • Custom compiled kernels run faster (with less code)
  • The system will have more memory (kernel parts will not be swapped into virtual memory)
  • Compiling unwanted features into the kernel can increase vulnerabilities that can be exploited by system attackers
  • Compiling a function as a module is slower than compiling it into the kernel

Three, obtain the kernel source code

1. Website download

The official website for releasing the Linux kernel version is www.kernel.org. We can download the kernel source code and the corresponding patch file here.

2. Instruction installation

Redhat department

yum install -y kernel-devel
Copy the code

Debian system

apt install linux-source
Copy the code

The source code downloaded using the instructions will be placed in /usr/src, although the source code downloaded using the instructions may not match the current kernel version of the system. To download a specific version of the source code, use the following command

liyongjun@liyongjun-VirtualBox:~$sudo apt install linux-source-4.15.0Copy the code

Iv. Compile and install

compile

liyongjun@liyongjun-VirtualBox:~$ cdThe/usr/SRC/Linux - source - 4.15.0 / Linux - source - 4.15.0 liyongjun @ liyongjun - VirtualBox: $make ~Copy the code

Wait patiently for hours…

The installation

liyongjun@liyongjun-VirtualBox:~$sudo make install // Install the kernel liyongjun@liyongjun-VirtualBox:~$sudo make modules_install // Install the kernel moduleCopy the code

5. Modify boot items

After the kernel is installed, the system is restarted. Uname -a finds that the kernel has not changed.

1. This is the time to modify the grup

sudo vim /etc/default/grub
Copy the code

I’m going to change GRUB_TIMEOUT=0 to GRUB_TIMEOUT=5 and I’m going to want it to wait 5 seconds on boot so I can choose the kernel version,

But it is of no damn use

GRUB_DEFAULT=0; GRUB_DEFAULT=”1 >4″;

cat /boot/grub/grub.cfg
Copy the code

See the kernel Linux 4.15.18 that needs to be replaced in the 5th menuentry of the submenu. So fill in 4 here (the number starts at 0), and note that “1 >4” also has a space after the 1.

Run the following command to update:

sudo update-grub
Copy the code

Restart to check the kernel version

Liyongjun @ liyongjun - VirtualBox: ~ $uname -r 4.15.18Copy the code

The kernel is successfully replaced.