In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to compile the Linux kernel. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
In the computer world, kernel kernel is a low-level software low-level software that handles communication between hardware and general systems. Except for some of the initial firmware burned into the computer motherboard, when you start the computer, the kernel makes the system realize that it has a hard drive, screen, keyboard, and network card. Equal time (more or less) is allocated to each part so that images, audio, file systems, and networks can run smoothly or even in parallel.
However, the demand for hardware is constant, and as more hardware is released, the kernel must include more code to ensure that that hardware works properly. It's hard to get specific numbers, but the Linux kernel is undoubtedly one of the top kernels in terms of hardware compatibility. Linux operates countless computers and mobile phones, board-level embedded systems (SoC) for industrial use and enthusiasts, RAID cards, sewing machines, and so on.
Back in the 20th century (or even the early 21st century), it didn't make sense for Linux users to download the latest kernel code and compile and install it just after buying new hardware. Now it's hard to see Linux users compiling kernels for fun or making money from highly specialized customized hardware. Now, you don't usually need to compile the Linux kernel anymore.
Here are some reasons and tutorials for quickly compiling the kernel.
Update the current kernel
Whether you buy a new brand computer with a new graphics card or Wifi chipset or a new printer at home, your operating system (called GNU+Linux or Linux, which is also the name of the kernel) needs a driver to open the channel for new components (graphics cards, chipsets, printers, and anything else). Sometimes when you plug in some new device, your computer says it has been found, which is somewhat deceptive. Don't be fooled, sometimes that's enough, but more often your operating system only uses a common protocol to detect a new device installed.
For example, your computer may be able to identify a new network printer, but sometimes that is simply because the printer's network card is designed to obtain an DHCP address and identify itself on the network. It doesn't mean that your computer knows how to send a document to a printer for printing. In fact, you can think that the computer doesn't even "know" that the device is a printer. It may simply show that the network has a device at a specific address and that the device identifies itself with a series of characters "p-r-i-n-t-e-r". The convenience of human language means nothing to computers. What the computer needs is a driver.
Kernel developers, hardware manufacturers, technical support and enthusiasts all know that new hardware will continue to be released. Most of them contribute drivers and submit them directly to the kernel development team for inclusion in the Linux. For example, Nvidia graphics card drivers are usually written into the Nouveau kernel module, and because Nvidia graphics cards are commonly used, its code is included in any daily distribution kernel (for example, when downloading the kernel from Fedora or Ubuntu). Nvidia is also less commonly used, for example, Nouveau modules are usually removed in embedded systems. There are similar modules for other devices: printers benefit from Foomatic and CUPS, wireless network cards have B43, ath9k, wl modules, and so on.
Distributions tend to include as many reasonable drivers as possible in the construction of their Linux kernels because they want you to use them immediately without installing drivers when you connect to a new device. This is true for most cases, especially now that many device manufacturers are funding the development of Linux drivers that sell their hardware and submit these drivers directly to the kernel team for use in normal distributions.
Sometimes you may be running a kernel that was installed six months ago and equipped with an exciting new device that just went on sale last week. In this case, your kernel may not have a driver for that device. The good news is that it often happens that the driver for that device already exists in the latest version of the kernel, which means you just need to update the running kernel.
Typically, this is done by installing package management software. For example, on RHEL, CentOS, and Fedora:
$sudo dnf update kernel
On Debian and Ubuntu, first get the version of your current kernel:
$uname-r4.4.186
Search for a new version:
$sudo apt update$ sudo apt search linux-image
Install the latest version found. In this example, the latest version is 5.2.4:
$sudo apt install linux-image-5.2.4
After the kernel update, you must reboot (unless you use kpatch or kgraft). At this point, if the device driver you need is included in the latest kernel, your hardware will work properly.
Install the kernel module
Sometimes a distribution does not expect users to use a device (or at least the driver for that device is not enough to be included in the Linux kernel). Linux takes a modular approach to drivers, so although drivers are not compiled into the kernel, distributions can push separate driver packages for the kernel to load. Although somewhat complex, it is very useful, especially when the driver is not included in the kernel but is loaded during boot, or when the driver in the kernel is out of date compared to the modular driver. The first problem can be solved with "initrd" (initializing the RAM disk), which is beyond the scope of this article, and the second point is solved through the "kmod" system.
The kmod system ensures that when the kernel is updated, all modular drivers installed with it are updated. If you install a driver manually, you won't be able to experience the automation provided by kmod, so you should choose it as long as you can install the package with kmod. For example, although the Nvidia driver is built in the kernel as a Nouveau module, the official driver is only released by Nvidia. You can manually install Nvidia's drivers on the website, download the ".run" file, and run the provided shell script, but you have to repeat the same process after installing the new kernel, because nothing tells the package management software that you manually installed a kernel driver. Nvidia drives your graphics card, and manually updating the Nvidia driver usually means that you need to perform the update through the terminal, because it cannot be displayed without the video card driver.
However, if you install the Nvidia driver through the kmod package, updating your kernel will also update your Nvidia driver. In Fedora and related distributions:
$sudo dnf install kmod-nvidia
On Debian and related distributions:
$sudo apt update$ sudo apt install nvidia-kernel-common nvidia-kernel-dkms nvidia-glx nvidia-xconfig nvidia-settings nvidia-vdpau-driver vdpau-va-driver
This is just an example, but if you really want to install the Nvidia driver, you must also block the Nouveau driver. Refer to your distribution documentation for the best steps.
Download and install the driver
Not everything is included in the kernel, and not everything can be used as a kernel module. In some cases, you need to download a special driver written and bound by the vendor, and in other cases, you have a driver but do not have a front-end interface for configuring the driver.
Two common examples are HP printers and Wacom digital boards. If you have a HP printer, you may have a general-purpose driver that can communicate with the printer or even print something. However, general-purpose drivers do not provide customized options for specific models of printers, such as double-sided printing, proofreading, paper tray selection, and so on. HPLIP (HP Linux Imaging and Printing system) provides options for task management, adjusting print settings, selecting available paper trays, and so on.
HPLIP is usually included in package management software; just search for "hplip".
Similarly, the driver for the digital board Wacom, which is mainly used by electronic artists, is usually included in the kernel, but settings such as adjusting pressure and keystroke functions can only be accessed through the graphics control panel included in GNOME by default. But it can also be accessed as an additional package "kde-config-tablet" on KDE.
There are several similar individual examples, such as no driver in the kernel, but a kmod version of the driver available for download in a RPM or DEB file and installed through the package management software.
Patch and compile your kernel
Even in the futuristic utopia of the 21st century, there are vendors who do not know enough about open source to provide installable drivers. Sometimes, some companies provide open source code for drivers, requiring you to download the code, patch the kernel, compile and install it manually.
This distribution has the same drawbacks as installing packaged drivers outside the kmod system: updates to the kernel can break the driver because you have to manually reintegrate it into the kernel each time you replace a new kernel.
Happily, this kind of thing becomes rare because the Linux kernel team does a good job of appealing to companies to communicate with them, and companies finally accept that open source will not disappear soon. But there are still novel or highly professional devices that only provide kernel patches.
Officially, distributions have specific habits about how you compile the kernel so that the package manager is involved in upgrading such an important part of the system. There are too many package managers to cover all of them. For example, when you use tools on Fedora such as rpmdev or devscripts on build-essential,Debian.
First, as usual, find the version of the kernel you are running:
$uname-r
In most cases, if you haven't upgraded the kernel yet, try upgrading the kernel. When you're done, maybe your problem will be solved in the newly released kernel. If you try and find that it doesn't work, then you should download the source code of the running kernel. Most distributions provide specific commands to do this, but if you do it manually, you can find its source code on kernel.org.
You must download any patches required by the kernel. Sometimes, these patches correspond to a specific kernel version, so choose carefully.
Usually, or at least when people are used to compiling the kernel, they get the source code and patch / usr/src/linux.
Extract the kernel source code and apply the required patches:
$cd / usr/src/linux$ bzip2-- decompress linux-5.2.4.tar.bz2 $cd linux-5.2.4 $bzip2-d.. / patch*bz2
Patch files may contain tutorials on how to use them, but they are usually designed to be executed at the top level of the kernel source tree.
$patch-p1
< patch*example.patch 当内核代码打上补丁后,你可以继续使用旧的配置来对打了补丁的内核进行配置。 $ make oldconfig make oldconfig 命令有两个作用:它继承了当前的内核配置,并且允许你配置补丁带来的新的选项。 你或许需要运行 make menuconfig 命令,它启动了一个基于 ncurses 的菜单界面,列出了新的内核所有可能的选项。整个菜单可能看不过来,但是它是以旧的内核配置为基础的,你可以遍历菜单并且禁用掉你没有或不需要的硬件模块。另外,如果你知道自己有一些硬件没有包含在当前的配置中,你可以选择构建它,当作模块或者直接嵌入内核中。理论上,这些并不是必要的,因为你可以猜想,当前的内核运行良好只是缺少了补丁,当使用补丁的时候可能已经激活了所有设备所必要的选项。 下一步,编译内核和它的模块: $ make bzImage$ make modules 这会产生一个叫作 vmlinuz 的文件,它是你的可引导内核的压缩版本。保存旧的版本并在 /boot 文件夹下替换为新的。 $ sudo mv /boot/vmlinuz /boot/vmlinuz.nopatch$ sudo cat arch/x86_64/boot/bzImage >/ boot/vmlinuz$ sudo mv / boot/System.map / boot/System.map.stock$ sudo cp System.map / boot/System.map
So far, you have patched and compiled the kernel and its modules, you have installed the kernel, but you have not installed any modules. That's the final step:
$sudo make modules_install
The new kernel is in place and its modules have been installed.
The final step is to update your bootstrap program so that your computer knows where it is before loading the Linux kernel. The GRUB bootstrapper makes this process quite simple:
Real-life compilation of $sudo grub2-mkconfig
Of course, no one executes these commands manually right now. Instead, refer to your distribution for instructions on how to modify the kernel using the developer toolset used by the release maintainer. These toolsets may create an installable package that integrates all patches and tells your package manager to upgrade and update your bootstrap.
Thank you for reading! This is the end of the article on "how to compile the Linux kernel". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.