Linux five-step build kernel tree

Linux five-step build kernel tree

0. The kernel tree that comes with the system

Sometimes, the installed system already comes with Linux內核樹that is sufficient for compiling the driver.

The built-in kernel tree is usually located in

/lib/modules/<system kernel version>/build

Among them, the system kernel version can be viewed using uname -r

$ uname -r
5.11.0-41-generic

However, the built-in kernel tree seems incomplete, so it is recommended to compile a complete kernel tree according to the following method.

1. Environment Configuration

first step

To configure the kernel tree for the first time, you need to install some necessary environments

sudo apt-get build-dep linux linux-image-$(uname -r)

(If you get an error message Error :: You must put some 'source' URIs in your sources.list , please refer to here)

Step 2

In addition to the above environment, you also need to install these

sudo apt-get install libncurses-dev gawk flex bison openssl libssl-dev dkms libelf-dev libudev-dev libpci-dev libiberty-dev autoconf dwarves

2. Download source code

sudo apt-get source linux-image-unsigned-$(uname -r)

After this step, there will be three more files.

linux-hwe-5.11_5.11.0-41.45~20.04.1.diff.gz
linux-hwe-5.11_5.11.0-41.45~20.04.1.dsc
linux-hwe-5.11_5.11.0.orig.tar.gz

And a folder where the kernel source code is located

linux-hwe-5.11-5.11.0

(Note: The file name may vary depending on the system version)

3. Build Preparation

(Note: If you get permission denied at any time when running a command, just add sudo at the beginning of the command and run it again)

Enter linux-hwe-5.11-5.11.0 folder and enter

make menuconfig

After a little loading, you will enter this page

insert image description here

You don’t need to modify anything here, just close the interface (use the arrow keys to select Exit and press Enter, or press Esc twice to exit), the reason is at the end of this chapter.

Then, this dialog box will be displayed

insert image description here

After selecting Yes in the blue box, press Enter to exit.

This will generate a .config file in the current directory (you can find this file by typing ls -a ), ensuring that the subsequent make can be executed smoothly.

4. Build the kernel

Enter the following command to start the build (if you encounter permission denied , add sudo at the beginning of the command and run it again)

make

You have to wait a long time here, usually one to several hours. You can use concurrency to speed up by using -j <最大并發任務數> command.最大并發任務數can generally be twice the number of CPUs.

(Note: By using make help , you can find that when you enter make , it will automatically execute the following three actions: 1) make vmlinux (build the original kernel), 2) make bzImage (build the compressed kernel), and 3) make modules (build modular drivers separately))

5. Install the module

Finally, install the module to the /lib/modules/$(uname -r) directory

sudo make modules_install 

Summarize

This is the end of this article about the five-step Linux kernel tree building. For more relevant Linux kernel tree content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Analysis of Linux kernel scheduler source code initialization
  • Some suggestions for Linux system optimization (kernel optimization)
  • How to compile the Linux kernel

<<:  The button has a gray border that is ugly. How to remove it?

>>:  Complete steps to quickly build a vue3.0 project

Recommend

Tutorial on installing DAMO database on Centos7

1. Preparation After installing the Linux operati...

Docker container time zone adjustment operation

How to check if the Docker container time zone is...

About uniApp editor WeChat sliding problem

The uniapp applet will have a similar drop-down p...

SQL implementation of LeetCode (197. Rising temperature)

[LeetCode] 197.Rising Temperature Given a Weather...

Specific use of pthread_create in linux to create threads

pthread_create function Function Introduction pth...

How to recover accidentally deleted messages files in Linux

If there are files that are being used by a proce...

How to design the homepage of Tudou.com

<br />I have been working in front-end for s...

CentOS installation mysql5.7 detailed tutorial

This article shares the detailed steps of install...

Optimizing query speed of MySQL with tens of millions of data using indexes

1. The role of index Generally speaking, an index...

How to install and configure mysql 5.7.19 under centos6.5

The detailed steps for installing mysql5.7.19 on ...

MySQL 8.x msi version installation tutorial with pictures and text

1. Download MySQL Official website download addre...

Complete steps to install mysql5.7 on Mac (with pictures and text)

I recently used a Mac system and was preparing to...

How to use SVG icons in WeChat applets

SVG has been widely used in recent years due to i...

WeChat applet realizes multi-line text scrolling effect

This article example shares the specific code for...