Ubuntu kernel compilation tutorial-compile the Linux4.5.0 Kernel
Tutorial environment: Ubnuntu 64-bit (14.04 recommended) + Xshell
The Linux ECs is very useful for compiling the kernel. This article describes the most basic kernel compilation methods. For convenience, all operations are performed under the root user.
If you are not a root user, you can use the su command to switch to the root user.
Note: It is best to disable this item when using xshell (tool -- option -- Advanced)
I. Environment preparation
1. Prepare the linux source code and patches, you can download on the official website (http://www.kernel.org), here we download version 4.5.
However, Alibaba provides http://mirrors.aliyun.com/, which can also be downloaded here for faster speeds. The command for downloading an image is as follows:
cd /tmpwget http://mirrors.aliyun.com/linux-kernel/v4.x/linux-4.5.tar.xzwget http://mirrors.aliyun.com/linux-kernel/v4.x/patch-4.5.xz
2. Prepare the environment required for Installation
Run apt-get update to update the software source, and then install the required environment:
apt-get install kernel-package build-essential libncurses5-dev fakeroot
3. decompress the kernel
Decompress the package:
Xz-d linux-4.5.tar.xz
After being decompressed, linux-4.5.tar is obtained,
Run the tar-xvf linux-4.5.tar to unzip the directory linux-4.5.
Copy both the kernel directory linux-4.5 and patch patch-4.5.xz to/usr/src and enter/usr/src
cp linux-4.5 /usr/src –rfcp patch-4.5.xz /usr/srccd /usr/src
2. Prepare for compilation
1. Install Kernel patches
Xz-d patch-4.5.xz | patch-p1
After the execution, no prompt indicates that the execution is correct
2. Compile the configuration
Look at the previous kernel version, copy the. config file inside to the linux-4.5 Folder:
In the picture above, my kernel folder is a linux-headers-3.13.0-32-generic and I need to copy the. config file in this folder to the linux-4.5 directory.
cp linux-headers-3.13.0-32-generic/.config linux-4.5/
Cd linux-4.5
Then execute make menuconfig,
Select load → OK → Save → OK → EXIT:
3. Compile the kernel
There are two steps to compile the kernel, which usually takes about 1-3 hours.
1. Compile the startup Image
Make bzImage-jN
Here, N is the number of your CPU cores x 2. For example, if I am a single-core CPU, I should execute the make bzImage-j2 command. If I am a dual-core CPU, I should execute make bzImage-j4.
If it is too troublesome, you can directly run make bzImage.
Two errors may occur:
Fatal error: openssl/opensslv. h: No such file or directory
This is because openssl is not installed. You need to install openssl: apt-get install libssl-dev first.
Bc: not found. Install bc: apt-get install bc
Install the corresponding dependency and run it again.
2. Compilation Module
Make modules-jN here N is the same as above
You can also run make modules directly.
4. Install the kernel
The process of installing the kernel is much faster, which is similar to installing the software in the software installation package.
First install the module
Make modules_install
Then install the kernel.
Make install
5. Change to start grub
Grub is a program for managing Ubuntu system startup. To run the compiled kernel, we need to modify the corresponding grub, which is actually very simple.
mkinitramfs 4.5.0 -o /boot/initrd.img-4.5.0update-grub2
The update-grub2 command will automatically modify grub,
The modified grub content is as follows: we can see that the kernel version has been changed to 4.5.0.
Now that the kernel has been compiled, restart the server and run the uname-a command to view your system version:
The system version is already linux 4.5!
How to install Linux Kernel 4.4 on Ubuntu
Linux Kernel 4.2.2 compilation and installation tutorial
Ubuntu 15.10 will use the Linux Kernel 4.2 Kernel
How to install Kernel 4.0.2 on CentOS 7
How to install Linux Kernel 4.0 on CentOS 7
How to install Linux kernel 4.0 on Ubuntu/CentOS?
How to install Linux kernel 13.10 On Ubuntu 3.12
How to install the 3.16.7 CKT2 kernel in Ubuntu 14.10, Ubuntu 14.04, and its derivative versions
Linux Kernel: click here
Linux Kernel: click here
This article permanently updates the link address: