Get the App
SLTechnology News&Howtos  ›  Servers  › 

To download and configure the linux kernel

Shulou Source: shulou.com Published: 2022-06-02 21:50:47 09月22日 Update

This article uses simple and easy-to-understand examples to introduce the steps to download and configure the linux kernel. The code is very detailed. Interested friends can refer to it for reference. I hope it can help you.

download a kernel

The first thing we do is download the kernel source code. Find the URL of the kernel you want to download at Kernel.org Once the URL is found, download the source file using the following command (I'll use the 4.17 RC2 kernel as an example):

wget https://git.kernel.org/torvalds/t/linux-4.17-rc2.tar.gz

Installation environment required

To compile the kernel, we first have to install some of the required environments. This can be done with a single command.

sudo apt-get install git fakeroot build-essential ncurses-dev xz-utils libssl-dev bc flex libelf-dev bison

It is important to note that you will need at least 128GB of locally available disk space to complete the kernel compilation process. So you have to make sure you have enough space.

Extract source code

Under the folder where the newly downloaded kernel is located, use this command to extract the kernel:

tar xvzf linux-4.17-rc2.tar.gz

Use cd linux-4.17-rc2 to enter the newly generated folder.

configure the kernel

Before we can compile the kernel, we must first configure which modules we want to include. Actually, there are some very simple ways to configure it. With a single command, you can copy the current kernel configuration file and then use the trusty menuconfig command to make any necessary changes. Use the following command to do this:

cp /boot/config-$(uname -r) .config

Now that you have a profile, type the command make menuconfig. This command opens a configuration tool that lets you traverse each available module and enable or disable the ones you want or don't want.

Chances are you'll disable an important part of the kernel, so proceed carefully during menuconfig. If you are unsure about an option, leave it alone. Or better yet, use our copy of the currently running kernel configuration file (because we know it works). Once you've traversed the entire configuration list (which is very long), you're ready to start compiling.

compile and install

Now it's time to actually compile the kernel. The first step is to compile using the make command. Call the make command and answer the necessary questions. These questions depend on which existing kernel you will upgrade and which kernel you will upgrade.

After answering the lengthy questions, you can install the previously enabled modules with the following command:

make modules_install

This command will take some time.

Now we install the kernel using this command:

sudo make install

Again, another command that will take a considerable amount of time. In fact, the make install command will take more time than the make modules_install command.

Enable kernel as boot

Once the make install command is complete, it's time to start the kernel as a boot. Use this command to achieve:

sudo update-initramfs -c -k 4.17-rc2

Of course, you'll need to replace the kernel version numbers above with the ones you compiled. When the command is complete, update grub with the following command:

sudo update-grub

You can now restart the system and select the newly installed kernel.

The steps to download and configure the linux kernel are shared here. I hope the above content can help you and learn more. If you think the article is good, you can share it so that more people can see it.

Tags: Kernel commands configuration compilation files modules time more source code problems steps necessary actual copy folder time environment space upgrade help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Information Docker vpn Linux