You are not logged in.

#1 2025-02-21 09:21:21

rupeshforu3
Member
Registered: 2023-01-06
Posts: 122

How to safely compile kernel myself install and use it.

How to safely compile kernel myself install and use it.

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.

chown -R $USER:$USER linux

4) Entered the source directory and issued the following command to clean any existing configuration.

make mrproper

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

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.

make localmodconfig

7) After that I entered the following command.

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.

make bzImage modules 

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

make modules_install 

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

make install.

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

grub-mkconfig -o /boot/grub/grub.cfg

13) After that I have installed the grub boot loader through the following command.

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.

Offline

#2 2025-02-23 09:01:45

rupeshforu3
Member
Registered: 2023-01-06
Posts: 122

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

Is there any configuration related to the following in kernel.

OpenCL
OpenGL
VAAPI
Vulkan

Offline

#3 2025-02-23 13:20:29

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 14,951

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

There shouldn't be , even nvidia has those things in userland .

Moderator note:
Moving to kernel & hardware board


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#4 2025-02-23 16:54:50

ReDress
Member
From: Nairobi
Registered: 2024-11-30
Posts: 245

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

rupeshforu3 wrote:

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.

distribution kernel(s) also has certificates/secure boot figured out which it seems, like it's something one has to always mess with when compiling a mainline kernel nowadays.

Offline

#5 2025-02-24 12:26:44

loqs
Member
Registered: 2014-03-06
Posts: 18,868

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

export KCPFLAGS=" -march=znver3 -O2 pipe"
export CPFLAGS=" -march=znver3 -O2 pipe"

Please see https://www.kernel.org/doc/Documentatio … kbuild.rst. KCPFLAGS is missing a second P.  Similarly for CPFLAGS.  CFLAGS and CPPFLAGS are not used by the kernel build process did you mean HOSTCFLAGS and HOSTCPPFLAGS?  Why pass options such `march` to the preprocessor?

Offline

#6 2025-02-24 13:36:14

rupeshforu3
Member
Registered: 2023-01-06
Posts: 122

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

I want to pass my CPU type which is znver3 to the c compiler, c++ compiler, rust compiler etc., and I want to use GCC as the default compiler instead of llvm.

How to pass znver3 to kernel build process.

I found a number of variables which are as follows
1) KCPPFLAGS
2) KCFLAGS
3) CPFLAGS
4) HOSTCFLAGS
5) HOSTCXXFLAGS
6) USERCFLAGS

MY intention is I want to use GCC as default and pass "znver3 -O2 pipe" to all compilers and every time I mean it may be while compiling kernel or other software like ffmpeg.

Is there any single export command to do this.

Offline

#7 2025-02-24 13:59:36

loqs
Member
Registered: 2014-03-06
Posts: 18,868

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

For the kernel only

export KCFLAGS=" -march=znver3 -O2 pipe"

gcc is the default compiler for the kernel unless you configure otherwise.  Please see https://docs.kernel.org/kbuild/llvm.html.
Why do you not want to use makepkg to build packages such as ffmpeg?

Offline

Board footer

Powered by FluxBB