Linux compiled kernel

Source: Internet
Author: User

To compile the kernel steps:

1.
Check the kernel version used by your OS first

[Email protected]:~$ uname-r
4.4.0-51-generic
[Email protected]:~$

2.
If the system is installed, the source code is installed automatically. In the/USR/SRC directory there is a corresponding version of the directory (Ubuntu installed generally no source code needs to download). As follows:

The suffix generic represents the universal version.

[Email protected]:/usr/src$ ls
linux-headers-4.4.0-21 linux-headers-4.4.0-21-generic linux-headers-4.4.0-51 Linux-headers-4.4.0-51-generic

3.

Download the source Code directive Apt-cache Search Linux-source View the available source versions of the system

[Email protected]:/usr/src$ apt-cache Search Linux-source
Linux-source-linux kernel source with Ubuntu patches
Linux-source-4.4.0-linux kernel source for version 4.4.0 with Ubuntu patches
Linux-source-4.8.0-linux kernel source for version 4.8.0 with Ubuntu patches
[Email protected]:/usr/src$

Install Linux source code. Download the source package.

[Email protected]:/usr/src$ sudo apt-get install linux-source-4.4.0

After the download is complete, under/USR/SRC, the file name is: linux-source-4.4.0.tar.bz2, is a compressed package, decompression can get the entire kernel source code:
Note that you have switched to Super User mode
[Email Protected]:/usr/src#tar jxvf linux-source-4.4.0.tar.bz2
Unzip into a new directory/usr/src/linux-source-4.4.0, all the source code is in this directory.

4. Link source Tree

Ln-s/usr/src/linux-source-4.4.0/ /lib/modules/4.4.0-51-generic/build #源代码的目录要和build的内核版本匹配

Enter this directory
Start configuring the kernel select the fastest original configuration (default) mode (I am)
[Email protected]:/usr/src/linux-source-4.4.0# make Oldconfig
Of course you can also use your preferred configuration such as Menuconfig, Xconfig (must have GTK environment bar). It doesn't have to be trimmed anyway, so it's OK to configure it in that way.
When you're done, start make it's a long time to be here for 11 hours.

Direct make bzimage. After execution, you can see that a new file has been generated under the current directory: Vmlinux, whose property is-rwxr-xr-x.
[Email protected]:/usr/src/linux-source-4.4.0$ make bzimage

The first time the following error occurs:

Scripts/sign-file.c:23:30:fatal error:openssl/opensslv.h

The workaround is as follows: missing this library.

sudo apt-get install Libssl-dev

And then:
[Email protected]:/usr/src/linux-source-4.4.0#make modules #将内核选项中的M选项的配置编译为了 *.ko file.
[Email protected]:/usr/src/linux-source-4.4.0#make modules_install #将生成的 *.ko file copied to/lib/modules/< kernel version number >/, and run Depmod generate MODULES.DEP kernel modules of the dependent files, Insmod and modprobe need these dependencies to automatically load dependent KO files, otherwise you need to manually add the dependent module to insert kernel modules into the kernel. Or with Modprobe, Modprobe will read the file/LIB/MODULES/4.4.0-51-GENERIC/MODULES.DEP. This file can be generated by the tool Depmod based on the currently loaded KO module. This file mainly refers to which kernel modules the kernel version needs to load and the dependent modules of the kernel modules. Modules.dep assume that the Ko file is located under the directory/lib/modules/version/directory.

In the Act unit

#modulea. Ko relies on Depend1.ko and Depned2.ko

MODULEA.ko:DEPEND1.ko Depend2.ko

A more accurate description is as follows:

/lib/modules/2.6.29/kernel/a.ko:/lib/modules/2.6.29/kernel/c.ko/lib/modules/2.6.29/kernel/b.ko

/lib/modules/2.6.29/kernel/b.ko:

/lib/modules/2.6.29/kernel/c.ko:/lib/modules/2.6.29/kernel/b.ko

When Modproe A.ko, he loads B.ko and C.ko in order (right-to-left).
After execution finishes, a new directory is generated under/lib/modules/lib/modules/linux-source-4.4.0-generic/
。 The build directory under this path is used for subsequent compilation of the module file. This completes the kernel compilation. You can restart the system.

Linux compiled kernel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.