View previous topic :: View next topic |
Author |
Message |
rupeshforu3 n00b

Joined: 19 Aug 2024 Posts: 63
|
Posted: Fri Feb 21, 2025 9:29 am Post subject: 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.
Code: |
chown -R $USER:$USER linux
|
4) Entered the source directory and issued the following command to clean any existing configuration.
5) I entered the following lines to my bash profile so that I need not enter again and again in terminal emulator.
Code: |
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: |
make localmodconfig
|
7) After that I entered the following command.
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: |
make bzImage modules
|
10) After that I issued the following command to install modules
Code: |
make modules_install
|
11) After that I have tried to install kernel to /boot through the following command.
12) After that I have updated my grub configuration through the following command.
Code: |
grub-mkconfig -o /boot/grub/grub.cfg
|
13) After that I have installed the grub boot loader through the following command.
Code: |
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. |
|
Back to top |
|
 |
Banana Moderator


Joined: 21 May 2004 Posts: 1902 Location: Germany
|
Posted: Fri Feb 21, 2025 11:12 am Post subject: |
|
|
Quote: | Finally I am asking is it safe to compile kernel myself or it is recommended to use default kernel provided by distribution. |
Safe is not an absolute thing, it depends on your preferences. Distribution kernels, either -bin or sources, do have additional patches added which the distribution think are good and needed.
So, yes you can do it the way to do it, but do not expect that your way is better. It is diferent. There are no absolute ways or configs which would result in the best possible. _________________ Forum Guidelines
PFL - Portage file list - find which package a file or command belongs to.
My delta-labs.org snippets do expire |
|
Back to top |
|
 |
Goverp Advocate


Joined: 07 Mar 2007 Posts: 2207
|
Posted: Fri Feb 21, 2025 11:14 am Post subject: |
|
|
Rupesh,
In essence, the steps you list seem correct. I think you will have a problem because the device drivers for your disks or NVMe or whatever will be modules, and therefore not available when you first boot this kernel.
Have you tried booting your new kernel, and if so, did it work? If not, what messages did you get?
Quote: | 1) Downloaded and installed kernel source code package. | - which package?
Quote: | 11) After that I have tried to install kernel to /boot through the following command.- | you should see your kernel in /boot, with a name "vmlinuz-x.y.z-rupesh" for whichever kernel version x.y.z you downloaded.
You should also see that in grub.cfg, if your "grub-mkconfig" worked correctly.
Quote: | 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. |
If "mainline kernel" means one from kernel.org, and "distribution kernel" is the package sys-kernel/gentoo-sources, the difference it not of efficiency. AFAIR gentoo-sources are basically the same as kernel.org but a little bit older (to allow ~arch users to find the bugs!), perhaps with patches need in response to bugs found by Gentoo users, and with patches to allow configuring OpenRc vs Systemd and to ensure some basic security features are selected.
You might find the "kmake" script I use (see my page in the wiki) useful. _________________ Greybeard |
|
Back to top |
|
 |
NeddySeagoon Administrator


Joined: 05 Jul 2003 Posts: 54916 Location: 56N 3W
|
Posted: Fri Feb 21, 2025 11:45 am Post subject: |
|
|
rupeshforu3,
Safe in what respect?
Secure ... it could be better. Start reading here and here
Don't use Code: | export KCPFLAGS=" -march=znver3 -O2 pipe"
export KCLAGS=" -march=znver3 -O2 pipe"
export CFLAGS=" -march=znver3 -O2 pipe"
export CPFLAGS=" -march=znver3 -O2 pipe" | Choose your CPU in the list in the configuration tool.
If it breaks when you pass your flags to the kernel build system, nobody will have seen the problem before.
USE=experimental when you emerge gentoo-sources will get you a patch that adds more CPUs to the list in in the kernel.
They are better tested than doing your own thing.
What happens when you get a panic on boot?
You will - don't expect it to work first time. :)
For easy recovery, you keep a few extra known working kernels in the boot menu.
Your own kernel will not be any faster, at least not measurably, than the distribution kernel.
It can have a smaller attack surface, as it is not required to boot everywhere and take up less HDD space.
The kernels job is to arbitrate among contenders for resources, then get out of the way, so that the code you want to run gets on the CPU. _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
 |
rupeshforu3 n00b

Joined: 19 Aug 2024 Posts: 63
|
Posted: Fri Feb 21, 2025 11:52 am Post subject: |
|
|
The kernel source package I have installed is
sys-kernel/zen-sources
Kernel version is 6.12.10
At the time of configuration I found the following error
Nvme_common not found.
Another issue is as I have entered the command "make localmodconfig" I thought everything will go fine but the configuration related to windows file systems like exFAT, NTFS etc. are not enabled.
After booting into the latest kernel I tried to mount exFAT partition directly through gui file manager but I received error as this partition support is not present in the kernel.
Similarly I think few settings are not present in the kernel configuration which are necessary to system work properly. _________________ Regards,
Rupesh. |
|
Back to top |
|
 |
