How to compile the kernel for linux
Download the kernel
We want The first thing to do is download the kernel source code. Find the URL of the required kernel you want to download at Kernel.org. After finding the URL, use the following command (I take the 4.17 RC2 kernel as an example) to download the source code file:
wget https://git.kernel.org/torvalds/t/linux-4.17-rc2.tar.gz
Install the required environment
In order to compile the kernel , we first have to install some 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: you will need at least 128GB of local free disk space to complete the kernel compilation process. So you have to make sure you have enough space.
Decompress the source code
In the folder where the newly downloaded kernel is located, use this command to decompress the kernel:
tar xvzf linux-4.17-rc2.tar.gz
Use the command cd linux-4.17-rc2 Enter the newly generated folder.
Configuring the kernel
Before officially compiling the kernel, we must first configure which modules need to be included. Actually, there are some very simple ways to configure it. Using one command, you can copy the current kernel configuration files and then use the reliable menuconfig command to make any necessary changes. Use the following command to complete:
cp /boot/config-$(uname -r) .config
Now that you have a configuration file, enter the command make menuconfig. This command will open a configuration tool that allows you to iterate through each available module and enable or disable the ones you need or don't need.
There is a good chance that you will disable an important part of the kernel, so proceed step by step carefully during menuconfig. If you're not sure about an option, leave it alone. Or better yet, use a copy of the config file for the currently running kernel (since we know it works). Once you've gone through the entire configuration list (it's quite long), you're ready to start compiling.
Compiling and Installing
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 the existing kernel you are upgrading and the upgraded kernel.
After answering the lengthy questions, you can install the previously enabled modules using the following command:
make modules_install
This command will take some time.
Now we use this command to install the kernel:
sudo make install
Once again, another command that is going to take a considerable amount of time. In fact, the make install command will take more time than the make modules_install command.
Enable the kernel as a boot
Once the make install command has completed, it is time to enable the kernel as a boot. Use this command to achieve:
sudo update-initramfs -c -k 4.17-rc2
Of course, you need to replace the above kernel version number with the one you compiled. When the command completes, use the following command to update grub:
sudo update-grub
Now you can reboot the system and select the newly installed kernel.
Recommended: Linux usage tutorial
The above is the detailed content of How to compile the linux kernel. For more information, please follow other related articles on the PHP Chinese website!