build and install kernel On Ubuntu18.04.1

  1. 先在https://www.kernel.org/上下载kernel代码文件,这里下载kernel4.18.5

  2. 针对ubuntu使用的kernel需要打上对应版本的patch,可以在如下地址上找到:http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.18.5/, 这里同样是v4.18.5版本目录下的patch

  3. 编译前的准备工作,更新获取编译依赖库
    sudo apt-get update
    sudo apt install make
    sudo apt install build-essential
    sudo apt install libncurses5-dev
    sudo apt install libssl-dev
    sudo apt install openssl
    sudo apt install zlibc
    sudo apt install minizip
    sudo apt install libidn11-dev
    sudo apt install libidn11
    sudo apt install libelf-dev
    sudo apt install bison
    sudo apt install flex

  4. 解压代码内核代码
    进入代码目录下,git apply 对应的kernel的patch文件,然后分别执行如下命令,以获取当前ubuntu内核的原始config
    build and install kernel On Ubuntu18.04.1_第1张图片

  5. make menuconfig
    先选load,再选择save,接着选择exit
    这一步如果有其它库缺失导致的menuconfig弹出失败,需要通过apt install解决。

  6. sudo make -j4

  7. sudo make modules_install; sudo make install

如果已经在当前内核目录下编译过,则需要执行如下命令,清除掉上次编译产生的中间文件,然后再次触发编译
sudo make mrproper
sudo make clean
sudo make menuconfig

最后一步,reboot 重启电脑,电脑重启后,开机过程中点按ESC键,Grub里选择”Advanced options for Ubuntu”,就会出现对应的新编译的内核选项。选中开机即可,然后命令终端中,通过uname -r 可以确认更新成功。
build and install kernel On Ubuntu18.04.1_第2张图片

按照上述步骤编译出来的中间文件都在源文件的相同路径中,可以参考kernel文件夹中的Readme变异文件到指定目录中,如下所示:

Build directory for the kernel

When compiling the kernel, all output files will per default be
stored together with the kernel source code.
Using the option make O=output/dir allows you to specify an alternate
place for the output files (including .config).
Example::

 kernel source code: /usr/src/linux-4.X
 build directory:    /home/name/build/kernel

To configure and build the kernel, use::

 cd /usr/src/linux-4.X
 make O=/home/name/build/kernel menuconfig
 make O=/home/name/build/kernel
 sudo make O=/home/name/build/kernel modules_install install

Please note: If the O=output/dir option is used, then it must be
used for all invocations of make.

这里使用如下cmds:

    mkdir out
    cp /boot/config-4.15.0-29-generic ./out/.config
    make O=out menuconfig
    sudo make O=out
    sudo make O=out INSTALL_MOD_STRIP=1 modules_install
    sudo make O=out install

build and install kernel On Ubuntu18.04.1_第3张图片

Done.

你可能感兴趣的:(build and install kernel On Ubuntu18.04.1)