How to compile and install Linux Kernel 5.1.2 from source code
How to compile and install Linux Kernel 5.1.2 from source code

Compiling a custom kernel has its advantages and disadvantages. However, new Linux user/admin find it difficult to compile Linux kernel. Compiling kernel needs to understand few things and then type a couple of commands. This step by step howto covers compiling Linux kernel version 5.1.2 under an Ubuntu or Debian Linux. The following instructions successfully tested on an RHEL 7/CentOS 7 (and clones), Debian Linux, Ubuntu Linux and Fedora Linux 28/29. However, instructions remain the same for any other Linux distribution.
How to compile and install Linux Kernel 5.1.2
The procedure to build (compile) and install the latest Linux kernel from source is as follows:
- Grab the latest kernel from kernel.org
- Verify kernel
- Untar the kernel tarball
- Copy existing Linux kernel config file
- Compile and build Linux kernel 5.1.2
- Install Linux kernel and modules (drivers)
- Update Grub configuration
- Reboot the system
Let us see all steps in details.
Step 1. Get the latest Linux kernel source code
Visit the official project site and download the latest source code. Click on the big yellow button that read as “Latest Stable Kernel“:
The filename would be linux-x.y.z.tar.xz, where x.y.z is actual Linux kernel version number. For example file linux-5.1.2.tar.xz represents Linux kernel version 5.1.2. Use the wget command to download Linux kernel source code:$ wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.1.2.tar.xz
Step 2. Extract tar.xz file
You really don’t have to extract the source code in /usr/src. You can extract the source code in your $HOME directory or any other directory using the following unzx command or xz command:$ unxz -v linux-5.1.2.tar.xz
OR$ xz -d -v linux-5.1.2.tar.xz
Verify Linux kernel tartball with pgp
First grab the PGP signature for linux-5.1.2.tar:$ wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.1.2.tar.sign
Try to verify it:$ gpg --verify linux-5.1.2.tar.sign
Sample outputs:
gpg: assuming signed data in 'linux-5.1.2.tar'
gpg: Signature made Sun 12 Aug 2018 04:00:28 PM CDT
gpg: using RSA key 79BE3E4300411886
gpg: Can't check signature: No public key
Grab the public key from the PGP keyserver in order to verify the signature i.e. RSA key ID 79BE3E4300411886 (from the above outputs):$ gpg --recv-keys 79BE3E4300411886
Sample outputs:
gpg: key 79BE3E4300411886: 7 duplicate signatures removed |
Now verify gpg key again with the gpg command:$ gpg --verify linux-5.1.2.tar.sign
Sample outputs:
gpg: assuming signed data in 'linux-5.1.2.tar' |
If you do not get “BAD signature” output from the “gpg –verify” command, untar/extract the Linux kernel tarball using the tar command, enter:$ tar xvf linux-5.1.2.tar
Step 3. Configure the Linux kernel features and modules
Before start building the kernel, one must configure Linux kernel features. You must also specify which kernel modules (drivers) needed for your system. The task can be overwhelming for a new user. I suggest that you copy existing config file using the cp command:$ cd linux-5.1.2
$ cp -v /boot/config-$(uname -r) .config
Sample outputs:
'/boot/config-4.15.0-30-generic' -> '.config'
Step 4. Install the required compilers and other tools
You must have development tools such as GCC compilers and related tools installed to compile the Linux kernel.
How to install GCC and development tools on a Debian/Ubuntu Linux
Type the following apt command or apt-get command to install the same:$ sudo apt-get install build-essential libncurses-dev bison flex libssl-dev libelf-dev
See “Ubuntu Linux Install GNU GCC Compiler and Development Environment” for more info.
How to install GCC and development tools on a CentOS/RHEL/Oracle/Scientific Linux
Try yum command:$ sudo yum group install "Development Tools"
OR$ sudo yum groupinstall "Development Tools"
Additional packages too:$ sudo yum install ncurses-devel bison flex elfutils-libelf-devel openssl-devel
How to install GCC and development tools on a Fedora Linux
Run the following dnf command:$ sudo dnf group install "Development Tools"
$ sudo dnf install ncurses-devel bison flex elfutils-libelf-devel openssl-devel
Step 5. Configuring the kernel
Now you can start the kernel configuration by typing any one of the following command in source code directory:
- $ make menuconfig – Text based color menus, radiolists & dialogs. This option also useful on remote server if you wanna compile kernel remotely.
- $ make xconfig – X windows (Qt) based configuration tool, works best under KDE desktop
- $ make gconfig – X windows (Gtk) based configuration tool, works best under Gnome Dekstop.
For example, run make menuconfig command launches following screen:$ make menuconfig # 最好在general setup中设置下你定义的名称,方便识别
You have to select different options as per your need. Each configuration option has HELP button associated with it so select help button to get help. Please note that ‘make menuconfig’ is optional. I used it here to demonstration purpose only. You can enable or disable certain features or kernel driver with this option. It is easy to remove support for a device driver or option and end up with a broken kernel. For example, if the ext4 driver is removed from the kernel configuration file, a system may not boot. When in doubt, just leave support in the kernel.
Step 5. How to compile a Linux Kernel
Start compiling and tocreate a compressed kernel image, enter:$ make
To speed up compile time, pass the -j as follows:## use 4 core/thread ##
$ make -j 4
## get thread or cpu core count using nproc command ##
$ make -j $(nproc)
Compiling and building the Linux kernel going take a significant amount of time. The build time depends upon your system’s resources such as available CPU core and the current system load. So have some patience.
Install the Linux kernel modules
$ sudo make modules_install
Install the Linux kernel
So far we have compiled the Linux kernel and installed kernel modules. It is time to install the kernel itself:$ sudo make install
It will install three files into /boot directory as well as modification to your kernel grub configuration file:
- initramfs-5.1.2.img
- System.map-5.1.2
- vmlinuz-5.1.2
Step 6. Update grub config
You need to modify Grub 2 boot loader configurations. Type the following command at a shell prompt as per your Linux distro:
CentOS/RHEL/Oracle/Scientific and Fedora Linux
$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg
$ sudo grubby --set-default /boot/vmlinuz-5.1.2 #安装自己定义的名称来设置
You can confirm the details with the following commands:grubby --info=ALL | more
grubby --default-index
grubby --default-kernel
Debian/Ubuntu Linux
The following commands are optional as make install does everything for your but included here for historical reasons only:$ sudo update-initramfs -c -k 5.1.2
$ sudo update-grub
How to build and install the latest Linux kernel from source code
You have compiled a Linux kernel. The process takes some time, however now you have a custom Linux kernel for your system. Let us reboot the system.
Reboot Linux computer and boot into your new kernel
Just issue the reboot command or shutdown command:# reboot
Verify new Linux kernel version after reboot:$ uname -mrs
Sample outputs:
Linux 5.1.2 x86_64
Conclusion – Linux Compile Kernel version 5.1.2
Configurations! You completed various steps to build the Linux kernel from source code and compiled kernel should be running on your system. I strongly suggest that you always keep backup of essential data and visit the kernel.org page here for more info.
提示:
make config : Ask me all options from the new kernel source.
make defconfig : It will auto answer the defaults for each options in new kernel source.
make oldconfig : Ask me the new options that is not present in current kernel.
make olddefconfig : It will auto answer the defaults for new options.
make menuconfig : Text baseed GUI to make some tweaks in .config file.
How to compile and install Linux Kernel 5.1.2 from source code的更多相关文章
- Install Linux Kernel - AT91SAM9260EK
两.AT91SAM9260EK 2.1下载 介绍页: http://www.at91.com/linux4sam/bin/view/Linux4SAM/LegacyLinuxKernel 下载页: a ...
- Install Linux Kernel 4.10 In CentOS and Ubuntu
https://www.ostechnix.com/install-linux-kernel-4-10-centos-ubuntu/
- Linux Kernel中所應用的數據結構及演算法
Linux Kernel中所應用的數據結構及演算法 Basic Data Structures and Algorithms in the Linux kernel Links are to the ...
- Linux kernel Wikipedia
http://en.wikipedia.org/wiki/Linux_kernel Development model The current development model of the Lin ...
- How to: Compile Linux kernel 2.6
Compiling custom kernel has its own advantages and disadvantages. However, new Linux user / admin ...
- Compile Linux Kernel on Ubuntu 12.04 LTS (Detailed)
This tutorial will outline the process to compile your own kernel for Ubuntu. It will demonstrate bo ...
- How to compile Linux kernel in fedora 6
前提:已裝好Fedora 6 core 2.6.18 ,在 Fedora 6 中compile linux kernel.1.下載 Fedora 6 core 2.6.18 http://www.ke ...
- CentOS7 + linux kernel 3.10.94 compile 简记
Linux kernel 一直以其开源著称,可以自己编译选择合适的模块,针对特定的系统可以有不同的编译选项 来源 此次编译的内核版本为3.10.94,从官网www.kernel.org下载而来,自己虚 ...
- linux kernel API and google android compile guide
(1)linux kernel API website: http://docs.knobbits.org/local/linux-doc/html/regulator/index.html http ...
随机推荐
- 获取浏览区变化的方法resize() 方法
当调整浏览器窗口的大小时,发生 resize 事件. resize() 方法触发 resize 事件,或规定当发生 resize 事件时运行的函数. <html> <head> ...
- Splinter 的认识和基础应用
Splinter 是一个使用Python开发的开源web应用测试程序,它可以帮助我们实现自动浏览站点和与其进行交互.它是依赖于其它python插件或拓展进行的,所以我们使用它之前需要安装一系列的依赖包 ...
- MK66FN2M0VLQ18
NXP Kinetis K66: 180MHz Cortex-M4F MCU, 2MB Flash, 256KB SRAM, Dual USBs (FS + HS), Ethernet, 144-LQ ...
- 自定义控件 - 字母索引 : LetterIndexView
实现字母列表,滑动列表显示当前选中字母,回调接口. 1.实现字母列表.初始化相关属性.计算每个字母所占宽高.绘制字母A-Z,#. private int itemWidth;//每个字母所占宽度 pr ...
- JVM(2) JVM内存模型
一.概述 Java的内存管理采用[自动内存管理]机制,因为这个自动管理机制,Java程序员就不需要去写释放内存的代码,而且不容易出现内存泄漏问题(比C/C++程序员少一些烦恼).但是由于内存的申请和释 ...
- atom超快替换文件中的tab到space
找到开源的插件代码里缩进全部用的是tab,但公司内部的缩进要求是用space,所以需要将所有的tab替换成space. 在Atom编辑器里,选中所有内容后,点击 Edit - Lines - Auto ...
- Win7下64位机安装SQL2000
win7下64位机安装SQLSERVER20001.右击计算机属性,查看操作系统 2.打开安装文件夹,按图点击 3.开始安装 4. 下一步选择 安装SQL Server2000 组件 5. 下一步 选 ...
- 测开之路九十五:css进阶之光标和溢出内容处理
光标样式:cursor 准备文字 css 溢出内容处理:overflow,默认溢出部分是显示 先把内容放到盒子里面 正常显示 不显示溢出内容 显示为滚动条 自动处理 css /* 光标样式 */p{ ...
- Krustal重构树
zz:https://blog.csdn.net/ouqingliang/article/details/81206050 Kruskal重构树基于Kruskal算法.在执行算法过程中,Kruskal ...
- 前端005/React生命周期
ES6中React生命周期 一.React生命周期 React生命周期主要包括三个阶段:初始化阶段.运行中阶段和销毁阶段. 在React不同的生命周期里,会依次触发不同的钩子函数. 二.React的生 ...