How to safely compile kernel myself install and use it.

Ask for help with issues regarding the Installations of the Debian O/S.
Post Reply
Message
Author
rupeshforu3
Posts: 150
Joined: 2012-12-06 07:04
Location: India

How to safely compile kernel myself install and use it.

#1 Post by rupeshforu3 »

Hi I am Rupesh from India and I have brought a new system with AMD Ryzen zen3 5500GT and Asus prime b450 motherboard. I installed Linux Operating System five months back updating, and using it without any problem. I thought to compile kernel source code optimized for my hardware and succeeded but I have some doubts.

I want to compile kernel source code to remove unnecessary blotware in the kernel and to improve performance.

I have read a number of tutorials and tried or experimented to compile kernel and learnt a number of lessons.

I tried to compile kernel according to what I learnt but still there may be any mistakes. As you are experts can you try to examine the steps I followed and give suggestions.

The main steps I followed are as follows

1)  Downloaded and installed kernel source code package.

2) Extracted the source code to my home directory.

3) Changed the ownership of the extracted directory recursively through the following command.

Code: Select all

chown -R $USER:$USER linux
4) Entered the source directory and issued the following command to clean any existing configuration.

Code: Select all

make mrproper
5) I entered the following lines to my bash profile so that I need not enter again and again in terminal emulator.

Code: Select all

export KCPFLAGS=" -march=znver3 -O2 pipe"
export KCLAGS=" -march=znver3 -O2 pipe"
export CFLAGS=" -march=znver3 -O2 pipe"
export CPFLAGS=" -march=znver3 -O2 pipe"
6) After that I have created a configuration file which consists of only the modules loaded by old kernel through the following command.

Code: Select all

make localmodconfig
7) After that I entered the following command.

Code: Select all

make xconfig
8) In this gui configuration I done the following changes.
*I selected amdgpu option to compile as module.
*I have added the string  Rupesh to LocalVersion
*I have selected append Local_Version to version to yes
*I have disabled support for other processors like intel etc except AMD.
*I have saved and exited the configuration.

9) After that I issued the following command to make the kernel and modules.

Code: Select all

make bzImage modules 
10) After that I issued the following command to install modules

Code: Select all

make modules_install 
11) After that I have tried to install kernel to /boot through the following command.

Code: Select all

make install.
12) After that I have updated my grub configuration through the following command.

Code: Select all

grub-mkconfig -o /boot/grub/grub.cfg
13) After that I have installed the grub boot loader through the following command.

Code: Select all

grub install /dev/nvmen101
I think that there is nothing better than "make localmodconfig" to create configuration file.

Previously I tried to compile mainline kernel which is downloaded from kernel.org but I thought distribution kernel source code is more efficient so I tried to compile distribution kernel.

Finally I am asking is it safe to compile kernel myself or it is recommended to use default kernel provided by distribution.

Kindly try to clarify my doubts.

Regards,
Rupesh.

lindi
Debian Developer
Debian Developer
Posts: 646
Joined: 2022-07-12 14:10
Has thanked: 2 times
Been thanked: 129 times

Re: How to safely compile kernel myself install and use it.

#2 Post by lindi »

Compiling the kernel can be fun learning experience but you should play around in a virtual machine and don't break your primary system. Note also that when you compile the kernel yourself you won't get any security updates.

arzgi
Posts: 1831
Joined: 2008-02-21 17:03
Location: Finland
Has thanked: 1 time
Been thanked: 107 times

Re: How to safely compile kernel myself install and use it.

#3 Post by arzgi »

rupeshforu3 wrote: 2025-02-21 09:26
I want to compile kernel source code to remove unnecessary blotware in the kernel and to improve performance.

Regards,
Rupesh.
Why do you thing kernel would have bloatware? Installer provides options to include modules to kernel, or kernel whit calls modules as needed.

Post Reply