1. Download the kernel and unzip it into the/USR/SRC directory
Execute the following command at the terminal to download the kernel of version 4.16.14 (currently the latest stable version) to the current shell Open Directory
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.16.14.tar.xz
Unzip the downloaded kernel file linux-4.16.14.tar.xz
xz -d linux-4.16.14.tar.xz 将 linux-4.16.14.tar.xz 文件解压成 linux-4.16.14.tar 压缩文件sudo tar -xvf linux-4.16.14.tar -C /usr/src 将 linux-4.16.14.tar 解压到 /usr/src 目录下
2. Installation of dependent libraries that may be used by the compilation kernel
sudo apt-get install libncurses5-dev libssl-dev sudo apt-get install build-essential openssl sudo apt-get install zlibc minizip sudo apt-get install libidn11-dev libidn11sudo apt-get install bisonsudo apt-get install flex
?
3. Configuring kernel Compilation Parameters
cd /usr/src/linux-4.16.14 切换到刚才我们解压的内核源代码目录下make mrproper 清除编译过程产生的中间文件,就是将内核代码还原为刚解压的状态,最好每次编译前执行一下。make clean 清除上次编译产生的中间文件,最好每次编译前执行一下。make menuconfig 配置编译参数,编译的内核模块选择,内核剪裁需要重点研究的部分。
4. Compiling the kernel
make -jN 也可以只使用 make ,N表示编译时用几个线程编译,最大不要超过CPU个数的两倍
Compiling the kernel is time consuming, about two hours.
5. Install the kernel
make modules_install 安装内核模块,驱动等 make install 安装内核
6. Other Notes
Kernel configuration, if you are prompted to find a dependent file during compilation, simply install the corresponding dependent file based on the error message you are prompted for.
For example, the following error message appears:
/bin/sh: 1: flex: not foundscripts/Makefile.lib:202: recipe for target 'scripts/kconfig/zconf.lex.c' failedmake[2]: *** [scripts/kconfig/zconf.lex.c] Error 127Makefile:514: recipe for target 'silentoldconfig' failed
The Flex module is required, but the computer is not installed, just perform sudo apt-get install flex
the installation on the line.
Compiling the Linux kernel using Ubuntu