sublogic Guru


Joined: 21 Mar 2022 Posts: 315 Location: Pennsylvania, USA
|
Posted: Sat Feb 22, 2025 3:08 am Post subject: Re: How to safely compile kernel myself install and use it. |
|
|
rupeshforu3 wrote: | Code: | make localmodconfig |
|
I would recommend:- make localyesconfig
- make xconfig and change the graphics and networking drivers back to modules
#1 ensures that your storage and filesystem drivers are builtin, not modules, thereby avoiding the issue pointed out by Goverp earlier.
#2 is for drivers that need external firmware; they are not needed in early boot, will initialize after the root partition is mounted, and will load what they need from /lib/firmware .
If you omit #2, you will probably be restricted to text consoles, and have no networking.
Quote: | Another issue is as I have entered the command "make localmodconfig" I thought everything will go fine but the configuration related to windows file systems like exFAT, NTFS etc. are not enabled. | Because the drivers were not in use when you ran localmodconfig. You should have mounted some exFAT or NTFS partitions before starting. Now, go back in xconfig and add the drivers (as modules). Also add USB storage, CDROM, etc. Rebuild, reinstall and reboot.
(Always keep a known good kernel as backup !) |
|
Back to top |
|
 |
rupeshforu3 n00b

Joined: 19 Aug 2024 Posts: 63
|
Posted: Sat Feb 22, 2025 11:50 am Post subject: |
|
|
Yesterday while compiling in the xconfig window for the amdgpu option I have selected y installed of m.
It's meaning is compile amdgpu into the kernel instead of module.
After installation of the kernel I booted into the latest kernel but I can't start display manager and so I have entered startx but I got errors related to drm.
In the grub boot loader I have selected old kernel to boot and at this time I am able to start display manager.
After that in the xconfig window I have selected amdgpu to compile as module.
After installation of the kernel I booted into the latest kernel and I am able to start display manager without any errors.
So localyesconfig tries to create configuration file with modules inbuilt into the kernel and so the system may not boot properly. _________________ Regards,
Rupesh. |
|
Back to top |
|
 |
pietinger Moderator

Joined: 17 Oct 2006 Posts: 5423 Location: Bavaria
|
|
Back to top |
|
 |
rupeshforu3 n00b

Joined: 19 Aug 2024 Posts: 63
|
Posted: Sat Feb 22, 2025 1:11 pm Post subject: |
|
|
Thanks for your support and I will read this tutorial thoroughly and do what you said. _________________ Regards,
Rupesh. |
|
Back to top |
|
 |
sublogic Guru


