Linux Kernel compilation tutorial
Compile Linux-kernel 4.14.14 and use Ubuntu 16.04 64-bit system.
The kernel-4.14.14 kernel File is about 96 MB. After decompression, the linux-4.14.14 directory is about 900 MB. Switch to the unzipped linux-4.14.14 file directory in the terminal and execute the following command:
1. config
Copy the current system compilation configuration in the/usr/src directory.
$ ls /usr/src/linux-headers-4.10.0-35 linux-headers-4.8.0-36 linux-headers-4.10.0-35-generic linux-headers-4.8.0-36-generic
The. config file exists in the linux-headers-*-generic Directory and copies it to the linux-4.14.14 directory.
linux-4.14.14$ cp /usr/src/linux-headers-4.10.0-35-generic/.config .
2. Compile the configuration
Possible problems
$ make menuconfig *** Unable to find the ncurses libraries or the *** required header files. *** 'make menuconfig' requires the ncurses libraries. *** *** Install ncurses (ncurses-devel) and try again. *** scripts/kconfig/Makefile:202: recipe for target 'scripts/kconfig/dochecklxdialog' failedmake[1]: *** [scripts/kconfig/dochecklxdialog] Error 1Makefile:543: recipe for target 'menuconfig' failedmake: *** [menuconfig] Error 2
An error occurred while compiling. If the ncurses library is missing, install it.
# Prompt not to find the ncurses-devel package # sudo apt-get install ncurses-develsudo apt-get install libncurses5-dev
After installation, run the command again. Select [load]-> [OK]-> [Save]-> [OK]-> [EXIT]-> [EXIT]
$ make menuconfig HOSTCC scripts/kconfig/mconf.o HOSTCC scripts/kconfig/lxdialog/checklist.o HOSTCC scripts/kconfig/lxdialog/util.o HOSTCC scripts/kconfig/lxdialog/inputbox.o HOSTCC scripts/kconfig/lxdialog/textbox.o HOSTCC scripts/kconfig/lxdialog/yesno.o HOSTCC scripts/kconfig/lxdialog/menubox.o HOSTLD scripts/kconfig/mconfscripts/kconfig/mconf Kconfig
Configuration result
3. Compile the kernel
Compile Boot Image
The compilation process is time-consuming. In the-jN part, the greater N, the faster the compilation speed. Of course, do not exceed the upper limit of your machine. It takes about 10 minutes to compile the entire kernel.
make bzImage -j256
Two possible problems:
Makefile:942: *** "Cannot generate ORC metadata for CONFIG_UNWINDER_ORC=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel". Stop.
If the corresponding library is missing, install sudo apt-get install libelf-dev.
fatal error: openssl/opensslv.h: No such file or directory
If openssl is not installed, install openssl: sudo apt-get install libssl-dev first.
Compilation Module
Run make modules-j256 directly.
4. Install the kernel
The process of installing the kernel is much faster, which is similar to the installation of software in the general software installation package.
First install the module
root # make modules_install
Then install the kernel.
root # make install
After the installation is complete, the corresponding kernel-related files will be generated in/boot. After the restart, on the boot guide page, We will select the boot kernel, in this case, we can choose the default 4.10 kernel or the latest 4.14 kernel that has just been compiled and installed.
5. Change to start grub
Grub is a program for managing Ubuntu system startup. We need to set the compiled kernel as the default running item and modify the corresponding grub, which is actually quite simple.
View Current:
$ cat /proc/version Linux version 4.10.0-35-generic (buildd@lcy01-33) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) ) #39~16.04.1-Ubuntu SMP Wed Sep 13 09:02:42 UTC 2017$cat /boot/grub/grub.cfg | grep 4.10....
[Not practical]
mkinitramfs 4.14.14 -o /boot/initrd.img-4.14.14update-grub2
The update-grub2 command will automatically modify grub for us