Home >System Tutorial >LINUX >How to build the necessary packages for custom Linux kernel source code compilation?
Building a custom kernel on Debian/Ubuntu
The Linux kernel is the core of all Linux systems, including thousands of GNU/Linux distributions, Android Unicom operating systems, and a large number of embedded systems, network devices, etc. Its popularity and ubiquity can be attributed to the fact that it is free and open source. Anyone can download the Linux kernel, modify it as needed, and compile it for their own commercial or private use.
With nearly 30 million lines of code and a large number of contributors from around the world, the Linux kernel sounds like a complex project that the average user would never bother with, right? You might think that the core of any such operating system should be left to scientists, programmers, and IT professionals. But in fact, downloading the Linux kernel source code and compiling it is very simple, and any Linux user can do it.
In this tutorial, we will guide Debian and Ubuntu users through gradually downloading the Linux kernel source code linux partition, installing the necessary packages that allow us to compile it, and finally compiling the kernel using our own custom options. Finally, you'll learn how to install the kernel into your own system so that your computer can run the kernel you created.
In this tutorial you will learn:
Step-by-step instructions for building a custom Linux kernel
We first download the Linux kernel source code. Navigate to download the version you want. Most likely you only want to download the latest version of the tarball.
Before changing the file you just downloaded, please open a command line terminal and install the following prerequisite software packages. Some are likely already installed.
$ sudo apt update $ sudo apt install fakeroot build-essential libncurses-dev xz-utils libssl-dev flex libelf-dev bison
Connect it and extract the Linux kernel tarball.
$ tar xvf linux-5.18.tar.xz $ cd linux-5.18
Replace the file name inside with the file name you downloaded.
This is where we can start customizing things. The steps that follow are just suggestions, but feel free to configure them as you see fit. First, we will copy the system's current kernel configuration file and use it with the new kernel.
$ cp /boot/config-$(uname -r) .config
The make command below allows us to edit the configuration file we just copied and select the features to be included in the compiled Linux kernel. Make the changes you want here. Once finished, you can save and exit this menu. Please note that linux kernel source code, if you just want to keep the current system settings, there is no need to make any modifications at all.
$ make menuconfig
After that, it’s time to use the following command to create the Linux kernel. You will see a lot of output in the terminal, and the compilation process may take a while. The first two commands make the necessary modifications to the certificate to facilitate our compilation.
$ scripts/config --disable SYSTEM_TRUSTED_KEYS $ scripts/config --disable SYSTEM_REVOCATION_KEYS $ sudo make
Once completed, we can install the necessary kernel modules using the following commands.
$ sudo make modules_install
Afterwards, to install the kernel onto your own system, complete it using the following command:
$ sudo make install
最后,重新启动系统以加载到刚才编译和安装的新内核中。
$ reboot
重新启动后,您应当见到您的系统正在使用刚才编译的新内核。您可以使用uname命令验证这一点,并查看版本号是否匹配。
$ uname -r
结束语
在本教程中,我们了解了怎样在基于Debian或Ubuntu的系统上从源代码下载和编译Linux内核。您还了解了怎样按照自己的须要配置Linux内核,以及怎样在自己的系统上安装内核。通过这种步骤linux内核源代码深度linux,您仍然可以在计算机上下载并安装最新的内核。您还可以依照须要尝试添加或删掉功能。
The above is the detailed content of How to build the necessary packages for custom Linux kernel source code compilation?. For more information, please follow other related articles on the PHP Chinese website!