Joined: 21 Mar 2022 Posts: 315 Location: Pennsylvania, USA
|
Posted: Sat Feb 22, 2025 11:41 pm Post subject: |
|
|
rupeshforu3 wrote: | So localyesconfig tries to create configuration file with modules inbuilt into the kernel and so the system may not boot properly. | Yes, because you followed instruction #1 in my post but did not follow instruction #2.
(Mind you, your bad kernel did boot to a text console, and that's half the battle. You could have repaired it from there with make menuconfig .)
As pietinger points out, an alternative to #2 is to embed the required firmware in the kernel.
Check your networking drivers too ! |
|
Back to top |
|
 |
rupeshforu3 n00b

Joined: 19 Aug 2024 Posts: 63
|
Posted: Sun Feb 23, 2025 8:59 am Post subject: |
|
|
Is there any configuration related to the following in kernel.
OpenCL
OpenGL
VAAPI
Vulkan _________________ Regards,
Rupesh. |
|
Back to top |
|
 |
NeddySeagoon Administrator


Joined: 05 Jul 2003 Posts: 54916 Location: 56N 3W
|
Posted: Sun Feb 23, 2025 11:46 am Post subject: |
|
|
rupeshforu3,
There are really no shortcuts.
Its been like this for over 26 years to my knowledge.
Thu detail in that 20 year old post is no longer correct but the method is still good. _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
 |
rupeshforu3 n00b

Joined: 19 Aug 2024 Posts: 63
|
Posted: Sun Feb 23, 2025 1:06 pm Post subject: |
|
|
Chatgpt reply is as follows.
The terms you've mentioned — `kernel.OpenCL`, `OpenGL`, `VAAPI`, and `Vulkan` — refer to various technologies related to graphics, compute, and video acceleration. These are typically not directly configured within the kernel but can be influenced by the kernel and the drivers supporting them. Let me break down how these technologies relate to kernel configuration:
1. **OpenCL**: This is a framework for writing programs that execute across heterogeneous platforms (CPUs, GPUs, etc.). While OpenCL itself is a user-space framework, kernel support is necessary for drivers that interact with OpenCL hardware (such as GPUs). The kernel might need to have specific drivers enabled, e.g., for AMD or Intel GPUs, to support OpenCL.
2. **OpenGL**: OpenGL is a graphics API, and it's supported by drivers that interact with GPUs. In the Linux kernel, you need to ensure that the correct drivers (like `nouveau` for Nvidia, `amdgpu` for AMD, or `i915` for Intel) are enabled for OpenGL to work. The kernel also must support KMS (Kernel Mode Setting) for graphics to be rendered properly. Additionally, hardware-specific OpenGL drivers often need to be installed (Mesa for open-source drivers, proprietary ones for Nvidia, etc.).
3. **VAAPI**: VAAPI (Video Acceleration API) is used for video decoding and encoding. It relies on hardware acceleration provided by the GPU. The kernel must have support for the relevant video acceleration drivers (like `i915` for Intel, `amdgpu` for AMD) to work with VAAPI. The kernel's video subsystem might need to be configured for this.
4. **Vulkan**: Vulkan is a low-level graphics API, and similar to OpenGL, it requires specific drivers. The kernel doesn't configure Vulkan itself but does need to support the relevant GPU drivers. For example, Vulkan support for AMD is provided through the `amdgpu` driver, for Intel via `i915`, and for Nvidia through proprietary drivers.
### Kernel Configuration
To enable or configure these technologies in the Linux kernel, you would typically need to:
- Enable or configure the necessary **graphics drivers** (e.g., `CONFIG_DRM`, `CONFIG_DRM_AMDGPU`, `CONFIG_DRM_I915`, etc.).
- Enable support for **video acceleration** (e.g., `CONFIG_VIDEO_VAAPI`).
- Ensure proper kernel mode setting (`CONFIG_DRM_KMS_HELPER`).
- Install the necessary user-space libraries and tools (like Mesa, Vulkan SDK, or OpenCL runtime).
These configurations mostly affect the kernel's ability to interact with the hardware and manage the required resources, while user-space drivers and applications (like Mesa or proprietary Nvidia drivers) handle the interaction with the APIs such as OpenCL, OpenGL, VAAPI, or Vulkan.
Would you need more details on any of these components or how to configure them in the kernel? _________________ Regards,
Rupesh. |
|
Back to top |
|
 |
NeddySeagoon Administrator


Joined: 05 Jul 2003 Posts: 54916 Location: 56N 3W
|
Posted: Sun Feb 23, 2025 1:37 pm Post subject: |
|
|
rupeshforu3,
Chatgpt is certainly artificial and certainly not intelligent. In a field like Linux, it will often lead you astray.
Linux keeps changing and ChatGPT and other large language models are always out of date.
Be careful how you use these things. _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
 |
trickygnome n00b


Joined: 17 May 2017 Posts: 16
|
Posted: Sun Feb 23, 2025 2:03 pm Post subject: |
|
|
I think everyone compile kernel by himself here. no?
I use this script:
Code: | #!/bin/sh
# - Run after "make install", before dracut installation
version=$(cat /usr/src/linux/include/config/kernel.release) # 6.1.0-gentoo
# old2 to old3
mv /boot/vmlinuz-${version}-old2 /boot/vmlinuz-${version}-old3
mv /boot/System.map-${version}-old2 /boot/System.map-${version}-old3
mv /boot/initramfs-${version}.img-old2 /boot/initramfs-${version}.img-old3
# old to old2
mv /boot/vmlinuz-${version}-old /boot/vmlinuz-${version}-old2
mv /boot/System.map-${version}-old /boot/System.map-${version}-old2
mv /boot/initramfs-${version}.img-old /boot/initramfs-${version}.img-old2
# save to old
mv /boot/vmlinuz-$version /boot/vmlinuz-${version}-old
mv /boot/System.map-$version /boot/System.map-${version}-old
mv /boot/initramfs-${version}.img /boot/initramfs-${version}.img-old
# rename
mv /boot/vmlinuz /boot/vmlinuz-$version
mv /boot/System.map /boot/System.map-$version
mv /boot/initramfs /boot/initramfs-$version
|
_________________ if posts > 50 then; eat(shit); fi
Shitty laptop with two cores 2.3GHz. Updating took one night per week.
I was working with powersave CPU governor for some time, but not now. |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|