The interested reader can refer part 1 of this series at the link below
https://www.hitchhikersguidetolearning.com/2020/11/02/compiling-the-linux-kernel-part-1/
- Now that the Linux 5.9.1 kernel code is downloaded and untarred, traverse to the linux-5.9.1 folder and open the “changes.rst” that contains the minimal requirements needed to compile the Linux kernel. The “changes.rst” will be present under the folder “Documentation/process” in the linux-5.9.1 folder. The code is compiled on Ubuntu Linux distribution.
- Verify that the specific libraries and utilities are the proper version (or higher version) and are installed. If they are not, upgrade the utilities or install the missing ones.
The below link also provides the same details as stated above https://www.kernel.org/doc/html/v5.9/process/changes.html
- Once the build requirements are in place, traverse to the linux-5.9.1 folder
- The kernel configuration (.config file) needs to be set up for the linux kernel build to start
- Just copy the current linux system configuration to current folder by copying the “.config” file from the boot folder
- cp /boot/config-$(uname -r) .config – this will copy 4.15 config file as .config file
- run “make menuconfig” command on the terminal to run the configuration menu. Choose different components/modules that you wish to enable (If not known which modules to enable – go with the default system configuration). The menu config is shown below
- libncurses-dev might need to be installed
- compile the kernel – using “make” command as shown below
- NOTE – libssl-dev library might be required to be installed
- Once the kernel is compiled – run the below command
- “sudo make modules_install” – this installs the different modules for the kernel being compiled (5.9.1 in this case) to /lib/modules. A folder by name of the linux kernel version (5.9.1 in this case) should be available in “/lib/modules“
- Run the below command to place the “vmlinuz” linux image in “/boot folder”
- “sudo make install” – for the particular linux kernel version – “vmlinuz-5.9.1” should be created in “/boot he“
- run the “update-initramfs” command as shown below to create an initramfs for 5.9.1 kernel (the kernel which was compiled)
-
“sudo update-initramfs -c -k 5.9.1” – this will create an “initrd.img-5.9.1” file in “/boot folder“. For information on the usage of “update-initramfs” – refer the link below https://manpages.ubuntu.com/manpages/precise/man8/update-initramfs.8.html
-
- Finally, update the grub loader to show the currently compiled kernel for load during device bootup by using the below command
- sudo update-grub
The next time the device is startd, the grub loader will provide an option to load the 5.9.1 image that was compiled.
Pingback: Compiling the Linux Kernel -Part 1 | Hitch Hiker's Guide to Learning